High Availbility

OS & Virtualization

Monday, February 18, 2013

Copying & Moving Files efficiently with xargs

How to move and/or copy a subset of files from one directory

 
eg 1 zip files older than 10 days


 find . -type f -name '*.trc' -mtime +10 | xargs tar -cvzf bdump_$(date +%Y%m%d).gz.tar --remove-files

From time to time I need to move and/or copy a subset of files from one directory to another


 #-- delete
find . -type f -ctime -1 | xargs -i rm {}

 #-- COPY
find . -type f -ctime -1 | xargs -I '{}' cp {} /some/other/directory

 #-- MOVE
find . -type f -ctime -1 | xargs -I '{}' mv {} /some/other/directory

 

It is very easy to compress a Whole Linux/UNIX directory. It is useful to backup files, email all files, or even to send software you have created to friends. Technically, it is called as a compressed archive. GNU tar command is best for this work. It can be use on remote Linux or UNIX server. It does two things for you:
=> Create the archive
=> Compress the archive

You need to use tar command as follows (syntax of tar command):





 
 tar -zcvf archive-name.tar.gz directory-name




2 comments:

Vincent said...

To unzip : tar -xvf filename.tar.gz

Vincent said...

Try this if this does not work

find / -iname "*.mp3" -type f | xargs -I '{}' mv {} /mnt/mp3