16.3 Reordering ls ListingsIn the previous tutorial ( 16.2 ) , 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 more ( 25.3 ) ) 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 % 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 cols ( 35.16 ) 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 pr -number ( 35.17 ) ) 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 % Adding the -u option shows the least recently accessed files first:
jerry@ora ~/.bin 63 % - , |
|