Cmik
December 8, 2010, 7:35pm
1
not sure if i'm doing this right i'm new tho this but i'm trying to use a space as a delimiter with the cut command
my code is
size=$( du -k -S -s /home/cmik | cut -d' ' -f1 )
i've also tried -f2 and switching the -d and -f around if that does anything
I see that above command prints the whole record (size and directory name). Not sure why it's not able to print only the size.
But following should work.
size=$( echo $(du -k -S -s /home/cmik) | cut -d' ' -f1 )
OR
size=$( du -k -S -s /home/cmik | cut -f1 )
OR
size=$( du -k -S -s /home/cmik | awk '{print $1}' )
OR
size=$( du -k -S -s /home/cmik | awk -F " " '{print $1}' )
I think du uses a TAB character between the size and the name so no -d needed on cut
size=$( du -k -S -s /home/cmik | cut -f1 )