How do I get the size of a directory on the command line?
I tried to obtain the size of a directory (containing directories and sub directories) by using the
lscommand with option
l. It seems to work for files (
ls -l file name), but if I try to get the size of a directory (for instance,
ls -l /home), I get only 4096 bytes, although altogether it is much bigger.
1) Strictly speaking, you can't. Linux has directories, not folders. 2) There's a difference between the size of a directory (which is a special file holding inodes that point to other files), and the size of the contents of that directory. As others have pointed out, the du command provides the latter, which is what it appears you want.
as you seem to be new, I'll just point out the helpful `-h` option you can add to the `-l` option (i.e. `ls -lh`) to get the sizes of files to be printed out in human-friendly notation like 1.1M instead of 1130301. The "h" in the `du -hs` command that @sam gave as the answer for your question about directories also means "human-readable", and it also appears in `df -h` which shows the human readable amounts of used and free space on disk.
du -sh file_path
du(disc usage) command estimates file_path space usage
-s, --summarize display only a total for each argument -h, --human-readable print sizes in human readable format (e.g., 1K 234M 2G)
To check more than one directory and see the total, use
-c, --total produce a grand total
...unless you have hardlinks ;-) http://stackoverflow.com/questions/19951883/du-counting-hardlinks-towards-filesize