Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

df -k query 4

Status
Not open for further replies.

dickiebird

Programmer
Feb 14, 2002
758
GB
Hi Guys
I run a check on jfs sizes (free space), using "df -k|cut -c30-35" eg:

df -k
Filesystem 1024-blocks Free %Used Iused %Iused Mounted on
/dev/hd4 24576 10136 59% 1987 17% /
/dev/hd2 811008 200484 76% 16999 9% /usr
/dev/hd9var 65536 24296 63% 854 6% /var
/dev/hd3 32768 18952 43% 222 3% /tmp

But I would prefer to use -f, the field option.

df -k|cut -f3 -d&quot;???&quot; <- What do I use here,

when there's a varying numbers of spaces between f2 and f3
- or should I just continue with current -c option?
Your input would be appreciated.
TIA
;-) Dickie Bird
db@dickiebird.freeserve.co.uk
 
Hi Dickie Bird,

is there any particular reason (just interest?) why you want to use cut and not awk (which would be simple) for that query?

Maybe there is some sophisticated cut solution...

mrjazz
 
No reason at all - it just hadn't occurred to me !
(it's /tmp I want to monitor)
df -k|grep tmp|awk '{print $3}'
Perfect !
TAL Mr J.
;-) Dickie Bird
db@dickiebird.freeserve.co.uk
 
Just to answer the original query for info. you could use tr to translate all multiple spaces to one space as follows:

df -k |tr -s ' ' ' ' | cut -f3 -d ' '

Might be useful for future reference. Cheers.
 
df -k|awk '/tmp/ {print $3}'

OR

df -k|awk '$NF ~ /tmp/ {print $3}'
vlad
+---------------------------+
|#include<disclaimer.h> |
+---------------------------+
 
i refuse to post my 'sed' version! vox clamantis in deserto.
 
I wish you'd refused to post your 'refusal' and posted the 'sed' solution instead! [tongue] vlad
+---------------------------+
|#include<disclaimer.h> |
+---------------------------+
 

if you insist....be all warned,
this assume understanding of regexp && is [not]really easy.
easy things are not interessant :)
it's an usefull exercise for most of unix-tools based on it, (ef)?grep, sed, vi, awk ...

nota1: does not work on csh (my preferred shell) cmd-line, because of the syntax
nota2: works on /bin/sh-cmd line
nota3: i don't use ksh && other exotics
nota4: allways works if the commands are in a script: df -k|sed -f script
nota5: after [{}] is a \n character.

/bin/df -k|/bin/sed -ne '/\tmp$/{
s/\([^ ]\) [ ]*\([^ ]\) [ ]*\([^ ]\).*/\3/p
}

in this case (i mean this thread)
i personnaly prefer ken's version for his general pourpose
just a remarque:
/bin/df -k <file(sys)> |tr -s ' ' ' ' | cut -f3 -d ' '

vlad's job will give wrong output if you have:
/qqqqqtmpwwww
/tmp
/tmp.qqqqq
and so on mounten on your fs

to work properly replace 'tmp' by '\/tmp$'
but i agree with him, IF you use AWK, let him DO the job
please NEVER use: df|grep|awk

awk is a fenomenal tool, if he HAS something to do, other tools cannot!!!
in this case, he make nothing but pattern-matching
really a little too stupid for mr. awk :(

an other situation is,if you have to compute the free space on your hd
now is the use of mr. awk really appropriate (i prefer it to perl or c)
df -k|awk '{print a+=$4;}'

vox clamantis in deserto.
 
you could always 'df -k /tmp/.' to limit it to the correct file system.
if you're on solaris (don't know about others), you could 'df -b /tmp/.' to give you a much smaller list to pick from.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top