Quickly find the largest files in a directory

Oct 26, 2009 - 4 Comments

From the Terminal, if you want to quickly find out what the largest files are in a directory, try this variation of the ls command:

ls -lShr

the l flag will display the items in a list, the S flag sorts by size, and h makes it readable in MB/GB (human readable), with r reversing the report order so that the largest file is the last on the list and thus right above the returned command prompt.

If you want the largest file in a directory of a certain type, simply specify the file type with a wildcard to show all files fitting that description:

ls -lShr *.zip

Try it out with any filetype *.mp3 *.mov *.wmv *.psd , etc

.

Related articles:

Posted by: Bill Ellis in Command Line, Tips & Tricks

4 Comments

» Comments RSS Feed

  1. frank says:

    You may also want to check out the bigfiles command line tool to get the largest files within a given directory:

    bigfiles -h

    time -p bigfiles -n 40 ~/

    see: http://codesnippets.joyent.com/posts/show/1888

  2. hypnopixel says:

    $ du -xak ~/ 2> /dev/null | sort -nr | head -n 40

    will list the 40 heaviest files in your home directory

  3. […] OS X Daily posted a tip on how to find the largest file in a directory.  I have my own that uses the du UNIX utility.  The du utility displays the file system usage statistics for each file and directory argument. To use it, type du in a Terminal window. The first column of output is the number of bytes and the second column is the directory path and file. If you run this utility in a directory with lots of files a lot of stuff will scroll off the screen. Not very useful. […]

  4. […] OS X Daily posted a tip on how to find the largest file in a directory.  I have my own that uses the du UNIX utility.  The du utility displays the file system usage statistics for each file and directory argument. To use it, type du in a Terminal window. The first column of output is the number of bytes and the second column is the directory path and file. If you run this utility in a directory with lots of files a lot of stuff will scroll off the screen. Not very useful. […]

Leave a Reply

 

Shop on Amazon.com and help support OSXDaily!

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates

Tips & Tricks

News

iPhone / iPad

Mac

Troubleshooting

Shop on Amazon to help support this site