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.

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.

NameDescription
devdevice ID
inoinode number
nlinknumber of hard links
typnode type
catnode category (directory or file)
useruser name
uiduser ID
groupgroup name
gidgroup ID
sizestorage space
blocksnumber of blocks
btimecreated at; "b" for birth
ctimechanged at; originally meant "created at"
mtimemodified at
atimeaccessed at
namenode name
cnamecanonical name (name in lower case with leading symbols stripped)
extfile extension
noneshorthand: 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.

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.

Examples

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 555665 f 1.0 MiB  file_d.txt 555640 f 1.0 KiB  file_b.txt 555692 f 14.0 B  file_f.txt 555639 d dir_a/ 555664 d dir_c/ 555691 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.