slugify [-acdhintuv] <source_file> ...
Slugify converts filenames and directories to a web friendly format.
Before running any destructive commands, consider a dry run -n before hand.
For additional details, please see the repository: https://github.com/benlinton/slugify
Options include:
-
-a: Remove spaces immediately adjacent to dashes. -
-c: Consolidate consecutive spaces into single space. -
-d: Replace spaces with dashes (instead of default underscores). -
-h: Display help. -
-i: Ignore case. -
-n: Dry run. -
-t: Treat existing dashes as spaces. -
-u: Treat existing underscores as spaces (useful with-a,-c, or-d). -
-v: Verbose mode.
Note, most examples below are run in verbose mode (-v) to help illustrate the
results. Verbose mode is unnecessary in real world scenarios.
Provide escaped filenames:
$ slugify -v My\ \ file.txt
rename: My file.txt -> my__file.txtAlternatively provide unescaped filenames inside quotes:
$ slugify -v "My file.txt"
rename: My file.txt -> my__file.txtGlobs (like * and ?) work as well:
$ slugify -v *.txt
rename: My file.txt -> my_file.txt
ignore: my_web_friendly_filename.txtProvide an unlimited number of arguments:
$ slugify -v "My first file.txt" "My second file.txt"
rename: My first file.txt -> my_first_file.txt
rename: My second file.txt -> my_second_file.txtDirectories are also supported:
$ slugify -v "My Directory"
rename: My Directory -> my_directoryConsolidate consecutive spaces into single spaces:
$ slugify -vc "My consolidated file.txt"
rename: My consolidated file.txt -> my_consolidated_file.txtReplace spaces with dashes:
$ slugify -vd "My dashed file.txt"
rename: My dashed file.txt -> my-dashed-file.txtThe -d option replaces each space with a dash.
$ slugify -vd "My dashed file.txt"
rename: My dashed file.txt -> my--dashed--file.txtCombine -d with -c (consolidate spaces) for a single dash between each word.
$ slugify -vdc "My dashed file.txt"
rename: My dashed file.txt -> my-dashed-file.txtIgnore case:
$ slugify -vi "UPPER CASE FILE.txt"
rename: UPPER CASE FILE.txt -> UPPER_CASE_FILE.txtPlay it safe with a dry run:
Dry run mode does not alter the filesystem in any way.
$ slugify -n *
--- Begin dry run mode.
rename: My file.txt -> my_file.txt
ignore: web_friendly_filename.txt
--- End dry run mode.Dry run mode also allows you to test filenames that don't exist. Great for testing!
$ slugify -n "Ghost File.txt"
--- Begin dry run mode.
not found: Ghost File.txt
rename: Ghost File.txt -> ghost_file.txt
--- End dry run mode.Dry run mode automatically enables verbose mode so there is no need to include
the -v option with -n.
Handle spaces adjacent to dashes:
In this example, without -a the dashes end up surrounded by underscores.
$ slugify -v "The Beatles - Yellow Submarine.mp3"
rename: The Beatles - Yellow Submarine.mp3 -> the_beatles_-_yellow_submarine.mp3But with -a the adjacent spaces are removed.
$ slugify -va "The Beatles - Yellow Submarine.mp3"
rename: The Beatles - Yellow Submarine.mp3 -> the_beatles-yellow_submarine.mp3The -a only removes spaces immediately adjacent to a dash, which may not be
the desired effect (below three spaces on either side of the dash get converted
into two underscores because of -a).
$ slugify -va "The Beatles - Yellow Submarine.mp3"
rename: The Beatles - Yellow Submarine.mp3 -> the_beatles__-__yellow_submarine.mp3But -c consolidates spaces into a single space and then -a will remove the
left over adjacent single spaces.
$ slugify -vac "The Beatles - Yellow Submarine.mp3"
rename: The Beatles - Yellow Submarine.mp3 -> the_beatles-yellow_submarine.mp3Convert existing underscores into dashes
The -u treats underscores as spaces and -d converts spaces into dashes.
$ slugify -vud "Spaces Dashes-And_Underscores.txt"
rename: Spaces Dashes-And_Underscores.txt -> spaces-dashes-and-underscores.txtConvert existing dashes into underscores
$ slugify -vt "Spaces Dashes-And_Underscores.txt"
rename: Spaces Dashes-And_Underscores.txt -> spaces_dashes_and_underscores.txthttps://github.com/benlinton/slugify/issues
Slugify is Copyright (C) 2012 Ben Linton https://github.com/benlinton/slugify
man(1), manpages(5)