我正在尝试实现一个一行命令来列出目录中的最后5个新文件,并将这些文件移到另一个位置。现在我可以把它们列出来,但是还没有找到移动它们的方法,有什么建议吗?
ls -1t *.txt | head -5
我有:
$ ls -1t *.txt | head -5
record_-_53810.20160511_-_1053+0200.txt
record_-_53808.20160511_-_1048+0200.txt
record_-_53570.20160510_-_1508+0200.txt
record_-_53568.20160510_-_1503+0200.txt
record_-_53566.20160510_-_1458+0200.txt
发布于 2016-05-11 10:34:51
只需管道到xargs
ls -1t *.txt | head -5 | xargs -i mv {} another_dir/
或者使用扩展本身:
mv $(ls -1t *.txt | head -5) another_dir/
甚至循环:
while IFS= read -r file;
do
mv "$file" another_dir/
done < <(ls -1t *.txt | head -5)
https://stackoverflow.com/questions/37159689
复制相似问题