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.
cat
is added to the list.cname
is added to the list.- All entries so far are dropped when
none
is encountered. mtime_
is added to the list.
Examples
dir_a/ dir_c/ dir_e/ file_b.txt file_d.txt file_f.txt
inode T Size Name 557618 f 1.0 MiB file_d.txt 557593 f 1.0 KiB file_b.txt 557645 f 14.0 B file_f.txt 557592 d dir_a/ 557617 d dir_c/ 557644 d dir_e/
Here the --sort
/-s
arguments have this effect:
cat_
sorts directories before files.size_
sorts nodes by size in descending order.ino
sorts nodes by inode number in ascending order.