Sorting
pls offers the ability to sort the output in your preferred order by
choosing as many as you prefer from 18 bases × 2 directions per base.
Arguments
--sort/-s can be used to select the sort bases. The flag can be specified
multiple times to sort by multiple bases. Each time it can take one of these
values. All values except none can optionally suffixed with an underscore _
to reverse their direction.
| Name | Description |
|---|---|
| dev | device ID |
| ino | inode number |
| nlink | number of hard links |
| typ | node type |
| cat | node category (directory or file) |
| user | user name |
| uid | user ID |
| group | group name |
| gid | group ID |
| size | storage space |
| blocks | number of blocks |
| btime | created at; "b" for birth |
| ctime | changed at; originally meant "created at" |
| mtime | modified at |
| atime | accessed at |
| name | node name |
| cname | canonical name (name in lower case with leading symbols stripped) |
| ext | file extension |
| none | shorthand: no sorting |
By default, pls sorts file by cat and cname, which means
- directories are listed before files (
cat) - nodes are sorted by their canonical names (
cname)
When sorting by multiple sort bases, the first listed basis is the primary sort basis, the second is the tie-breaker for the first, the third is the tie-breaker for the second and so on.
Mechanism
When parsing the --sort/-s flag, values are read from the CLI, in order, and
added to a vector of sort bases till we encounter the shorthand value none,
which clears the vector.
For example, consider the pls invocation below.
pls --sort=cat --sort=cname --sort=none --sort=mtime_catis added to the list.cnameis added to the list.- All entries so far are dropped when
noneis encountered. mtime_is added to the list.
Examples
pls # or --sort=cat --sort=cname or -s=cat -s=cname dir_a/ dir_c/ dir_e/ file_b.txt file_d.txt file_f.txtpls --det=ino --det=typ --det=size --sort=cat_ --sort=size_ --sort=ino inode T Size Name798285 f 1.0 MiB file_d.txt791863 f 1.0 KiB file_b.txt798326 f 14.0 B file_f.txt791822 d dir_a/798284 d dir_c/798325 d dir_e/Here the --sort/-s arguments have this effect:
cat_sorts directories before files.size_sorts nodes by size in descending order.inosorts nodes by inode number in ascending order.