Hide

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.


If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

Hide

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for:

Hide

News

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

Commands using du from sorted by
Terminal - Commands using du - 190 results
find . -type d -d 1 -print0 | xargs -0 du -sm | sort -nr
du -hs file-name
du -csh --time *|sort -n|tail
du -hsx * | sort -rh | head -10
find . -type d| while read i; do echo $(ls -1 "$i"|wc -m) $(du -s "$i"); done|sort -s -n -k1,1 -k2,2 |awk -F'[ \t]+' '{ idx=$1$2; if (array[idx] == 1) {print} else if (array[idx]) {print array[idx]; print; array[idx]=1} else {array[idx]=$0}}'
2014-02-25 22:50:09
User: knoppix5
Functions: awk du echo find ls read sort wc
1

Very quick! Based only on the content sizes and the character counts of filenames. If both numbers are equal then two (or more) directories seem to be most likely identical.

if in doubt apply:

diff -rq path_to_dir1 path_to_dir2

AWK function taken from here:

http://stackoverflow.com/questions/2912224/find-duplicates-lines-based-on-some-delimited-fileds-on-line

du -g | perl -ne 'print if (tr#/#/# == <maximum depth>)'
2014-02-15 07:33:36
User: RAKK
Functions: du perl
Tags: perl du unix aix
0

Lists directory size up to a maximum traversal depth on systems like IBM AIX, where the du command doesn't have Linux's --max-depth option. AIX's du uses -g to display directory size on gigabytes, -m to use megabytes, and -k to use kilobytes. tr### is a Perl function that replaces characters and returns the amount of changed characters, so in this case it will return how many slashes there were in the full path name.

find . -name "pattern" -type f -exec du -ch {} + | tail -n1
du -xm --max-depth 2 /var/log | sort -rn | head
2013-12-16 13:29:33
User: srvesh
Functions: du sort
0

this will give u the details in MB's; from high to low....

du -Sh | sort -h | tail
2013-11-27 17:50:11
User: pdxdoughnut
Functions: du sort
1

I added -S to du so that you don't include /foo/bar/baz.iso in /foo, and change sorts -n to -h so that it can properly sort the human readable sizes.

du -ah | sort -h | tail
du -hs *|sort -h
du -k ~/* | awk '$1 > 50000' | sort -nr
find /Users/jpn/.ievms/ -type f -print0| xargs -0 du -sh
2013-10-16 09:54:19
Functions: du find xargs
-3

When you do a ls -1 | xargs rm it wouldn't workd because those files have spaces. So you must use

find -print0 and xargs -0

du -ah | sort -hr | head -n50 | cat -n
du -hd1 | sort -hr
brew cleanup -n | awk '{print $3}' | xargs du -s | awk '{s+=$1} END {print s}'
find -name *.bak -print0 | du -hc --files0-from=-
du -Lsbc * |awk 'function hr(bytes){hum[1024**4]="TiB";hum[1024**3]="GiB";hum[1024**2]="MiB";hum[1024]="kiB";for(x=1024**4;x>=1024;x/=1024){if(bytes>=x){return sprintf("%8.3f %s",bytes/x,hum[x]);}}return sprintf("%4d B",bytes);}{print hr($1) "\t" $2}'
ls | xargs -I{} du -sh {}
du -m --max-depth=1 [DIR] | sort -nr
du -hs `du -sk * | sort -rn | cut -f2-`
du -xks * | sort -n
2013-07-18 16:10:28
User: rdc
Functions: du sort
1

This command is useful for finding out which directories below the current location use the most space. It is summarised by directory and excludes mounted filesystems. Finally it is sorted by size.

du -hs /path/to/folder/*
du -h --max-depth=1 /path/folder/
2013-07-09 19:56:13
User: ene2002
Functions: du
1

I wanted an easy way to list out the sizes of directories and all of the contents of those directories recursively.

find . -type d -print0 | xargs -0 du -s | sort -n | tail -10 | cut -f2 | xargs -I{} du -sh {} | sort -rn