rename many files
Change the ending of many files, replace spaces in names, or number them.
filesshell
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.
add to the end of a file
Add 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 extension
Take a path apart in a script: the folder, the name, the name without its extension, the extension.
add a folder to the path
Let the shell find programs in a folder, for good, and reload the settings without logging out.