Posts Tagged ‘xargs’

unrar All Files in Directory

By Mark Davidson on July 15th, 2010

For quite a while I have found it a pain that unrar does not allow you to extract multiple files at once.
The other day I finally figured out how to get past this. Simply use xargs with place holders.

This command will unrar all the files in the current directory and any subdirectories to the directory /home/user/directory/

find . -iname "*.rar" | xargs -i unrar x {} /home/user/directory/

Linux Find and Modification Time

By Mark Davidson on February 5th, 2010

Recently I needed to do some cleaning up of some temporary files on one of my web servers so I came up with this find command

find . -mtime +1 -type f -printf '%p %Ax\n'

this command will list files in the current directory that where last modified more than 24 hours ago, when printing out the file names it will also print out the date the file was last modified.

find . -mtime +1 -type f -printf '%AY-%Am-%Ad %AT %p\n' | sort

makes use of some more conditions within the printf and the sort command. By putting the date on the front of each entry which is printed out and using the sort command the files are printed in chronological order.

find . -mtime +0 -type f -print0 | xargs -0 du -csh

is the final example I will give this time which combines using find with xargs and du in order to find the disk usage of all the files that match the find condition.