What each piece of this command does: du /home | sort -nr +0 -1 | head -10
I have the command:
du /home | sort -nr +0 -1 | head -10
and need to know what each piece ("du", "/home", "|", "sort", "-nr", "+0", "-1", "head", and "10") does.
du /home
du - Disk Usage
Command gives result of disk usage for /home
directory in KB
|
known as pipe; for feeding the output data to next command (sort)
sort -nr +0 -1
OPTION MEANING:
interpreting sorting keys alphabetically or numerically (-n option)
in ascending or descending order (-r -- sort in reverse option)
-n (numeric keys sorting)
+n (sorting using n-th field, counting from zero)
sort - sorting the result (see man pages for sort to find what those option does)
head -10
Finally it results the top 10 records
du /home
gives a list of the "Disk Usage" (thus the name of the command) of every directory in /home and, recursively, all sub-directories. One line output per directory. "|" sends the output to the next command.
sort
Sorts the result, with "-n" specifying numeric (as opposed to lexicographic) sort, "r" specifies reverse order so the largest value appears first). "-nr" is equivalent to "-n -r"
head -10
Outputs only the first 10 lines of the previous command.
In essence it's finding the 10 largest directories in /home.
du /home shows disk usage for every directory on the /home area of your disk.
sort -nr +0 -1 performs a reverse numeric sort on its input (which comes from the du command).
head -10 shows the first 10 lines of its input (which comes from the sort command).
man xxx shows you the manual for command xxx. For example, man du
, man sort
, and man head
.
精彩评论