Linux du command - display the disk footprint of a directory or file

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:

Linux du command

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    .
Like(1)

Related

Linux Login Logout Command
Linux login commandLinux logout commandLinux nologin commandLinux exit commandLinux sulogin commandLinux rlogin commandLinux poweroff commandLinux ctrlaltdel CommandLinux shutdown commandLinux halt commandLinux reboot commandLinux init commandLinux runlevel commandLinux telinit command
Linux File Management Command
Linux cat commandLinux tac commandLinux nl commandLinux more commandLinux less commandLinux head commandLinux tail commandLinux rev commandLinux fold commandLinux fmt commandLinux expand commandLinux pr commandLinux sort commandLinux uniq commandLinux cut commandLinux comm commandLinux diff commandLinux join commandLinux diff3 commandLinux cmp commandLinux colrm commandLinux paste commandLinux mkdir commandLinux tr commandLinux split commandLinux csplit commandLinux tee commandLinux unexpand commandLinux patch commandLinux awk commandLinux sed commandLinux od commandLinux pwd commandLinux cd commandLinux ls commandLinux dir commandLinux dirs commandLinux touch commandLinux rmdir commandLinux cp commandLinux mv commandLinux rm commandLinux install commandLinux tmpwatch commandLinux file commandLinux du commandLinux wc commandLinux tree commandLinux cksum commandLinux md5sum commandLinux sum commandLinux dirname commandLinux mkfifo Command
Cron Expressions
Cron Expression to Run Every Day at 12 PMUnderstanding Vue Cron ExpressionsUnderstanding JS Cron ExpressionsA Comprehensive Guide to Cron Expressions for Scheduled TasksUnderstanding Linux Cron ExpressionsUnderstanding Quartz Cron ExpressionsCron ExpressionCron Time ExpressionCron Expression ParsingCron Expression: Executing a Task Every SecondCron Expression for Every Minute ExecutionCron Expression to Execute Every 10 MinutesCron Expression: Executing Every HourCron Expression to Execute Once a YearCron Expression: How to Schedule a Task to Run Daily at Midnight?