Folder Sizes
du prints the size of a folder. The size counts the folder and all the files inside it.
Three folders, three sizes
This command prints one line for each folder. The sizes are small, because the practice folder holds text files.
$ cd ~/practice
$ du -sh notes data projectsOne file
This command prints one line for a file too. The shopping list is one small file.
$ cd ~/practice
$ du -sh notes/shopping.txtThe whole folder
This command prints one total for the practice folder. The total is 36K.
$ cd ~/practice
$ du -sh .Example
$ cd ~/practice
$ du -sh notes data projects
$ du -sh .Key points
- Use du -sh with a folder name to print its size in one line.
- The -s option prints one total for the whole folder.
- The -h option prints the size in plain sizes like K.
- Use du -sh . to print the size of the current folder.
- Use du -sh with a file name to print the size of one file.
- In short, du measures a folder, and -sh keeps the answer to one line.
In this example, the first command moves into the practice folder. du -sh prints three lines next. notes is 8.0K, data is 12K, and projects is 8.0K. du -sh . prints the whole folder last. The total is 36K.
Note
The sizes count disk blocks, so a small file still shows 4.0K.
Try it Yourself
Edit the code, then press Run.
Running is simulated
Exercise
What does du -sh notes print?