Slavik
Slavik

Reputation: 84

How to sort files by size on C shell

How can I get an array of filenames of all files in specified directory sorted by size of file. For example if I have files with next sizes:

file1 58
file2 32
file3 178

I want to get something like this:

set arr = (file2 file1 file3)

Upvotes: 1

Views: 366

Answers (1)

anubhava
anubhava

Reputation: 785128

Assuming you can store output as shown in question in a file sort and cut can work:

sort -nk2,2 file | cut -d ' ' -f1
file2
file1
file3

and using set directly:

set arr = (sort -nk2 * | cut -d ' ' -f1) 

Upvotes: 1

Related Questions