ner*_*tor 9 shell bash shell-script timestamps files
我有大量来自旧硬盘驱动器的图片,我正在尝试整理这些图片。如果我运行ls -l,我会注意到所有这些文件的创建日期都是 2012 年或更早。理想情况下,我想将这些移动到我计算机的第二个硬盘上,该硬盘未设置为自动安装。最好,我可以将这一切作为一个批处理来完成,其中一些命令链接在一起。到目前为止,我ls -l | grep -i 2012只吐出 2012 提供的日期的文件ls -l。现在,诀窍是将cp所有这些文件放到新目录中。我不确定下一步该去哪里,因为每个文件都必须被复制。我的下一组命令是什么?
shi*_*ams 15
不要使用ls. 不建议在这种情况下使用。此外,使用grep根据日期过滤不是一个好主意。您的文件名本身可能包含2012字符串,即使它在 2012 年没有被修改。
使用find命令并通过管道传输其输出。
find . -newermt 20120101 -not -newermt 20130101 -print0 | xargs -0 cp -t /your/target/directory
Run Code Online (Sandbox Code Playgroud)
这里,
-newermt 20120101 ==> File's modified date should be newer than 01 Jan 2012
-not ==> reverses the following condition. Hence file should be older than 01 Jan 2013
-print0 and -0 ==> Use this options so that the command doesn't fail when filenames contain spaces
Run Code Online (Sandbox Code Playgroud)