Recursively find and list filesize and full path on the command linePosted: 2 October 2009 Filed under: system administration, ubuntu | Tags: command line, linux, system administration 2 Comments
Can’t beat the command line for flexibility and power in accomplishing system administration tasks. Here’s one way to recursively list the filesizes and full paths of files with a particular extension from the command line:
nice find . -name "*.swf" -type f -print0 | xargs -0r ls -skS | less
This is a succinct way to say:
“Show me all Flash files in the current directory hierarchy, descending to unlimited depth. Print the full filename on standard output followed by a null character. Send each filename in turn to the ‘ls’ command, which will look up each file’s size and print that in 1K blocks followed by the filename. (If there aren’t any results from the first command, don’t even run the ‘ls’ command, since that will just give us a list of all the files in the current directory.) Finally, send all that output to the ‘less’ command, which will allow me to page through and view it easily.”
-r switch to
xargs command to ensure we don’t see a list of all files, if the first ‘find’ command doesn’t find any. That sort of thing could be confusing.
THANKS! used it to recover information from a backup hard drive, by comparing the dates.
Awesome, glad to hear it. I tweaked the options a little, above.