All BASH users (Linux, Unix, OSX, etc) use the ls command, but when we want to know how much disk space has been used, the ls command just doesn’t cut it sometimes. While it is a useful command for listing information about files in a directory, or the directory structure, it doesn’t give you the overall space that a directory uses – including the files inside of it. Sometimes you need a lot more information and the commands to do it are not commonly known. Here’s a typical output of the ls command:
user@localhost:~/Pictures$ ls -lh
-rw------- 1 user user 993K Jul 12 15:08 IMAG0142.jpg
-rw------- 1 user user 790K Jul 12 15:08 IMAG0143.jpg
-rw------- 1 user user 1.1M Jul 12 15:08 IMAG0144.jpg
-rw------- 1 user user 1.3M Jul 12 15:08 IMAG0145.jpg
-rw------- 1 user user 1.1M Jul 12 15:08 IMAG0146.jpg
-rw------- 1 user user 1.1M Jul 12 15:08 IMAG0147.jpg
Notice how the output shows the sizes of the files. However, if we cd .. and look at the directory itself, it shows this:
Although it is clearly stated above while in the Pictures directory that the content takes up 644 Megabytes of space, listing the directory itself only shows that it is 24 Kilobytes. That’s a little misleading, don’t you think?
In order to get around this issue, there is a different command that will do the trick; the du command.
The command as typed above shows the combined size of all directories in the present working directory. However, if you were to add a directory name to the command, you would have this output:
If you were to use a * instead of a directory name, you would retrieve the results of all of the directories in the current directory: