Merge pull request #161 from terminalforlife/master

Add du(1) Sheet & Some Examples
pull/162/head
Igor Chubin 3 years ago committed by GitHub
commit 37d55ddf0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,31 @@
# 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}

@ -0,0 +1,28 @@
# sort
# Sort lines of text files
# Return the contents of the British English dictionary, in reverse order.
sort -r /usr/share/dict/british-english
# Since sort(1) can filter out duplicate adjacent lines or fields, this example
# therefore makes uniq(1) redundant. You should only ever use uniq(1) if you
# need its functionality, or need uniqueness without sorting.
#
# By default, sort(1) sorts lines or fields using the ASCI table. Here, we're
# essentially getting alphanumeric sorting, where case is handled separately; -
# this results in these words being adjacent to one another, thus duplicates
# are removed.
#
# If you need better uniq-ing, you could refer to AWK & its associative arrays.
printf '%s\n' this is a list of of random words with duplicate words | sort -u
# Sort numerically. If you don't provide the `-n` flag, sort(1) will instead
# sort by the ASCI table, as mentioned above, meaning it'll display as 1, 10, -
# 11, 2, 3, 4, etc.
printf '%d\n' {1..9} 10 11 | sort -n
# You can even sort human-readable sizes. In this example, the 2nd column is
# being sorted, thanks to the use of the `-k` flag, and the sorting is
# reversed, so that the top-most storage space hungry filesystems are displayed
# from df(1).
df -ht ext4 /dev/sd[a-z][1-9]* | sed '1d' | sort -rhk 2
Loading…
Cancel
Save