Skip to content

The sort Command

Sam Matzko edited this page Dec 13, 2021 · 3 revisions

The sort command provides the basis for all Sortery's advanced sorting. It takes up to three arguments: the date-format option, the date-type option, and the preserve-name flag, none of which are required.

The Preserve Name Flag (-p, --preserve-name)

This flag takes no arguments. When passed, it tells Sortery to preserve the original name of each file when sorting, by putting the original name after the date, separated by a space. So if we have a file1.txt, and the preserve-name flag is passed, instead of renaming file1.txt to 2021-12-25 15h05m58s.txt, Sortery will rename it to 2021-12-25 15h05m58s file1.txt.

The Date Format Option (--date-format)

This flag takes a string argument representing the template date format for renaming the files. The default is %Y-%m-%d %Hh%Mm%Ss; for example, 2021-12-25 15h05m58s. See the chrono docs for details on specific formatting options. Be sure to put quotes around the template format: --date-format="%Y-%m-%d %Hh%Mm%Ss".

The Date Type Option (--date-type)

This flag takes an argument, which must be one of c, m, or a, that specifies the specific date to sort the files by. The table below shows each option and how it sorts the files:

Option How it sorts
a Sort all the files by access time: the last time each file was accessed.
c Sort all the files by creation time: the time each file was created.
m Sort all the files by modification time: the time each file was last modified.

The Exclude Type Option (-e, --exclude-type)

This option takes a string argument of any file-type extensions to exclude from the sorting, each type separated by a -. For example, to exclude JPEGs and PNGs, pass --exclude-type="jpg-png" to the sort subcommand. Any files with the end extension .jpg or .png will be left alone while the sorting commences. Any extension works; it doesn't have to be an officially recognized file format. You could use --exclude-type="thisisatypethatdoesnotexsist", if you wanted.

The Only Type Option (-o, --only-type)

This option functions the same as the exclude-type option, except instead of excluding the files types, it makes them exclusive. That means that the file types passed to only-type and only those file types will be sorted. All other file types will be ignored. Note that the exclude-type and only-type options cannot be used together.

Clone this wiki locally