Thursday, July 17, 2008

Finding all file types in a directory tree

So, this is going to be a pretty nerdy post - please avert your eyes if you're not into getting uber-geeky.

Today, I was working on a web migration plan and I needed to know all of the distinct file extensions that existed in our web directory. To do get the answer to my question, I executed a pretty sweet command that I learned from Vince, Master of the Unixverse.

find /www/my_folder | awk -F. '{ print $NF }' | sort | uniq -c

Here's a quick analysis of this command:

"find /www/my_folder" - lists all of the files, recursively, in /www/my_folder and all of its subdirectories

"awk -F. '{ print $NF }' " - get the file extension from each file (everything after the last dot in each file path)

"sort" - sort all of the resultant extensions alphabetically

"uniq -c" - list each file extension only once and print a count of how many times it occurs

Yes, this is a pretty oblique, archaic post, but you may need it someday!

--Chris

1 comment:

jamie-lee said...

*You* were working on a web migration plan?! *I* was also working on a web migration plan!

Small world.