O'Reilly logo

Linux and Unix Shell Programming by David Tansley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

11.2. sort on the system

Sort can be used to sort the usernames from the /etc/passwd file. All we need to do is sort on field 1, which is the login name field, then pass the output using a pipe to awk, and let awk print the first field.

						$ cat passwd | sort -t: +0 | awk -F":" '{print $1}' 
adm 
bin 
daemon 
... 
...
					

Sort can also be used on the df command to print the usage column in desending order. Here’s a normal df output.

						$df 
Filesystem  1024-blocks Used   Available Capacity Mounted on 
/dev/hda5   495714      291027 179086    62%      / 
/dev/hda1   614672      558896 55776     91%      /dos
					

Now using -b option, which ignores any leading blanks when sorting, we use field 4 (+4), which is the ‘capacity’ column. Reversing the sort gives a clearer picture of the free space on ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required