Bootstrap FreeKB - Linux Commands - List the amount of space being using the du (disk usage) command
Linux Commands - List the amount of space being using the du (disk usage) command

Updated:   |  Linux Commands articles

Let's say John Doe has the following files and directories.

/home/john.doe/foo.txt
/home/john.doe/files/bar.txt

 

Assuming your present working directory is /home/john.doe, the du command without any options will return something like this.

  • 4 ./files means that the "files" directory contains 4 KB of files
  • 8 . means that there are 8 KB of files at and below the present working directory (/home/john.doe)
[john.doe@server001 ~]$ du
4       ./files
8       .

 

Often, it is much easier to use the --human-readable flag.

[john.doe@server001 ~]$ du --human-readable
4.0K       ./files
8.0K       .

 

The -s or --summarize flags can be used to provide a summary of the size of each directory, instead of each individual file. In this example, there are 8 KB of files at and below the present working directory (/home/john.doe).

[john.doe@server001 ~]$ du --human-readable --summarize
8.0K       .

 

The --exclude option can be used to exclude directories. In this example, the /home/john.doe/files directory is excluded.

[john.doe@server001 ~]$ du --human-readable --summarize --exclude /home/john.doe/files
4.0K       .

 

And here is how you an include hidden files and directories in the output.

[john.doe@server001 ~]$ du --human-readable --summarize $(ls -A /home/john.doe)
4.0K foo
2.5M .bar

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter b4e163 in the box below so that we can be sure you are a human.