How to find large directories

Use this simple command to find large directories. To find directories over 1GB.
backup:/# du -h / | grep ^[0-9.]*G
The above command will display something like the following.

backup:/# du -h / | grep ^[0-9.]*G
du: cannot access `/proc/6451/task/6451/fd/4': No such file or directory
du: cannot access `/proc/6451/task/6451/fdinfo/4': No such file or directory
du: cannot access `/proc/6451/fd/4': No such file or directory
du: cannot access `/proc/6451/fdinfo/4': No such file or directory
1.3G    /opt/splunk/var/lib/splunk/defaultdb/db/hot_v1_0/rawdata
3.2G    /opt/splunk/var/lib/splunk/defaultdb/db/hot_v1_0
3.2G    /opt/splunk/var/lib/splunk/defaultdb/db
3.2G    /opt/splunk/var/lib/splunk/defaultdb
3.2G    /opt/splunk/var/lib/splunk
3.2G    /opt/splunk/var/lib
3.5G    /opt/splunk/var
3.7G    /opt/splunk
3.8G    /opt

To find directories over 10GB and sort the output with the largest directories on top

[root@localhost]# du -h / | grep ^[1-9][0-9][0-9.]*G | sort -rn

To find directories over 200GB

[root@localhost]# du -h / | grep ^[2-9][0-9][0-9][0-9.]*G

du – h Lists directory sizes in human readable format
/ Tells the du command to search the / (root) directory. It could easily
be another directory such as /home/ or /var/log/
| The | or pipe symbol sends the output of the “du -h /” command to
the following command.
grep Grep searches through the output looking for strings matching the
following regular expression.
^[1-9][0-9][0-9.]*G A regular expression^ Represents the start of the string

[1-9] Represents digits 1-9

[0-9] Represents digits 0-9

[0-9.] Represents digits 0-9 or . (the “dot” character is a special
character and must have a in front to show we are looking for a “dot”

* Represents the previous expression ([0-9.]) Zero or more times.

G Represents the capital letter G. When du outputs data in human
readable format, Gigabytes are represented by “G”.

| The Pipe symbol again. This time it is used to send output to the sort command.
sort -rn This command sorts the output from the other commands with the largest directories on top.
Posted on: 19/07/2010








0 Comments
If you want to leave a comment please Login or Register
Playing with printer......
Allow specific IP via htaccess......
How to find large directories......