Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sorting ls-l owners in Unix

Tags:

unix

I want to sort the owners in alphabetical order from a call to ls -l and cannot figure out a way to do it. I know something like ls-l | sort would sort the file name but how do i sort the owners in order?

like image 744
brian Avatar asked Nov 10 '10 04:11

brian


1 Answers

The owner is the third field, so use -k 3:

ls -l | sort -k 3

You can extend this idea to sorting based on other fields, and you can have multiple -k options. For instance, maybe you want to sort by owner, and then size in descending order:

ls -l | sort -k 3,3 -k 5rn
like image 153
John Kugelman Avatar answered Oct 26 '22 06:10

John Kugelman