cancel
Showing results for 
Search instead for 
Did you mean: 

Faster way to move old file

heaman1
Regular Advisor

Faster way to move old file

I have thousands files in a path , I tried to use command "find" to move the old file (elder than 150 days) to another path , but it takes 1 day but only move 15% of these files , and the server also become very slow .


the command

find . -mtime +150 -exec mv {} path \;

2 REPLIES
V. Nyga
Honored Contributor

Re: Faster way to move old file

Hi,

'+' should be faster than ';'

find . -mtime +150 -exec mv {} path \+

HTH
Volkmar
*** Say 'Thanks' with Kudos ***
Dennis Handly
Acclaimed Contributor

Re: Faster way to move old file

>Volkmar: find . -mtime +150 -exec mv {} path +

Unfortunately you can't use {} anywhere but last with "+".

So either you need to do xargs or write your own mv script that swaps the order. Unfortunately xargs -i is just as slow:
find . -mtime +150 | xargs -i echo mv {} path

So you need to use:
find . -mtime +150 -exec mv_em path {} +

mv_em:
#!/usr/bin/ksh
target=$1
shift
mv "$@" "$target"