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
精彩评论