Skip to content

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.

--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 be 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.

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.

Terminal window
pls --sort=cat --sort=cname --sort=none --sort=mtime_
  • 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.
Terminal window
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.txt
Terminal window
pls --det=ino --det=typ --det=size --sort=cat_ --sort=size_ --sort=ino
inode T Size Name
8429588 f 1.0 MiB  file_d.txt
8427180 f 1.0 KiB  file_b.txt
8430237 f 14.0 B  file_f.txt
8427179 d dir_a/
8429584 d dir_c/
8429597 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.