Tag Info

Hot answers tagged

229

Use GNU coreutils >= 7.5: du -hs * | sort -h


44

du | sort -nr | cut -f2- | xargs du -hs


22

@Douglas Leeder, one more answer: Sort the human-readable output from du -h using another tool. Like Perl! du -h | perl -e 'sub h{%h=(K=>10,M=>20,G=>30);($n,$u)=shift=~/([0-9.]+)(\D)/; return $n*2**$h{$u}}print sort{h($b)<=>h($a)}<>;' Split onto two lines to fit the display. You can use it this way or make it a one-liner, it'll work ...


13

As far as I can see you have three options: Alter du to sort before display. Alter sort to support human sizes for numerical sort. Post process the output from sort to change the basic output to human readable. You could also do du -k and live with sizes in KiB. For option 3 you could use the following script: #!/usr/bin/env python import sys import ...


11

I've had that problem as well and I'm currently using a workaround: du -scBM | sort -n This will not produce scaled values, but always produce the size in megabytes. That's less then perfect, but for me it's better than nothing (or displaying the size in bytes).


11

Found this posting elsewhere. Therefore, this shell script will do what you want without calling du on everything twice. It uses awk to convert the raw bytes to a human-readable format. Of course, the formatting is slightly different (everything is printed to one decimal place precision). #/bin/bash du -B1 | sort -nr |awk '{sum=$1; ...


9

find /my/dir -type f | while read filename ; do fuser -s $filename || echo $filename ; done This uses find just to generate a list of files. Then the while loop iterates over the list of results, for each result it runs fuser -s $filename which will exit with success if something is using the file. The || echo $filename part means "if fuser failed ...


8

Briefly... Linux is a kernel, FreeBSD is an Operating System. So you really can't compare them like you want. The major distributions of Linux each have various levels of compatibility and differences... but I'll try to hit the things you named at least: There are a couple different package managers (dpkg and rpm probably being the most popular) for Linux ...


7

This version uses awk to create extra columns for sort keys. It only calls du once. The output should look exactly like du. I've split it into multiple lines, but it can be recombined into a one-liner. du -h | awk '{printf "%s %08.2f\t%s\n", index("KMG", substr($1, length($1))), substr($1, 0, length($1)-1), $0}' | sort -r | cut -f2,3 ...


6

yes it will; but you dont have to reboot the server; try: rndc flush or just restart bind


6

Hmm. glibc 2.5 is a dependency on pretty much everything in CentOS5. If you change it to glibc 2.7, your box will explode. Here's some discussion over in the CentOS forums: https://www.centos.org/modules/newbb/viewtopic.php?topic_id=28345&forum=41 https://www.centos.org/modules/newbb/viewtopic.php?viewmode=flat&topic_id=27133&forum=38


5

I'd suggest that you read almost all of man sudoers to gain a thorough understanding of what this does, but you want to do this: %users ALL=(dummy) /bin/chown *


5

I haven't heard of it before now, but my knee-jerk reaction is "not another httpd". Apache is the Swiss-Army knife; Nginx is fast, IIS is the MS solution. There are others that fulfill a niche need in certain markets, but many suffer from being ill maintained, and have small followings. If it works for you, I'm all for it. But if you're starting from ...


5

Here's an example that shows the directories in a more compact summarized form. It handles spaces in directory/filenames. % du -s * | sort -rn | cut -f2- | xargs -d "\n" du -sh 53G projects 21G Desktop 7.2G VirtualBox VMs 3.7G db 3.3G SparkleShare 2.2G Dropbox 272M apps 47M incoming 14M bin 5.7M rpmbuild 68K vimdir.tgz


5

Got another one: $ du -B1 | sort -nr | perl -MNumber::Bytes::Human=format_bytes -F'\t' -lane 'print format_bytes($F[0])."\t".$F[1]' I'm starting to like perl. You might have to do a $ cpan Number::Bytes::Human first. To all the perl hackers out there: Yes, I know that the sort part can also be done in perl. Probably the du part, too.


5

I've a simple but useful python wrapper for du called dutop. Note that we (the coreutils maintainers) are considering adding the functionality to sort to sort "human" output directly.


4

Use the "-g" flag -g, --general-numeric-sort compare according to general numerical value And on my /usr/local directory produces output like this: $ du |sort -g 0 ./lib/site_ruby/1.8/rubygems/digest 20 ./lib/site_ruby/1.8/rubygems/ext 20 ./share/xml 24 ./lib/perl 24 ./share/sgml 44 ./lib/site_ruby/1.8/rubygems/package 44 ...


4

I got this from inside the help screen in nano by pressing ctrl-g: Ctrl F-Key Esc Key ^^ (F15) (M-A) Mark text at the cursor position M-^ (M-6) Copy the current line and store it in the cutbuffer ^U (F10) Uncut from the cutbuffer into the current line ^ = ctrl M = esc So you position your cursor at the ...


4

To discover which Linux flavor you're running, type the following commands: ls -al /etc/*release cat /etc/*release ls -la /etc/*version cat /etc/*version Depending on which Linux flavor you're running, you'll have a file that match one of above criteria, telling the Linux version. For example, RedHat has a /etc/redhat-release and Debian has a ...


4

"ps" displays the UID number if the user name is too long for the display, On Debian systems which include the "Debian-exim" user it is common to see this as the UID instead. This is probably what you're seeing. The presence of a '-' is a red herring here, and it happens everywhere that uses procps, not just Debian and Ubuntu: ...


4

Simply add a route for that IP to your local gateway. You can do this in your openvpn client config like this. route 10.99.77.55 255.255.255.255 net_gateway In the config net_gateway is automatically replaced with the correct address.


4

find / -user alice -print0 | du -ch --files0-from=-


3

Assuming you want to run ten times, this syntax will work: parallel -n0 foo.sh ::: {1..10} parallel needs an input sequence of some length (::: {1..10}) AND you need to ignore the contents of the input sequence(-n0), you only care about its length. Your original command: parallel foo.sh, contains no input sequence to indicate how much parallelism you ...


3

The main claim to fame of UnxUtils is that it sits on top of MSVCRT.dll as opposed to glibc. This means that it is aware of native windows paths (i.e. you can use commands like ls c:). Some (particularly cygwin and SFU) map native DOS path names under a unix-like tree structure. Native DOS path support is useful if you want to execute unix commands from ...


3

Another one: du -h | perl -e' @l{ K, M, G } = ( 1 .. 3 ); print sort { ($aa) = $a =~ /(\w)\s+/; ($bb) = $b =~ /(\w)\s+/; $l{$aa} <=> $l{$bb} || $a <=> $b } <>'


3

This snippet was shameless snagged from 'Jean-Pierre' from http://www.unix.com/shell-programming-scripting/32555-du-h-sort.html. Is there a way I can better credit him? du -k | sort -nr | awk ' BEGIN { split("KB,MB,GB,TB", Units, ","); } { u = 1; while ($1 >= 1024) { $1 = $1 / 1024; u += 1 ...


2

Found this one on line... seems to work OK du -sh * | tee /tmp/duout.txt | grep G | sort -rn ; cat /tmp/duout.txt | grep M | sort -rn ; cat /tmp/duout.txt | grep K | sort -rn ; rm /tmp/duout.txt


2

I learned awk from concocting this example yesterday. It took some time, but it was great fun, and I learned how to use awk. It runs only du once, and it has a output much similar to du -h du --max-depth=0 -k * | sort -nr | awk '{ if($1>=1024*1024) {size=$1/1024/1024; unit="G"} else if($1>=1024) {size=$1/1024; unit="M"} else {size=$1; unit="K"}; ...



Only top voted, non community-wiki answers of a minimum length are eligible