rename many files
Change the ending of many files, replace spaces in names, or number them.
Steps
-
for f in *.txt; do mv -- "$f" "${f%.txt}.md"; doneevery .txt to .md
-
rename 's/\.txt$/.md/' *.txtthe same with rename (the perl one; package rename)
-
for f in *\ *; do mv -- "$f" "${f// /_}"; donespaces in names to underscores
-
rename -n 's/ /_/g' *show what rename would do, without doing it
Notes
- There are two rename programs: the perl one takes s/old/new/, util-linux's takes old new files.
Commands used
mvrename
Each has a page in lore: lore mv opens it.
Related recipes
- add to the end of a fileAdd lines to a file without replacing it, also to a file only root can write.
- argument list too long"Argument list too long" from rm, cp or mv: too many files for one command line. Hand them over in batches.
- get a file's name, folder and extensionTake a path apart in a script: the folder, the name, the name without its extension, the extension.
- add a folder to the pathLet the shell find programs in a folder, for good, and reload the settings without logging out.