BenJacob
BenJacob

Reputation: 987

Sorting ls output by file size

I am currently sorting the output of ls -l by byte count using:

ls -l | sort -r -k5,5 -n

What if I wanted to make this work with the -@ flag? Currently this will output:

-rwxr-xr-x@ 1 name  staff  7106  2 May 10:43 c
-rwxr-xr-x  1 name  staff   675 22 Apr 17:57 a
-rwxr-xr-x  1 name  staff   486 23 Apr 07:56 b
drwxr-xr-x  4 name  staff   136 25 Apr 18:38 d
-rwxr-xr-x  1 name  staff   120 23 Apr 07:59 e
-rwxr-xr-x  1 name  staff   112 22 Apr 18:45 g
-rwxr-xr-x  1 name  staff    51 22 Apr 18:45 f
total 56
    com.apple.metadata:_kMDItemUserTags   42

Where I want it to take the extended attribute keys line and keep it below the appropriate file like so:

-rwxr-xr-x@ 1 name  staff  7106  2 May 10:43 c
    com.apple.metadata:_kMDItemUserTags   42
-rwxr-xr-x  1 name  staff   675 22 Apr 17:57 a
-rwxr-xr-x  1 name  staff   486 23 Apr 07:56 b
drwxr-xr-x  4 name  staff   136 25 Apr 18:38 d
-rwxr-xr-x  1 name  staff   120 23 Apr 07:59 e
-rwxr-xr-x  1 name  staff   112 22 Apr 18:45 g
-rwxr-xr-x  1 name  staff    51 22 Apr 18:45 f
total 56

Upvotes: 2

Views: 748

Answers (1)

user2141130
user2141130

Reputation: 1004

No need to use sort, just use the -S option with ls

ls -Sl

(that's an upper case S)

Upvotes: 4

Related Questions