You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
1.4 KiB
Plaintext

# du
# Estimate file space usage
# With 'root' privileges, use du(1), sort(1), and head(1) to display a list of
# the top 20 space-consuming files in whichever storage medium '/' is mounted.
#
# Here, du(1) is using the `-x` flag to keep to the one filesystem, which is
# important for getting accurate results on the filesystem on which you
# might, for example, be needing to free space.
#
# In order to sort the human-readable file sizes, sort(1) is using the `-h`
# flag, the `-k` flag to specify the column to sort (first), and its using
# the `-r` flag to reverse the sorting, so we see the highest size first.
#
# To then show the top-20 lines, we use head(1) and specify the number of lines
# via the `-n` flag. The default number of lines displayed by head(1) and
# tail(1) is 10.
#
# Root privileges are gained for this task by using sudo(8) on bash(1) in order
# to have a new root-owned BASH session, which then executes the commands
# proceeding the `-c` flag.
sudo bash -c 'du -xh / | sort -rhk 1 | head -n 20'
# Display just the total human-readable size of the current working directory.
du -sh
# Display the total human-readable size of the three provided directories, as
# well as the grand total of the combined directories.
du -chs ~/Desktop ~/Pictures ~/Videos
# You could potentially make this task a bit easier with BASH brace expansion.
du -chs ~/{Desktop,Pictures,Videos}