Showing posts with label du. Show all posts
Showing posts with label du. Show all posts

Thursday, September 22, 2016

du command examples in linux ?

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 recursively manner.

1. To find out the disk usage summary of a /home/minazul directory tree and each of its sub directories. Enter the command as:
[root@linuxforfreshers.com]# du  /home/minazul
40      /home/minazul/downloads
4       /home/minazul/.mozilla/plugins
4       /home/minazul/.mozilla/extensions
12      /home/minazul/.mozilla
12      /home/minazul/.ssh
689112  /home/minazul/Ubuntu-12.10
689360  /home/minazul

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


2. Using “-h” option with “du” command provides results in “Human Readable Format“. Means you can see sizes in Bytes, Kilobytes, Megabytes, Gigabytes etc.
[root@linuxforfreshers.com]# du -h /home/minazul
40K     /home/minazul/downloads
4.0K    /home/minazul/.mozilla/plugins
4.0K    /home/minazul/.mozilla/extensions
12K     /home/minazul/.mozilla
12K     /home/minazul/.ssh
673M    /home/minazul/Ubuntu-12.10
674M    /home/minazul


3. To get the summary of a grand total disk usage size of an directory use the option “-s” as follows.
[root@linuxforfreshers.com]# du -sh /home/minazul
674M    /home/minazul


4. Using “-a” flag with “du” command displays the disk usage of all the files and directories.
[root@linuxforfreshers.com]# du -a /home/minazul
4       /home/minazul/.bash_logout
12      /home/minazul/downloads/uploadprogress-1.0.3.1.tgz
24      /home/minazul/downloads/Phpfiles-org.tar.bz2
40      /home/minazul/downloads
12      /home/minazul/uploadprogress-1.0.3.1.tgz
4       /home/minazul/.mozilla/plugins
4       /home/minazul/.mozilla/extensions
12      /home/minazul/.mozilla
4       /home/minazul/.bashrc
689108  /home/minazul/Ubuntu-12.10/ubuntu-12.10-server-i386.iso
689112  /home/minazul/Ubuntu-12.10
689360  /home/minazul


5. Using “-a” flag along with “-h” displays disk usage of all files and folders in human readeable format. The below output is more easy to understand as it shows the files in Kilobytes, Megabytes etc.
[root@linuxforfreshers.com]# du -ah /home/minazul
4.0K    /home/minazul/.bash_logout
12K     /home/minazul/downloads/uploadprogress-1.0.3.1.tgz
24K     /home/minazul/downloads/Phpfiles-org.tar.bz2
40K     /home/minazul/downloads
12K     /home/minazul/uploadprogress-1.0.3.1.tgz
4.0K    /home/minazul/.mozilla/plugins
4.0K    /home/minazul/.mozilla/extensions
12K     /home/minazul/.mozilla
4.0K    /home/minazul/.bashrc
673M    /home/minazul/Ubuntu-12.10/ubuntu-12.10-server-i386.iso
673M    /home/minazul/Ubuntu-12.10
674M    /home/minazul


6. Find out the disk usage of a directory tree with its subtress in Kilobyte blcoks. Use the “-k” (displays size in 1024 bytes units).
[root@linuxforfreshers.com]# du -k /home/minazul
40      /home/minazul/downloads
4       /home/minazul/.mozilla/plugins
4       /home/minazul/.mozilla/extensions
12      /home/minazul/.mozilla
12      /home/minazul/.ssh
689112  /home/minazul/Ubuntu-12.10
689360  /home/minazul


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.
[root@linuxforfreshers.com]# du -mh /home/minazul
40K     /home/minazul/downloads
4.0K    /home/minazul/.mozilla/plugins
4.0K    /home/minazul/.mozilla/extensions
12K     /home/minazul/.mozilla
12K     /home/minazul/.ssh
673M    /home/minazul/Ubuntu-12.10
674M    /home/minazul


8. The “-c” flag provides a grand total usage disk space at the last line. If your directory taken 674MB space, then the last last two line of the output would be.
[root@linuxforfreshers.com]# du -ch /home/minazul
40K     /home/minazul/downloads
4.0K    /home/minazul/.mozilla/plugins
4.0K    /home/minazul/.mozilla/extensions
12K     /home/minazul/.mozilla
12K     /home/minazul/.ssh
673M    /home/minazul/Ubuntu-12.10
674M    /home/minazul
674M    total


9. The below command calculates and displays the disk usage of all files and directories, but excludes the files that matches given pattern. The below command excludes the “.txt” files while calculating the total size of diretory. So, this way you can exclude any file formats by using flag “-–exclude“. See the output there is no txt files entry.
[root@linuxforfreshers.com]# du -ah --exclude="*.txt" /home/minazul
4.0K    /home/minazul/.bash_logout
12K     /home/minazul/downloads/uploadprogress-1.0.3.1.tgz
24K     /home/minazul/downloads/Phpfiles-org.tar.bz2
40K     /home/minazul/downloads
12K     /home/minazul/uploadprogress-1.0.3.1.tgz
4.0K    /home/minazul/.bash_history
4.0K    /home/minazul/.bash_profile
4.0K    /home/minazul/.mozilla/plugins
4.0K    /home/minazul/.mozilla/extensions
12K     /home/minazul/.mozilla
4.0K    /home/minazul/.bashrc
24K     /home/minazul/Phpfiles-org.tar.bz2
4.0K    /home/minazul/geoipupdate.sh
4.0K    /home/minazul/.zshrc
120K    /home/minazul/goaccess-0.4.2.tar.gz.1
673M    /home/minazul/Ubuntu-12.10/ubuntu-12.10-server-i386.iso
673M    /home/minazul/Ubuntu-12.10
674M    /home/minazul


10. Display the disk usage based on modification of time, use the flag “–time” as shown below.
[root@linuxforfreshers.com]# du -ha --time /home/minazul
4.0K    2015-10-12 22:32        /home/minazul/.bash_logout
12K     2015-01-19 18:48        /home/minazul/downloads/uploadprogress-1.0.3.1.tgz
24K     2015-01-19 18:48        /home/minazul/downloads/Phpfiles-org.tar.bz2
40K     2015-01-19 18:48        /home/minazul/downloads
12K     2015-01-19 18:32        /home/minazul/uploadprogress-1.0.3.1.tgz
4.0K    2012-10-13 00:11        /home/minazul/.bash_history
4.0K    2012-10-12 22:32        /home/minazul/.bash_profile
0       2013-01-19 18:32        /home/minazul/xyz.txt
0       2013-01-19 18:32        /home/minazul/abc.txt
4.0K    2012-10-12 22:32        /home/minazul/.mozilla/plugins
4.0K    2012-10-12 22:32        /home/minazul/.mozilla/extensions
12K     2012-10-12 22:32        /home/minazul/.mozilla
4.0K    2012-10-12 22:32        /home/minazul/.bashrc
24K     2013-01-19 18:32        /home/minazul/Phpfiles-org.tar.bz2
4.0K    2013-01-19 18:32        /home/minazul/geoipupdate.sh
4.0K    2012-10-12 22:32        /home/minazul/.zshrc
120K    2013-01-19 18:32        /home/minazul/goaccess-0.4.2.tar.gz.1
673M    2013-01-19 18:51        /home/minazul/Ubuntu-12.10/ubuntu-12.10-server-i386.iso
673M    2013-01-19 18:51        /home/minazul/Ubuntu-12.10

674M    2013-01-19 18:52        /home/minazul

Friday, January 15, 2016

What is the command for finding the highest memory occupied file in Linux ?



# du –ah / | sort –n –r | head –n 1

Option Explanations :du  – estimate file space usage
a – write counts for all files, not just directories
h – print sizes in human readable format (eg. 1K 234M 2G)
sort – sort lines of text files
n – compare according to string numerical value
r – reverse the result of comparisons
head – output the first part of files

n – number of lines