26

Useful commands to check directory size

 5 years ago
source link: https://www.tuicool.com/articles/hit/R3Q3UvE
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Often times, there is a need to check the size of the sub-directories or files in a project, on a live or development server, or just at our local machine.

Here is a list of useful commands that you can leverage to make sure the available disk space of your machine is normal and that huge node_modules directory size hasn't gone crazy :D

We will use the du command , which is explained below:

du (disc usage) command estimates file_path space usage

The options -sh are (from man du):

  -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 du -sch:

-c, --total
         produce a grand total

So, let's see the basic commands:

Shows you the size of the directory in readable format:

$ du -sh directory/

Shows you a list with all the directories along with their sizes, ordered by size:

$ du -sh * | sort -h

Example in my example flutter project:

paul@paul-Inspiron-N5110:~/projects/flutter_test$ du -sh * | sort -h
4,0K    android.iml
4,0K    flutter_test_android.iml
4,0K    flutter_test.iml
4,0K    pubspec.yaml
4,0K    README.md
8,0K    test
12K lib
200K    android
212K    ios

Bonus:

Outputs the total and available size of your system's paritions

$ df -h

Outputs the inodes usage in your system:

$ df -i

If you have more useful commands to share, leave them in the comments below!


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK