Linux: Find Out Directory Size Command

I am a new Linux user. How do I find out size of a directory on Linux operating systems using command line options?

You need to use the du command:

[a] Find and estimate file space usage.

[b] Summarize disk usage of each FILE/Directory/Folder.

[c] Shows the sizes of directories and files.


The basic syntax is:

du dirName
du [options] dirName


Without any options, du command shows the names and used space for each directories including all sub-directories in the current directory:
Sample outputs:

Fig.01: du command in action

To find information about /etc and /home/nixcraft directory, enter:
du /path/to/dir
du /etc
du /home/nixcraft
du /root /home/nixcraft

Pass the -h option to get output in human readable format i.e. show output in kilobytes (K), megabytes (M) and gigabytes (G):
du -h /etc
du -h /dir1/file2
du -h /root
du -h

Sample outputs:

8.0K	./.vim
24K	./scripts
48K	./.ssh
16K	./.keychain
2.2M	./.lftp
2.4M	.

Pass the -s option to see the total disk space used by a directory:
du -sh
du -sh /etc/
du -sh /etc /home/ /securebackup/

Sample outputs:

4.1M	/etc
152K	/home/
902M	/securebackup/

Pass the -c to see a grand total for all of the files, type:
du -csh /root/ /etc/ /home/
Sample outputs:

2.4M	/root/
4.1M	/etc/
152K	/home/
6.6M	total
See also

Posted by: SXI ADMIN

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.


How to KVM, QEMU start or stop virtual machine from command line (CLI)

KVM or Kernel Based Virtual Machine is a popular virtualization technology. It allows you to run virtual guest machines over a host machine. To start...

How to Docker backup Saving and restoring your volumes

Running a Docker volume backup First, we spin up a temporary container, and we mount the backup folder and the target Docker volume to this container....

How to Start and Enable Firewalld on CentOS 7

In this article, we discuss how to start and enable firewalld. It is highly recommended that you have a firewall protecting your server.Pre-Flight CheckThese...