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 - 189 results
find . -size +100000k -exec du -h {} \;
find -type f -exec du -sh {} + | sort -rh | head
find -type f | xargs -I{} du -s "{}" | sort -rn | head | cut -f2 | xargs -I{} du -sh "{}"
2011-01-04 11:10:56
User: glaudiston
Functions: cut du find head sort xargs
-1

Show the top file size in human readable form

find -type f | xargs -I{} du -sk "{}" | sort -rn | head
du -sk * | sort -rn | head
2011-01-03 10:49:40
User: EBAH
Functions: du sort
3

Also:

* find . -type f -exec ls -s {} \; | sort -n -r | head -5

* find . -type f -exec ls -l {} \; | awk '{print $5 "\t" $9}' | sort -n -r | head -5

find . -type f -size +20000k -print0 | xargs -0 du -h | awk -F"\t" '{printf "%s : %s\n", $2, $1}'
2010-12-15 17:51:09
User: depesz
Functions: awk du find xargs
0

Output made so that it will match initial suggestion for this task. Personally, I think that output of du -h is more readable.

du -h |grep -P "^\S*G"
2010-12-13 15:26:31
User: girish_patel
Functions: du grep
0

This Command will list files & folders which are in GBs.

G can be replace by M to get files in MBs.

alias duh='dulist=$(du -sh */); for i in T G M K; do printf "$dulist"|egrep "^[0-9\.]+$i" | sort -rn; done'
2010-12-07 11:11:26
User: forcefsck
Functions: alias du egrep printf sort
Tags: disk usage
-1

Alias to produce a list of all subdir sizes in current dir, in reverse order and human readable units. du is executed only once. Remove the slash after the asterisk to include files.

du . -mak|sort -n|tail -10
2010-12-03 19:28:55
User: georgesdev
Functions: du sort tail
0

du -m option to not go across mounts (you usually want to run that command to find what to destroy in that partition)

-a option to also list . files

-k to display in kilobytes

sort -n to sort in numerical order, biggest files last

tail -10 to only display biggest 10

du -hs */ | sort -hr | head
2010-11-28 15:08:01
User: eronisko
Functions: du sort
14

Directories listed in human-readable format

find /home/ -type f -exec du {} \; 2>/dev/null | sort -n | tail -n 10 | xargs -n 1 du -h 2>/dev/null
2010-11-10 07:24:17
User: mxc
Functions: du find sort tail xargs
Tags: disk usage
1

This combines the above two command into one. Note that you can leave off the last two commands and simply run the command as

"find /home/ -type f -exec du {} \; 2>/dev/null | sort -n | tail -n 10"

The last two commands above just convert the output into human readable format.

find / -type f -size +100M -exec du {} \; | sort -n | tail -10 | cut -f 2
find . -type f -size +500M -exec du {} \; | sort -n
2010-11-09 18:15:44
Functions: du find sort
Tags: size find
1

Greater than 500M and sorted by size.

find / -type f 2>/dev/null | xargs du 2>/dev/null | sort -n | tail -n 10 | cut -f 2 | xargs -n 1 du -h
2010-11-09 13:45:11
User: mxc
Functions: cut du find sort tail xargs
Tags: disk usage
1

Often you need to find the files that are taking up the most disk space in order to free up space asap. This script can be run on the enitre filesystem as root or on a home directory to find the largest files.

du -sh ~/*
2010-11-05 10:20:16
Functions: du
1

Display the size (human reading) of all the directories in your home path (~).

du -b filename
ls -d1a /var/www/*/web | xargs du -hs
2010-10-18 17:16:23
User: DRoBeR
Functions: du ls xargs
-1

Calculate foldersize for each website on an ISPConfig environment. It doesn't add the jail size. Just the "public_html".

du --max-depth=1|sort -n|cut -f2|tr '\n' '\0'|xargs -0 du -sh 2>/dev/null
du -a --max-depth=1 | sort -n
sudo du -sm * | sort -n
2010-09-24 17:56:41
User: wabi
Functions: du sort sudo
0

sudo is optional, but to find out about all files, it is nice, or else run as superuser, ie: su -c 'du -sm * | sort -n'

while true; do du -s <file_or_directory>; sleep <time_interval>; done
2010-08-24 19:55:13
User: potatoface
Functions: du sleep
1

very handy if you copy or download a/some file(s) and want to know how big it is at the moment

svn status | awk '{print $2}' | xargs du | sort -n | tail
while (( 1==1 )); do du -c . >> output.log; sleep 2; done; tail -f output.log
2010-07-12 17:23:45
User: aceiro
Functions: du sleep tail
-5

this command shows the space used in postgres directory.

du -shc .[^.]* * | grep [MG]
2010-07-06 10:13:18
User: rubo77
Functions: du grep
-2

shows only folders, that are MB or GB in total size