Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Find

Status
Not open for further replies.

maynarja

MIS
Jan 24, 2007
41
CA
This is most likely an easy one.

But i am writing a bash script to search for certain file extensions and then move the files to another directory. It works fine except that it searches the directory that the files are moved too.

find / -noleaf -iname "*.bak" -exec mv {} dump /;

I have tried the -path and -prune but it does not work for me or i have them in the worng places????
 
If all else fails, try

1) Store absolute paths of .baks in a temp file
2) Loop through temp file and move each line (path to .bak) to the desired directory
 
No it works fine, but it tries to copy all the files in "dump" to "dump"

Code:
find / -iname "*.bak" -exec mv {} dump \;

So i am now doing it like this.

Code:
find / -noleaf -iname "*.bak" | grep -v $DUMP | xargs -i cp {} dump/
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top