Walker News

Some du Sample Commands To Check Linux Folder And File Size Information

The du command, probably an acronym of “disk usage” or “directory usage”, is handy to print folder and file size information in Linux command prompt as well as Linux shell script.

In Microsoft Windows, you can highlight some files in folder then right click on them and select Properties to check total files sizes of those selected files. Can this be done in Linux? How to do it?

Certainly, Linux can do what Windows does. In Linux command prompt, use wildcard character to select some files in directory and use du command to display a grand total of file size for those selected files:
  • the -c option switch is to print a grand total of file size, and
  • the -h option switch is to display the file size information in a user-friendly format
WalkerNews.net # du -ch *.tgz
24M     drt1.tgz
31M     drt2.tgz
55M     total
  • use -k to display file size information in KB only:
WalkerNews.net # du -ck *.tgz
24040   drt1.tgz
31600   drt2.tgz
55640   total

Now, suppose you would like to check or display the size of current folder (working directory), please use the -s option switch (optionally, use -m option switch to show the folder size in MB format or -h to get human-readable format):
WalkerNews.net # du -sm
11764   .
WalkerNews.net # du -sh
12G     .

To display the size of all folders (up to 1 level depth of directory), use the --max-depth=1 modifier:
WalkerNews.net # du -h --max-depth=1
16K     ./lost+found
3.2G    ./backup
95M     ./kiv
12G     .

As you can see, the 12GB refers to current working directory size, indicates there are some other files taking quite a lot of disk space, which together with the “backup” and “kiv” folders eat up to 12GB of disk space.

In order to display all the folders size (1 level depth of directory) as well as size of files in current folder, use this sample of du command:
du -sh *

Custom Search

2017  •  Privacy Policy