Commands using du (244)

  • Sort disk usage from directories in the current directory Show Sample Output


    2
    du --max-depth=1 -h . | sort -h
    x3mboy · 2022-08-23 14:58:57 478

  • 1
    du -hc *
    eluis · 2009-02-05 17:04:21 18

  • 1
    du --max-depth=1 -m
    bseaver · 2009-02-16 15:48:12 226

  • 1
    sudo du -sh $(ls -d */) 2> /dev/null
    Code_Bleu · 2009-08-07 19:00:09 4
  • A little bit smaller, faster and should handle files with special characters in the name.


    1
    find . -maxdepth 1 ! -name '.' -execdir du -0 -s {} + | sort -znr | gawk 'BEGIN{ORS=RS="\0";} {sub($1 "\t", ""); print $0;}' | xargs -0 du -hs
    ashawley · 2009-09-11 16:07:39 7

  • 1
    watch -n 60 du /var/log/messages
    rbossy · 2009-10-27 14:53:41 3

  • 1
    du -ms * 2>/dev/null |sort -nr|head
    yooreck · 2009-11-23 16:06:40 3
  • simple find -> xargs sort of thing that I get a lot of use out of. Helps find huge files and gives an example of how to use xargs to deal with them. Tested on OSX snow leopard (10.6). Enjoy. Show Sample Output


    1
    find . -type f -size +1100000k |xargs -I% du -sh %
    4fthawaiian · 2010-01-31 22:04:07 8
  • tar directory and compress it with showing progress and Disk IO limits. Pipe Viewer can be used to view the progress of the task, Besides, he can limit the disk IO, especially useful for running Servers. Show Sample Output


    1
    tar pcf - home | pv -s $(du -sb home | awk '{print $1}') --rate-limit 500k | gzip > /mnt/c/home.tar.gz
    Sail · 2010-04-02 15:29:03 6

  • 1
    du -sm $dirname
    unixmonkey10174 · 2010-06-04 10:00:16 7
  • This command will search all subfolders of the current directory and list the names of the folders which contain less than 2 MB of data. I use it to clean up my mp3 archive and to delete the found folders pipe the output to a textfile & run: while read -r line; do rm -Rv "$line"; done < textfile


    1
    find . -type d -exec du -sk '{}' \; | awk '{ if ($1 <2000) print $0 }' | sed 's/^[0-9]*.//'
    mtron · 2010-06-16 09:37:56 3
  • very handy if you copy or download a/some file(s) and want to know how big it is at the moment


    1
    while true; do du -s <file_or_directory>; sleep <time_interval>; done
    potatoface · 2010-08-24 19:55:13 3
  • Display the size (human reading) of all the directories in your home path (~). Show Sample Output


    1
    du -sh ~/*
    unixmonkey13748 · 2010-11-05 10:20:16 6
  • 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. Show Sample Output


    1
    find / -type f 2>/dev/null | xargs du 2>/dev/null | sort -n | tail -n 10 | cut -f 2 | xargs -n 1 du -h
    mxc · 2010-11-09 13:45:11 6
  • Greater than 500M and sorted by size.


    1
    find . -type f -size +500M -exec du {} \; | sort -n
    PhillipNordwall · 2010-11-09 18:15:44 3

  • 1
    find / -type f -size +100M -exec du {} \; | sort -n | tail -10 | cut -f 2
    PhillipNordwall · 2010-11-09 18:34:49 3
  • 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.


    1
    find /home/ -type f -exec du {} \; 2>/dev/null | sort -n | tail -n 10 | xargs -n 1 du -h 2>/dev/null
    mxc · 2010-11-10 07:24:17 3
  • 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


    1
    du . -mak|sort -n|tail -10
    georgesdev · 2010-12-03 19:28:55 2
  • Show the top 10 file size


    1
    find -type f | xargs -I{} du -sk "{}" | sort -rn | head
    glaudiston · 2011-01-04 11:10:02 3
  • If you're only using -m or -k, you will need to remember they are either in Megabyte or kilobyte forms. So by using -B, it gives you the unit of the size measurement, which helps you from reading the result faster. You can try with -B K as well. Show Sample Output


    1
    du --max-depth=1 -B M |sort -rn
    unixmonkey20397 · 2011-04-12 15:01:12 7
  • as per eightmillion's comment. Simply economical :)


    1
    du -h | sort -hr
    mooselimb · 2011-11-06 23:15:36 3

  • 1
    du --max-depth=1 | sort -nr | awk ' BEGIN { split("KB,MB,GB,TB", Units, ","); } { u = 1; while ($1 >= 1024) { $1 = $1 / 1024; u += 1 } $1 = sprintf("%.1f %s", $1, Units[u]); print $0; } '
    threv · 2011-12-08 17:43:09 4
  • This one line Perl script will display the smallest to the largest files sizes in all directories on a server. Show Sample Output


    1
    du -k | sort -n | perl -ne 'if ( /^(\d+)\s+(.*$)/){$l=log($1+.1);$m=int($l/log(1024)); printf ("%6.1f\t%s\t%25s %s\n",($1/(2**(10*$m))),(("K","M","G","T","P")[$m]),"*"x (1.5*$l),$2);}' | more
    Q_Element · 2012-02-07 15:49:19 10
  • from my bashrc ;)


    1
    find . -mount -type f -printf "%k %p\n" | sort -rg | cut -d \ -f 2- | xargs -I {} du -sh {} | less
    bashrc · 2012-03-30 07:37:52 3
  • This command give a human readable result without messing up the sorting.


    1
    for i in G M K; do du -hx /var/ | grep [0-9]$i | sort -nr -k 1; done | less
    jlaunay · 2012-06-26 22:57:17 6
  • ‹ First  < 2 3 4 5 6 >  Last ›

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. 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.

Share Your Commands


Check These Out

Which processes are listening on a specific port (e.g. port 80)
swap out "80" for your port of interest. Can use port number or named ports e.g. "http"

Multi-line grep
Using perl you can search for patterns spanning several lines, a thing that grep can't do. Append the list of files to above command or pipe a file through it, just as with regular grep. If you add the 's' modifier to the regex, the dot '.' also matches line endings, useful if you don't known how many lines you need are between parts of your pattern. Change '*' to '*?' to make it greedy, that is match only as few characters as possible. See also http://www.commandlinefu.com/commands/view/1764/display-a-block-of-text-with-awk to do a similar thing with awk. Edit: The undef has to be put in a begin-block, or a match in the first line would not be found.

Find the package that installed a command

Delete all but the latest 5 files, ignoring directories

cat stdout of multiple commands
Concatenate the stdout of multiple commands.

check open ports without netstat or lsof

Check command history, but avoid running it
!whatever will search your command history and execute the first command that matches 'whatever'. If you don't feel safe doing this put :p on the end to print without executing. Recommended when running as superuser.

Convert file type to unix utf-8
converts encoding of a file to unix utf-8 useful for data files that contain what would be usable ascii text but are encoded as mpeg or some other encoding that prevents you from doing common manipulations like 'sed'

check open ports without netstat or lsof

Find the package that installed a command


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: