In the , I introduced you to several different ways of sorting ls' output, based on file time. There was one constant: ls listings were always from first (most recent) to last, moving (first) down each column and then across the page.
That's often not the most convenient way to look at the world. For example, if you're going to look at a directory with many, many files, it might be easier to list the files across the screen first, and then down. This would be particularly nice if you're using a pager (like pg or) to read the listing. Then the first screenful will show the files at the top of the list. Here's an example:
jerry@ora ~/.bin 59 %
ls -x | pgREADME alifile append c-w cgrep crontab cw cx dirtop distprompter drmm echoerr fixsubj fols incc incs maillog mhadd mhprofile pickthis recomp reheader replf rfl rhno rhyes rmmer rn2mh rtfm saveart scandrafts showmult showpr tcx tofrom unshar weather which xmhprint zfolders zloop zrefile zscan
This listing is "alphabetic"-not sorted by time. So README is first in the list (uppercase comes below lowercase), and alifile is next to it. The -x flag makes the output multi-column. BSD doesn't have -x. To get the same sorting order under BSD, pipe ls output through the script.
Both BSD and System V have the -C option; it sorts filenames down columns instead of across. In fact, -C is the default on BSD when you aren't redirecting the output of ls. If BSD ls detects that it's writing anywhere other than a terminal, it defaults to single-column output, rather than multi-column. Under BSD, you'll need to use -C (or another technique like the cols script or ) to get output in columns when you pipe ls output.
The -r option lists the files in reverse order. I find this particularly useful when I'm looking at modification times. Because -t shows files by modification time, newest first - using -tr shows files by modification time, oldest first:
jerry@ora ~/.bin 61 %
ls -trechoerr replf zscan c-w dirtop saveart xmhprint zrefile cx cgrep rtfm distprompter reheader maillog pickthis README fixsubj drmm rfl rhyes append mhadd incc showpr rhno fols rmmer tofrom zloop crontab mhprofile rn2mh scandrafts unshar weather recomp alifile showmult tcx incs zfolders cw which
jerry@ora ~/.bin 63 %
ls -turREADME maillog which mhadd tofrom alifile replf zfolders crontab tcx append reheader zloop recomp showmult cgrep rhyes xmhprint distprompter mhprofile dirtop rhno zscan cw rmmer fixsubj showpr zrefile cx rfl echoerr scandrafts drmm c-w rtfm fols saveart incc weather incs unshar pickthis rn2mh