I wanted to do a sort of files in IBM AIX today and I came across this useful command.
ls -al | sort +4n
This command performs a numeric sort on the fifth column of the “ls -al” output. This results in a file listing where the files are listed in ascending order, from smallest in size to largest in size.
The “sort” command sorts information piped into it. There are several options that let you sort information in a variety of ways.
Other examples :
ps -ef | sort
This command pipeline sorts the output of the “ps -ef” command. Because no arguments are supplied to the sort command, the output is sorted in alphabetic order by the first column of the ps -ef output (i.e., the output is sorted alphabetically by username).
ls -al | sort +4n
This command performs a numeric sort on the fifth column of the “ls -al” output. This results in a file listing where the files are listed in ascending order, from smallest in size to largest in size.
ls -al | sort +4n | more
The same command as the previous, except the output is piped into the more command. This is useful when the output will not all fit on one screen.
ls -al | sort +4nr
This command reverses the order of the numeric sort, so files are listed in descending order of size, with the largest file listed first, and the smallest file listed last.


