Difference between revisions of "How to check directory size in linux"

From Cyberlaw: Difficult Issues Winter 2010
Jump to navigation Jump to search
(Created page with "Find directory size with du -sh command in Linux The best Linux command to check directory size is using du -sh command. Open the terminal and type du -sh directory name in t...")
 
 
Line 2: Line 2:
 
The best Linux command to check directory size is using du -sh command.  Open the terminal and type du -sh directory name in the prompt. The directory size will be listed on the first column.  The size will be displayed in Human Readable Format. This means we can see directory sizes in Bytes, Kilobytes, Megabytes, Gigabytes, etc.
 
The best Linux command to check directory size is using du -sh command.  Open the terminal and type du -sh directory name in the prompt. The directory size will be listed on the first column.  The size will be displayed in Human Readable Format. This means we can see directory sizes in Bytes, Kilobytes, Megabytes, Gigabytes, etc.
  
-s, –summarize : display only a total size
+
* -s, –summarize : display only a total size
-h, –human-readable : print sizes in human readable format (e.g., 1K 234M 2G)
+
* -h, –human-readable : print sizes in human readable format (e.g., 1K 234M 2G)
 
   
 
   
  
 
For example, the following command will check the size of the /etc directory: $ du -sh /etc. The output of this command will be something like this: 18M /etc
 
For example, the following command will check the size of the /etc directory: $ du -sh /etc. The output of this command will be something like this: 18M /etc
 
  
 
   
 
   
 
If we need to check the size of files and sub-directory under /etc/, we can use du -sh /etc/*.
 
If we need to check the size of files and sub-directory under /etc/, we can use du -sh /etc/*.
# du -sh /etc/*
+
 
4.0K /etc/adjtime
 
8.0K /etc/aide.conf
 
4.0K /etc/aliases
 
12K /etc/aliases.db
 
4.0K /etc/alternatives
 
  
 
[https://www.howtouselinux.com/post/check-directory-size-in-linux 5 ways to check directory size in Linux]
 
[https://www.howtouselinux.com/post/check-directory-size-in-linux 5 ways to check directory size in Linux]

Latest revision as of 11:29, 17 May 2022

Find directory size with du -sh command in Linux The best Linux command to check directory size is using du -sh command. Open the terminal and type du -sh directory name in the prompt. The directory size will be listed on the first column. The size will be displayed in Human Readable Format. This means we can see directory sizes in Bytes, Kilobytes, Megabytes, Gigabytes, etc.

  • -s, –summarize : display only a total size
  • -h, –human-readable : print sizes in human readable format (e.g., 1K 234M 2G)


For example, the following command will check the size of the /etc directory: $ du -sh /etc. The output of this command will be something like this: 18M /etc


If we need to check the size of files and sub-directory under /etc/, we can use du -sh /etc/*.


5 ways to check directory size in Linux