gatorparrots
~departed~
Say you want to find out how big your MP3 collection is. It's relatively easy to find all the .mp3 files on a drive and calculate the total amount of disk space they collectively occupy, all from one command.
We want to run a find command, then pipe the output to du via xargs. (The -0 flag for xargs in conjunction with the -print0 flag for find will handle spaces in filenames. From the xargs man page:
Here is the command:
sudo find / -iname "*.mp3" -print0 | xargs -0 du -cks
To make it more fun, throw an alias into your .*shrc file like so:
alias diskspc 'sudo find / -iname "*\!:1*" -print0 | xargs -0 du -cks'
This will net you the ability to search for any file type. For example, issuing diskspc .mp3 would return the filesize for every MP3 file (regardless if its extension is .MP3 or .mp3, thanks to the -iname case insensitive flag for find).
We want to run a find command, then pipe the output to du via xargs. (The -0 flag for xargs in conjunction with the -print0 flag for find will handle spaces in filenames. From the xargs man page:
Code:
-0 Use NUL (``\0'') instead of whitespace as the argument sepa-
rator. This can be used in conjuction with the -print0
option of find(1).
sudo find / -iname "*.mp3" -print0 | xargs -0 du -cks
To make it more fun, throw an alias into your .*shrc file like so:
alias diskspc 'sudo find / -iname "*\!:1*" -print0 | xargs -0 du -cks'
This will net you the ability to search for any file type. For example, issuing diskspc .mp3 would return the filesize for every MP3 file (regardless if its extension is .MP3 or .mp3, thanks to the -iname case insensitive flag for find).