The Linux du command is used to display the disk footprint of a directory or file.
Linux du command Function Description
Use the du command to display the disk footprint of a directory or file.
Goes step-by-step to each subdirectory of the specified directory and displays how much of the file system data blocks are occupied by that directory. If no file or directory name is given, then the current directory is counted.
Linux du command Syntax
du [option] [file|directory]
The meaning of each option in the command is shown in the table.
Option | Description |
---|---|
-s |
Only the total usage of each parameter in the command column is calculated separately |
-a |
Export the disk usage of all files, not just directories |
-c |
Display Total information |
-l |
If it is hardwired, the dimensions are computed several times |
-x |
Skip directories on different file systems |
-h |
Display in KB, MB, GB to improve the readability of information |
-S |
Excluding subdirectory occupancy |
-L |
Find the true destination of any symbolic link indication |
Linux du command Examples
Displays the disk footprint of the /home/deepinout/examples.desktop file.
du /home/deepinout/examples.desktop
Output:
Displays the /home/deepinout/examples.desktop
file with a disk footprint of 12KB
Displays the /root directory disk footprint.
[root@rhel ~]# du -s /root
1216 /root
// Displays the /root directory disk footprint as 1216KB
Displays the /root directory disk footprint in MB.
[root@rhel ~]# du -sh /root
1.2M /root
//Displays the /root directory disk usage as 1.2MB
File sorted from largest to smallest
ubuntu@VM-0-14-ubuntu:~/git-work/linux-command$ du -sh * |sort -rh
2.9M command
1.9M assets
148K template
72K package-lock.json
52K dist
28K build
16K README.md
4.0K renovate.json
4.0K package.json
4.0K LICENSE
Displays only the size of the subdirectories in the current directory.
ubuntu@VM-0-14-ubuntu:~/git-work/linux-command$ du -sh ./*/
1.9M ./assets/
28K ./build/
2.9M ./command/
52K ./dist/
148K ./template/
View the space occupied by the files in the specified directory.
ubuntu@VM-0-14-ubuntu:~/git-work/linux-command/assets$ du ./*
144 ./alfred.png
452 ./chrome-extensions.gif
4 ./dash-icon.png
1312 ./Linux.gif
16 ./qr.png
Only the size of the sum is displayed.
ubuntu@VM-0-14-ubuntu:~/git-work/linux-command/assets$ du -s .
1932 .
Displays the size of the sum and is easy to read.
ubuntu@VM-0-14-ubuntu:~/git-work/linux-command/assets$ du -sh .
1.9M .