Linux disk use by directory

How to analyse disk usage in command line linux?

du and df are nice, but I don’t know how to filter the data they provide the way I do with SequoiaView. I would like to know which are the largest folders and the largest files in a glance.

7 Answers 7

You might also want to try the NCurses Disk Usage aka ncdu .

Use it like ncdu -x -q if you’re invoking it remotely (e. g. via ssh ) and ncdu -x otherwise.

ncdu 1.6 ~ Use the arrow keys to navigate, press ? for help --- /home/geek ----------------------------------------------------------------- 27.6MiB /qm test 1 rework 312.0kiB /sidebar 88.0kiB /rackerhacker-MySQLTuner-perl-6add618 8.0kiB /.w3m 4.0kiB /.cache e 4.0kiB /.ssh 160.0kiB ng.tar.gz 76.0kiB plowshare_1~svn1673-1_all.deb 4.0kiB .bashrc 4.0kiB .bash_history 4.0kiB .profile 4.0kiB .htoprc 4.0kiB .bash_logout 0.0 B .lesshst 

This is available under Mac OS X too.

The following flags to the command line might be helpful:

-q Quiet mode, doesn't update the screen 10 times a second while scanning, reduces network bandwidth used -x Don't cross filesystem borders (don't descend into a directory which is a mounted disk) 

Use some combination of the commands and options:

du --max-depth=1 2> /dev/null | sort -n -r | head -n20 

to view only the largest few. If you’d like to use it a lot, then bind it to an alias, e.g. in bash by adding to ~/.bashrc

alias largest='du --max-depth=1 2> /dev/null | sort -n -r | head -n20' 

I submitted @RedGrittyBrick suggestion and an error redirection to /dev/null as an edit subject to approval.

My modified version of this to display values in human readable format: du -h —max-depth=1 2> /dev/null | sort -h -r

Читайте также:  Linux permission to move files

I would like to recommend dutree, which offers a hierachical visualization.

You can select more or less levels of detail, and exclude paths for better control of visualization. You can also compare different paths.

enter image description here

It is implemented in Rust, fast and efficient.

$ dutree -h Usage: dutree [options] [..] Options: -d, --depth [DEPTH] show directories up to depth N (def 1) -a, --aggr [N[KMG]] aggregate smaller than N B/KiB/MiB/GiB (def 1M) -s, --summary equivalent to -da, or -d1 -a1M -u, --usage report real disk usage instead of file size -b, --bytes print sizes in bytes -f, --files-only skip directories for a fast local overview -x, --exclude NAME exclude matching files or directories -H, --no-hidden exclude hidden files -A, --ascii ASCII characters only, no colors -h, --help show help -v, --version print version number 

Источник

10 Useful du (Disk Usage) Commands to Find Disk Usage of Files and Directories

The Linux “du” (Disk Usage) is a standard Unix/Linux command, used to check the information of disk usage of files and directories on a machine.

The du command has many parameter options that can be used to get the results in many formats. The du command also displays the files and directory sizes in a recursive manner.

Check Disk Usage In Linux

This article explains 10 useful “du” commands with their examples, which might help you to find out the sizes of files and directories in Linux. The information provided in this article is taken from the man pages of du command.

How to Find the Size of a Directory in Linux

1. To find out the disk usage summary of a /home/tecmint directory tree and each of its subdirectories. Enter the command as:

[[email protected]]# du /home/tecmint 40 /home/tecmint/downloads 4 /home/tecmint/.mozilla/plugins 4 /home/tecmint/.mozilla/extensions 12 /home/tecmint/.mozilla 12 /home/tecmint/.ssh 689112 /home/tecmint/Ubuntu-12.10 689360 /home/tecmint

The output of the above command displays the number of disk blocks in the /home/tecmint directory along with its sub-directories.

Читайте также:  Manjaro linux kde настройка

How to Find the Directory Size in Human Readable Format

2. Using the “-h” option with the “du” command provides results in “Human Readable Format“. This means you can see sizes in Bytes, Kilobytes, Megabytes, Gigabytes, etc.

[[email protected]]# du -h /home/tecmint 40K /home/tecmint/downloads 4.0K /home/tecmint/.mozilla/plugins 4.0K /home/tecmint/.mozilla/extensions 12K /home/tecmint/.mozilla 12K /home/tecmint/.ssh 673M /home/tecmint/Ubuntu-12.10 674M /home/tecmint

How to Find Total Size of a Directory in Linux

3. To get the summary of a grand total disk usage size of a directory uses the option “-s” as follows.

[[email protected]]# du -sh /home/tecmint 674M /home/tecmint

4. Using the “-a” flag with the “du” command displays the disk usage of all the files and directories.

[[email protected]]# du -a /home/tecmint 4 /home/tecmint/.bash_logout 12 /home/tecmint/downloads/uploadprogress-1.0.3.1.tgz 24 /home/tecmint/downloads/Phpfiles-org.tar.bz2 40 /home/tecmint/downloads 12 /home/tecmint/uploadprogress-1.0.3.1.tgz 4 /home/tecmint/.mozilla/plugins 4 /home/tecmint/.mozilla/extensions 12 /home/tecmint/.mozilla 4 /home/tecmint/.bashrc 689108 /home/tecmint/Ubuntu-12.10/ubuntu-12.10-server-i386.iso 689112 /home/tecmint/Ubuntu-12.10 689360 /home/tecmint

5. Using the “-a” flag along with “-h” displays disk usage of all files and folders in a human-readable format. The below output is easier to understand as it shows the files in Kilobytes, Megabytes, etc.

[[email protected]]# du -ah /home/tecmint 4.0K /home/tecmint/.bash_logout 12K /home/tecmint/downloads/uploadprogress-1.0.3.1.tgz 24K /home/tecmint/downloads/Phpfiles-org.tar.bz2 40K /home/tecmint/downloads 12K /home/tecmint/uploadprogress-1.0.3.1.tgz 4.0K /home/tecmint/.mozilla/plugins 4.0K /home/tecmint/.mozilla/extensions 12K /home/tecmint/.mozilla 4.0K /home/tecmint/.bashrc 673M /home/tecmint/Ubuntu-12.10/ubuntu-12.10-server-i386.iso 673M /home/tecmint/Ubuntu-12.10 674M /home/tecmint

6. Find out the disk usage of a directory tree with its subtree in Kilobyte blocks. Use the “-k” (displays size in 1024 bytes units).

[[email protected]]# du -k /home/tecmint 40 /home/tecmint/downloads 4 /home/tecmint/.mozilla/plugins 4 /home/tecmint/.mozilla/extensions 12 /home/tecmint/.mozilla 12 /home/tecmint/.ssh 689112 /home/tecmint/Ubuntu-12.10 689360 /home/tecmint

7. To get the summary of disk usage of directory tree along with its subtrees in Megabytes (MB) only. Use the option “-mh” as follows. The “-m” flag counts the blocks in MB units and “-h” stands for human-readable format.

[[email protected]]# du -mh /home/tecmint 40K /home/tecmint/downloads 4.0K /home/tecmint/.mozilla/plugins 4.0K /home/tecmint/.mozilla/extensions 12K /home/tecmint/.mozilla 12K /home/tecmint/.ssh 673M /home/tecmint/Ubuntu-12.10 674M /home/tecmint

8. The “-c” flag provides a grand total usage disk space at the last line. If your directory is taken 674MB space, then the last last two lines of the output would be.

[[email protected]]# du -ch /home/tecmint 40K /home/tecmint/downloads 4.0K /home/tecmint/.mozilla/plugins 4.0K /home/tecmint/.mozilla/extensions 12K /home/tecmint/.mozilla 12K /home/tecmint/.ssh 673M /home/tecmint/Ubuntu-12.10 674M /home/tecmint 674M total 

How to Exclude Files with du Command

9. The below command calculates and displays the disk usage of all files and directories, but excludes the files that match the given pattern. The below command excludes the “.txt” files while calculating the total size of a directory. So, this way you can exclude any file formats by using the flag “-–exclude“. See the output there is no txt files entry.

[[email protected]]# du -ah --exclude="*.txt" /home/tecmint 4.0K /home/tecmint/.bash_logout 12K /home/tecmint/downloads/uploadprogress-1.0.3.1.tgz 24K /home/tecmint/downloads/Phpfiles-org.tar.bz2 40K /home/tecmint/downloads 12K /home/tecmint/uploadprogress-1.0.3.1.tgz 4.0K /home/tecmint/.bash_history 4.0K /home/tecmint/.bash_profile 4.0K /home/tecmint/.mozilla/plugins 4.0K /home/tecmint/.mozilla/extensions 12K /home/tecmint/.mozilla 4.0K /home/tecmint/.bashrc 24K /home/tecmint/Phpfiles-org.tar.bz2 4.0K /home/tecmint/geoipupdate.sh 4.0K /home/tecmint/.zshrc 120K /home/tecmint/goaccess-0.4.2.tar.gz.1 673M /home/tecmint/Ubuntu-12.10/ubuntu-12.10-server-i386.iso 673M /home/tecmint/Ubuntu-12.10 674M /home/tecmint

How to Find Directory Usage By Modification Time

10. Display the disk usage based on a modification of time, use the flag “–time” as shown below.

[[email protected]]# du -ha --time /home/tecmint 4.0K 2012-10-12 22:32 /home/tecmint/.bash_logout 12K 2013-01-19 18:48 /home/tecmint/downloads/uploadprogress-1.0.3.1.tgz 24K 2013-01-19 18:48 /home/tecmint/downloads/Phpfiles-org.tar.bz2 40K 2013-01-19 18:48 /home/tecmint/downloads 12K 2013-01-19 18:32 /home/tecmint/uploadprogress-1.0.3.1.tgz 4.0K 2012-10-13 00:11 /home/tecmint/.bash_history 4.0K 2012-10-12 22:32 /home/tecmint/.bash_profile 0 2013-01-19 18:32 /home/tecmint/xyz.txt 0 2013-01-19 18:32 /home/tecmint/abc.txt 4.0K 2012-10-12 22:32 /home/tecmint/.mozilla/plugins 4.0K 2012-10-12 22:32 /home/tecmint/.mozilla/extensions 12K 2012-10-12 22:32 /home/tecmint/.mozilla 4.0K 2012-10-12 22:32 /home/tecmint/.bashrc 24K 2013-01-19 18:32 /home/tecmint/Phpfiles-org.tar.bz2 4.0K 2013-01-19 18:32 /home/tecmint/geoipupdate.sh 4.0K 2012-10-12 22:32 /home/tecmint/.zshrc 120K 2013-01-19 18:32 /home/tecmint/goaccess-0.4.2.tar.gz.1 673M 2013-01-19 18:51 /home/tecmint/Ubuntu-12.10/ubuntu-12.10-server-i386.iso 673M 2013-01-19 18:51 /home/tecmint/Ubuntu-12.10 674M 2013-01-19 18:52 /home/tecmint

Источник

Оцените статью
Adblock
detector