Get your server issues fixed by our experts for a price starting at just 25 USD/Hour. Click here to register and open a ticket with us now!

Author Topic: Some useful switches for “du – disk usage”  (Read 1591 times)

0 Members and 1 Guest are viewing this topic.

sujitht

  • Guest
Some useful switches for “du – disk usage”
« on: July 15, 2017, 10:57:07 pm »
Most commonly used form

# du -sch
---------
h -> human readable format.
c -> display a total size usage at the end of result.
s -> display total size of a file or total size of all files in a directory.

Usage:
Code: [Select]
# du -s /home/abl
213932 /home/abl
# du -sh /home/abl
209M /home/abl
# du -sch /home/abl
209M /home/abl
209M total
Listing all files and directories, switch “a”
--------------------------------------------
# du -ah

a -> this switch displays disk usage of all individual files and directories.

Usage:
Code: [Select]
# du -ah /home/Downloads | tail

0 /home/Downloads/all_databases
2.7M /home/Downloads/18_cloudflare_v0_1_noans.pptx
24K /home/Downloads/assessment.odt
2.0M /home/Downloads/final.pptx
60M /home/Downloads/images1602396421.zip
4.0K /home/Downloads/ca.crt
4.0K /home/Downloads/ca (1).crt
16K /home/Downloads/Lamp.txt
60K /home/Downloads/winmail.dat
154M /home/Downloads

Exclude something from the command output, using –exclude

# du –exclude

-–exclude -> This switch will avoid the particular file name that we have mentioned.
In the below example du -ah avoid files ending with .txt (–exclude=”*.txt”)
Code: [Select]
# du -ah --exclude="Lamp.txt"  /home/Downloads | tail
5.0M /home/Downloads/Best_Practices_for_CS_final.pptx
0 /home/Downloads/all_databases
2.7M /home/Downloads/18_cloudflare_v0_1_noans.pptx
24K /home/Downloads/assessment.odt
2.0M /home/Downloads/final.pptx
60M /home/Downloads/images1602396421.zip
4.0K /home/Downloads/ca.crt
4.0K /home/Downloads/ca (1).crt
60K /home/Downloads/winmail.dat
154M /home/Downloads
Display modification time of files/folders, using –time

# du –time

–time ->This option shows the modification date and time of the file/directories.

# du -sch –time *

Code: [Select]
23M 2016-10-14 01:23 Downloads.tar.gz
24K 2016-11-28 17:22 Questions.odt
4.0K 2012-12-04 07:58 index.html
52K 2017-06-10 16:23 monitoring-cacti.png
20K 2016-10-31 22:31 MH
452K 2017-05-23 05:32 Scriptz.ctb
0 2017-02-27 18:30 msn.lock
36K 2017-03-16 22:16 Music
4.0K 2017-05-06 17:07 nginx.docu.txt
34M 2017-06-27 21:15 Pictures
380K 2017-03-18 10:46 Public
8.0K 2016-11-01 18:51 Report_updated.xlsx
4.0K 2016-10-03 17:24 Templates
28M 2016-10-14 18:05 test docs
4.0K 2017-04-01 08:51 ticket
48K 2016-12-10 00:28 Videos
514M 2017-07-15 21:35 total