Cutting the column including size
Solution 1
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).
Solution 2
You don't need to parse ls
: stat -c %s *
will give you a column of sizes. If you want the filename too: stat -c "%s %n" *
user2344333
Updated on June 28, 2022Comments
-
user2344333 almost 2 years
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 filels -l > info.txt
, and now I want to cut the column including size . I docat 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
-
gNU.be about 11 yearsCut will still work just fine. You can make an output like that look nice and neat if you pipe the column command. "ls -l | column -t" It's very handy for the df and mount commands.
-
shellter about 11 yearsSounds good and thanks for sharing! (but ... )
-ksh: column: not found [No such file or directory]
. good luck to all.