LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 08-30-2007, 07:59 AM   #1
adam_blackice
Member
 
Registered: Apr 2006
Location: /*Egypt */ //cairo
Distribution: Ubuntu 7.04 , SLED 10 , Fedora , RHEL 5
Posts: 312

Rep: Reputation: 32
simple awk script question


hello all

while i was reading in the bash beginners guide in the awk section i found this script that prints the critical partitions

Code:
 df -h | sort -rnk 5 | head -3 | \awk '{ print "Partition " $6 "\t: " $5 " full!" }'
and i want to understand what is the use of "sort -rnk 5" ,, head -3 ? and i will be thankful


thanks
 
Old 08-30-2007, 08:06 AM   #2
nx5000
Senior Member
 
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 52
sort -rnk 5
is equivalent to sort -r -n -k 5
* -k 5 means sort by the 5th field (column)

* -n means numerical sort . Take 4,74,8,99
A non numerical will sort like this: 4 74 8 99
A numerical one will sort like this: 4 8 74 99

* -r means reverse
A numerical reversed : 99 74 8 4

head -3
will print the first three line of the input

In this case, it will print the 3 biggest values: 99 74 8
 
Old 08-30-2007, 08:13 AM   #3
adam_blackice
Member
 
Registered: Apr 2006
Location: /*Egypt */ //cairo
Distribution: Ubuntu 7.04 , SLED 10 , Fedora , RHEL 5
Posts: 312

Original Poster
Rep: Reputation: 32
thanks for you help

and i want to know what is the use of "\" backward slash and "/" forward slash inside the awk command ? .
 
Old 08-30-2007, 08:17 AM   #4
Calvera
LQ Newbie
 
Registered: Aug 2007
Location: Glasgow, Scotland
Distribution: Ubuntu
Posts: 1

Rep: Reputation: 0
Quote:
Originally Posted by adam_blackice View Post
thanks for you help

and i want to know what is the use of "\" backward slash and "/" forward slash inside the awk command ? .
The '\t' is giving you a tab character. Can't see a '/' in the awk command?!

D.
 
Old 08-30-2007, 08:24 AM   #5
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
The \ at the start of the awk command makes the shell ignore any aliases set on the awk command, and forces it to use the version of awk found in the PATH variable. This way, when writing shell scripts, you can be sure that the command you indend to run is that which is executed. This is often used in conjunction with rm to make sure files get deleted:
Code:
\rm -f files
 
Old 08-30-2007, 08:30 AM   #6
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
I would highly recommend downloading the coreutils manual from the GNU website. The coreutils package contains many of the most common programs and their options.

http://www.gnu.org/software/coreutil.../coreutils.pdf
 
Old 08-30-2007, 09:07 AM   #7
adam_blackice
Member
 
Registered: Apr 2006
Location: /*Egypt */ //cairo
Distribution: Ubuntu 7.04 , SLED 10 , Fedora , RHEL 5
Posts: 312

Original Poster
Rep: Reputation: 32
many thanks for all\\

the df command just print the partitions like 1.)mounted patitions and 2.) the / partitions

if i want to make the script reads the whole file system like /etc /var /opt .....

any ideas

and thanks again

Last edited by adam_blackice; 08-30-2007 at 09:38 AM.
 
Old 08-30-2007, 09:47 AM   #8
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
Quote:
Originally Posted by adam_blackice View Post
if i want to make the script reads the whole file system like /etc /var /opt .....

any ideas
Look into replacing the df command with the du command; it will do what you're looking for...
 
Old 09-03-2007, 07:24 AM   #9
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
This will show you percentage of use of each mounted filesystem.

Code:
mount | grep '^/dev/' | cut -d' ' -f1 | xargs df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/hda5             64665412  41686320  19694204  68% /
/dev/sdb2            837569504 264709116 530314248  34% /media/lbigdisk
/dev/hda1             30408696  30185872    222824 100% /mnt/windows
/dev/sdb1            122887832   1947900 120939932   2% /media/My Book
/dev/sda1            244992000 202144672  42847328  83% /media/NetDisk
 
Old 09-03-2007, 02:23 PM   #10
adam_blackice
Member
 
Registered: Apr 2006
Location: /*Egypt */ //cairo
Distribution: Ubuntu 7.04 , SLED 10 , Fedora , RHEL 5
Posts: 312

Original Poster
Rep: Reputation: 32
Thanks Guru
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
simple awk question getline coldy78 Programming 3 04-20-2007 11:39 PM
simple awk question mr_scary Linux - General 3 02-23-2007 06:37 PM
Simple question about sed or awk setianusa Programming 2 09-16-2005 03:57 PM
Simple bash/awk/sed scripting question R00ts Programming 4 04-16-2005 02:55 AM
Bash script question (grep and awk) hamish Linux - Software 6 04-06-2005 03:14 PM


All times are GMT -5. The time now is 01:44 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration