I have a folder full of folders and files. I want to sort files by size (so I could remove the largest files).
I know how to do that in Windows Explorer, but I can not find a way to do it in Mac OS X Finder.
Windows 2003:
- open folder in Windows Explorer
- click button
Search
- leave
Search for files or folders named
andContaining text
text fields empty - click button
Search Now
- sort by size
Is there a way to do something like this in Finder on Mac OS X?
Best Answer
Open Terminal, cd to the folder you want to analyze and use this command:
It should print a list of all files in the hierarchy, sorted by size. At least on my machine, which is not a Mac, but some other Unix. But in principal it should be roughly the same.
Thanks to Richard Hoskins for the bug with the spaces in the names. That's actually a feature in xargs. See this site where it's explained quite nicely. Above version should work now.
Edit
Here is an explanation how the command works:
find . ==> find items from current working directory "."
-type f ==> search for regular files
-print0 ==> print full file name to standard out, ending with a null character, instead of newline (this is for handling filenames with newlines and white space by xargs)
xargs ==> execute command xargs (executes a command for every line in standard in)
-0 ==> line delimiter is null character
ls -l ==> the command for xargs to execute. This way we get the details especially the size of the files.
sort ==> sort lines in standard in
-k5,5rn ==> sort field definition, begin at field 5 (delimiter default is blank) and end at field 5. That's the size field in ls -l display. r stands for reverse sort order, so that the biggest files are on top and n stands for numerical sort order.