我是shell脚本的新手,我有要求。
当我运行shell脚本时,它应该将最近7天的文件从当前文件夹移动到新文件夹。 我的文件看起来像tools_20150727.log,tools_20150726.log,....像这样
请在这方面帮助我。
答案 0 :(得分:1)
下面会有用
find . -type f -mtime -7 -exec mv {} newfolder \;
如果您只想移动.log文件,请使用下面的
find . -type f -name *.log -mtime -7 -exec mv {} newfolder \;
-type f == meaning the pick all files only
-name *.log == having name like .log
-mtime -7== modified within 7 days
-exec == execute also on output from find meaning files found in find command
mv {} newfolder == move all the file found to newfolder