I want to cut the column which include the size of files . I use ls -l
to view info about files in current localization . I save info about file in txt file ls -l > info.txt
, and now I want to cut the column including size . I do cat info.txt | cut -d'' -f6
but i don’t work . What I do wrong ?
This include info.txt :
-rwx------ 1 s10891 Domain Users 2188 May 4 14:51 info.txt -rwx------ 1 s10891 Domain Users 1640 Mar 10 07:43 code.txt -rwx------ 1 s10891 Domain Users 68 Mar 4 11:59 sorted.txt drwx------ 1 s10891 Domain Users 0 Jan 11 09:48 PPJ drwx------ 1 s10891 Domain Users 0 Sep 7 2012 public_html drwx------ 1 s10891 Domain Users 0 Apr 15 11:16 RBD drwx------ 1 s10891 Domain Users 0 Jan 7 09:45 RDB drwx------ 1 s10891 Domain Users 0 Apr 15 12:00 SOP drwx------ 1 s10891 Domain Users 0 Apr 8 12:53 sop_ex3 -rwx------ 1 s10891 Domain Users 122 Feb 25 11:48 sop_info.txt drwx------ 1 s10891 Domain Users 0 Jan 14 09:41 WindowsFormsApplicati drwx------ 1 s10891 Domain Users 0 Jan 14 09:41 WindowsFormsApplicati drwx------ 1 s10891 Domain Users 0 Jan 14 09:41 WindowsFormsApplicati
and I want to get this :
2188 1640 68 0 0 0 0 0 0 122 0 0 0
Advertisement
Answer
most cut
s count literal characters, so for -f 6
to work, your data has to be exactly in the same columns. Not sure if your 3rd to last line is a typo or an exact reproduction of your output, but it illustrates the problem with cut perfectly.
For this case, most people will use an awk
solution:
ls -l | awk '{print $6}'
Will produce the output you have listed
The beauty of awk is that field 6 is determined by the value of awk FS variable (field separator), which defaults to “multiple white space values” (space or tab) (this is not an exact description, but is close enough for your needs).