Advantages of sls over ls:
The option strings supplied with the -s and -p options determine the sort order and output format of the listing. The option string is a single argument consisting of two types of objects: plain characters, which are simply copied to the output stream, and conversion specifications, each of which causes a particular member (or field) of the stat(2) structure to be sorted or printed. (The correspondence is not quite one-to-one, but it's close.) Plain characters and field widths in the sort option string are ignored.
Each conversion specification is introduced by the character % (unless two appear together, in which case a single one is output). After the %, any of the following may appear in sequence:
An optional `-' flag: for the -p option, it specifies left-adjustment for string-type fields (no effect on numeric fields); for the -s option, it means reverse the sort order on this field.
An optional decimal digit string specifying a minimum field width (-p option only). If the converted value has fewer characters than the field width, it will be padded on the left (or right, if the left-adjustment flag has been given) to the field width. If the converted value has more characters than the field width, the field width will be ignored. If the digit string has a leading ``0'', numeric-type fields will be zero-filled on the left to the width of the field.
A (required) flag character, which results in the conversion of a field from the stat structure for each file. Some flag characters may be followed by optional modifier character(s). Each flag character has a default field width and format. The flag characters and their meanings are:
The a, c, and m flag characters use a default format of Mmm dd yyyy HH:MM (``%h %d 19%y %H:%M''). This can be changed by setting the SLS_DATEFMT environment variable to a suitable date format string; by specifying the -u command line option, which requests ls-style dates; or by following the flag character with a quoted format string of the type used by date(1) (with several extensions; see below). (Note that either single or double quotes must delimit the date format string in the -p option string, so use your shell's particular syntax for embedded quotes.)
The date format string may contain plain characters, which are copied to the output, or any of the following format modifier characters (preceded by a `%'):
To produce the same output as ``ls -l'':
sls -u -p '%t%p %2l %-u %s %m %N'
To list the size (in kbytes), access and modify dates (no times), and file names (no pathname), sorted by size (largest first):
sls -s %-s -p '%sk %a"%h %d 19%y" %m"%h %d 19%y" %nb' /usr/mydir
How a shell script might get the last-modify date on a file with sls vs. ls (assume that SLS_DATEFMT="%h %d %H:%M"; remember that you have no control over the time vs. year field with ls):
FILEDATE=`ls -l file | awk '{print $5,$6,$7}'`
FILEDATE=`sls -p %m file`
What I personally am probably going to do with sls is alias lsl to
sls -a -p ' %P %t %5skk %-30N %c"%y%m%d.%T" %i 'which is a format I like, and is geared to single-user unix.
It is impossible to distinguish between two files with the same name in two different directories with the %nb output format flag.
There are several features of the ``standardized output'' nature of sls that are incompatible with ls, and may cause some initial confusion; these are mentioned below.
The default alignment for string-valued fields (right-justified) does not match ls, but is consistent with the C library function printf (which uses the ``-'' option flag to specify left-justification).
sls does not automatically eliminate the directory part of the file name in the listing when supplied with a single directory name argument; the user must explicitly request that with the %nb output format flag.
The symbolic link notation ``linkname -> name'' that ls automatically provides with -l output must also be explicitly requested by the user with the %N output format flag.
Sls has no multi-column output capability.
The default format for dates in sls displays both the time and year, resulting in wider output (see ``DATE FORMAT STRINGS'' section for information on overriding this default).
Rich Baughman rich@cfi.com OR ima!cfisun!rich 7 March 1989The cLIeNUX version may have accumulated a century field and maybe colors by the time you read this.