More Than Five
More Than Five

Reputation: 10429

Finding which files are taking up most space

On a mac terminal, I want to find out which files are the biggest in my project.

I try:

du -h | sort 

But this sorts by path first and then within path the file size. How do I do it just for file size?

Thanks

Upvotes: 4

Views: 1617

Answers (5)

anubhava
anubhava

Reputation: 785481

On OSX following works:

find . -maxdepth 1 -type f -exec du -k {} \; | sort -nr

Upvotes: 1

devnull
devnull

Reputation: 123608

It appears that you want to list files by size. Try:

find . -type f -printf "%s %p\n" | sort -n

(By default, du doesn't list counts for files. Use the -a or --all option to list count for files as well.)

Upvotes: 1

hashier
hashier

Reputation: 4750

Try

du -scm * | sort -n

If you want to have it as a nice zsh function you can use this:

function dudir () { du -scm ${1:-*(ND)} | sort -n }

Upvotes: 2

trojanfoe
trojanfoe

Reputation: 122401

Sort by numeric/reversed:

$ du -sk * | sort -nr
190560  find_buggy_pos.out
126676  DerivedData
29460   fens.txt
11108   cocos2d_html.tar.gz
484     ccore.log
164     ccore.out
16      a.out.dSYM
12      x
12      p
12      o
12      a.out
4       x.txt
4       trash.c
4       test2.cpp
4       test.cpp
4       stringify.py
4       ptest.c
4       o.cpp
4       mismatch.txt
4       games.pgn

Upvotes: 1

falsetru
falsetru

Reputation: 369274

Use -k option:

du -sk * | sort -n

Upvotes: 0

Related Questions