rename many files

Change the ending of many files, replace spaces in names, or number them.

  • files
  • shell

Steps

  1. for f in *.txt; do mv -- "$f" "${f%.txt}.md"; done

    every .txt to .md

  2. rename 's/\.txt$/.md/' *.txt

    the same with rename (the perl one; package rename)

  3. for f in *\ *; do mv -- "$f" "${f// /_}"; done

    spaces in names to underscores

  4. 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

  • mv
  • rename

Each has a page in lore: lore mv opens it.