开发者

Using mtime other than with FIND

开发者 https://www.devze.com 2023-03-26 07:54 出处:网络
I am trying to write a script which will move files older than 1 day to an archive directory. I used the following find command:

I am trying to write a script which will move files older than 1 day to an archive directory. I used the following find command:

for filename in `find /file_path/*.* -type f开发者_如何学Go -mtime +1`

This fails since my argument list is too big to be handled by find. I got the following error:

/usr/bin/find: arg list too long

Is it possible to use find in an IF-ELSE statement? Can someone provide some examples of using mtime other then in find.

Edit: To add the for loop of which the find is a part.


find /file_path -name '*.*' -mtime +1 -type f |
while read filename
do ...move operation...
done

That assumes your original code was acceptable in the way it handled spaces etc in file names, and that there is no sensible way to do the move in the action of find. It also avoids problems with overlong argument lists.


Why not just use the -exec part of find?


If you just want to cp files, you could use

find /file_path -name "." -mtime +1 -type f | xargs -i mv {} /usr/local/archived

0

精彩评论

暂无评论...
验证码 换一张
取 消