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 and Containing 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?

link|improve this question

75% accept rate
Check the edits. Outside of what I've posted, anything further would probably need a 3rd-party tool. – John Rudy Sep 11 '09 at 12:05
feedback

6 Answers

up vote 5 down vote accepted

Open Terminal, cd to the folder you want to analyze and use this command:

find . -type f -print0 | xargs -0 ls -l | sort -k5,5rn

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.

link|improve this answer
Doesn't work on the Mac's default (bash) shell. Unterminated quote from xargs, which makes no sense to me since there are no quotes, but I don't use bash-fu as often as I should and therefore am probably missing something obvious. :) – John Rudy Sep 11 '09 at 13:08
i will try that on my mac at home after work, hopefully i will return with a correct answer – dertoni Sep 11 '09 at 13:22
This almost works for me with bash on a Macintosh. I don not get unterminated quote errors, but it breaks with files or folders with spaces in the name. – Richard Hoskins Sep 11 '09 at 15:53
@Richard Hoskins thanks, man, corrected that. – dertoni Sep 11 '09 at 18:37
@John Rudy, sorry, I don't know how that happens. On my Mac it works. – dertoni Sep 11 '09 at 18:39
show 3 more comments
feedback

Assuming it's just a folder, open the folder in Finder. Then click the "Detail" view button. Finally, click the "Size" column. The largest files will sort to the top. Additionally, folders within this folder are also sorted by size -- simply click the triangle next to them, and you will see their files sorted as well. (Don't "open" the folder by double-clicking, just click the triangle to expand their contents.)

Screen Shot

If you wanted to do a search, you can search by file size. Go to the File menu, and choose Find. Click the list that starts out saying "Kind," and choose "Other." Select Size from the list that comes up. Enter your criteria and search. However, I cannot find a way to make the search results display the file size column, so it's easier to use that to, say, find files greater than a certain size than to actually sort by size.

link|improve this answer
It is not just a folder, I guess I was not clear enough. The folder is full of other folders and files. – Željko Filipin Sep 11 '09 at 11:58
See the edit I just dropped in about searching. You can do it, but it's a bit more difficult. However, if you are in list view as displayed above, each folder is also sorted by size -- click the disclosure triangle next to the folder, and its contents will also be sorted by size. – John Rudy Sep 11 '09 at 12:03
Thanks. There are a lot of folders inside folders, so expanding each folder is not option for me. Finder search looks like it could work, but I just can not find a way to search for all files (I do not want to enter anything for file name, I want all files to be listed). – Željko Filipin Sep 11 '09 at 12:16
Does du work in Mac OS X? I've never tried. – Randolph West Sep 11 '09 at 12:17
Is there a wildcard (like *) that would match all file names? – Željko Filipin Sep 11 '09 at 12:17
show 1 more comment
feedback

Use Detail view and sort by the size heading?

link|improve this answer
Maybe I did not make it clear enough, the folder is full of other folders that contain files. If I sort contents of the folder, it will show me which folders inside it are the biggest, and I do not need that, I need sizes of files inside folders. – Željko Filipin Sep 11 '09 at 11:57
feedback
  • open Finder
  • go to folder
  • Finder > File > Find...
  • in Search change selection from This Mac to "folder name"
  • click Kind
  • select Other and then Size
  • click button OK
  • (solution to my problem is size greater than 1 MB)
link|improve this answer
feedback

For cleaning my disk of big files, I prefer simply using Grand Perspective:

cool looking and useful

link|improve this answer
Disk Inventory X is similar, and Daisy Disk is a great commercial alternative. – Daniel Beck Apr 9 '11 at 8:15
@Daniel I just tried DIX once again and it uses so much more memory than GP, and has less features, even though some are unique. I've installed it along with GP and I hardly use it. Now Daisy Disk I gotta try. I don't really like Pie Charts and Ubuntu has a very similar looking disk mapper that I also don't enjoy much. But that Daisy website looks promising. – Cawas Apr 9 '11 at 12:35
feedback

I found this article helpful. While in "Detail" view of Finder, go to View > Show View Options and check "Calculate all sizes"

link|improve this answer
feedback

protected by random Aug 10 '11 at 20:13

This question is protected to prevent "thanks!", "me too!", or spam answers by new users. To answer it, you must have earned at least 10 reputation on this site.

Not the answer you're looking for? Browse other questions tagged or ask your own question.