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"

Rename files in batch

Download an Entire website with wget

Set laptop display brightness
Run as root. Path may vary depending on laptop model and video card (this was tested on an Acer laptop with ATI HD3200 video). $ cat /proc/acpi/video/VGA/LCD/brightness to discover the possible values for your display.

Get AWS temporary credentials ready to export based on a MFA virtual appliance
You might want to secure your AWS operations requiring to use a MFA token. But then to use API or tools, you need to pass credentials generated with a MFA token. This commands asks you for the MFA code and retrieves these credentials using AWS Cli. To print the exports, you can use: `awk '{ print "export AWS_ACCESS_KEY_ID=\"" $1 "\"\n" "export AWS_SECRET_ACCESS_KEY=\"" $2 "\"\n" "export AWS_SESSION_TOKEN=\"" $3 "\"" }'` You must adapt the command line to include: * $MFA_IDis ARN of the virtual MFA or serial number of the physical one * TTL for the credentials

a short counter
Maybe you know shorter ?

Log colorizer for OSX (ccze alternative)
Download colorizer by @raszi @ http://github.com/raszi/colorize

add all files not under version control to repository
This should handle whitespaces well and will not get confused if your filenames have "?" in them

Sort netflow packet capture
Sort netflow packet capture by unique connections excluding source port.

back ssh from firewalled hosts
host B (you) redirects a modem port (62220) to his local ssh. host A is a remote machine (the ones that issues the ssh cmd). once connected port 5497 is in listening mode on host B. host B just do a ssh 127.0.0.1 -p 5497 -l user and reaches the remote host'ssh. This can be used also for vnc and so on.


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: