Skip to content

Instantly share code, notes, and snippets.

@sn0rk64
Last active February 8, 2022 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sn0rk64/91be66afb351719f2e07b7121cc96ff7 to your computer and use it in GitHub Desktop.
Save sn0rk64/91be66afb351719f2e07b7121cc96ff7 to your computer and use it in GitHub Desktop.

Output the file sizes in human-readable format.

ls -laSh /var/www/html

And to sort in reverse order, add the -r flag as follows.

ls -laShr /var/www/html

List subdirectories recursively using the -R option.

ls -laShR /var/www/html

Display the disk usage of the first-level subdirectories.

du -shc *

Sort ascending.

du -shc * | sort -h

Sort descending.

du -shc * | sort -hr

The same, but with hidden files included.

du -sch .[!.]* *

Find out top 10 files and directories in human readable format.

du -Sh /var/www/html | sort -rh | head -10

Explanation.

du -a: show for all files and directories.
du -h: display sizes in human readable format (e.g., 1K, 234M, 2G).
du -s: show only a total for each argument (summary). Doesn't work with -a.
du -S: do not include the size of subdirectories.
du -x: skip directories on different file systems.
sort -r: reverse the result of comparisons.
sort -h: compare human readable numbers. This is GNU sort specific option only.
head -10 OR -n 10: show the first 10 lines.


Use the df command to know the free space in the filesystem containing the directory.

df -h .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment