Check the filesize or disk space usage of directories/files using du command

As a linux beginner, I tried to do stuff from the console as often as possible but for most of the time I ended up relying on the GUI. Filesize was one of those things. I don't know why I never searched for it but I came to know about du while looking at one of my seniors work on his system.

Du probably stands for "disk usage". You will usually need these two options - 'h' and 's'. e.g. If you want find out the size of a file, say a movie, then run the following command.

[shredder12]$ du movie.avi
718016 movie.avi

The output is in KiBs and is not readable for all of us. By using -h option, you can convert the output into human readable formats.

[shredder12]$ du -h movie.avi
702M movie.avi

Now, when you are dealing with directories, using du will recursively throw the output of all the directories, which might not be what you are looking for. In such cases, we use "-s", this summarizes the output to the total disk usage of the directory concerned.

Here is an example without "-s"

[shredder12]$ du -h movie/
4.0K movie/sub/en
4.0k movie/sub/fr
12k movie/sub
702M movie/

Now, with "-s"

[shredder12]$ du -sh movie/
702M movie/

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <img> <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote> <h1> <h2> <h3> <h4> <h5> <h6> <p> <br>
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Image links with 'rel="lightbox"' in the <a> tag will appear in a Lightbox when clicked on.

More information about formatting options

Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.