Skip to content

Instantly share code, notes, and snippets.

@aprossi
Created May 24, 2019 06:36
Show Gist options
  • Save aprossi/8880b59c3f52a6ad5ff43b8696f24717 to your computer and use it in GitHub Desktop.
Save aprossi/8880b59c3f52a6ad5ff43b8696f24717 to your computer and use it in GitHub Desktop.
Rename multiple files with prefix or suffix in Linux console

Add a suffix

for file in *; do mv "$file" "$(basename "$file")yourSuffix"; done;

Exmpale to add an underscore "_" at the end each text file:

for file in *.txt; do mv "$file" "$(basename "$file")_"; done;

Add a prefix

for file in *.txt; do mv "$file" "yourPrefix$file"; done;

Exmpale to add an underscore "_" in front of text each file name:

for file in *.txt; do mv "$file" "_$file"; done;

Make sure you run those commands in Bash shell.

Alternative: Add suffix with find command

find . -type f -exec bash -c 'mv $0 $0yourSuffix' {} \;

Exmpale to add an underscore "_" at the end each text file:

find . -type f -exec bash -c 'mv $0 $0_' {} \;

Alternative: Add prefix with find command

find . -type f -exec bash -c 'mv $0 yourPrefix$0' {} \;

Exmpale to add an underscore "_" in front of text each file name:

find . -type f -exec bash -c 'mv $0 _$0' {} \;

This will run in any shell and you can easily define the set of files that should be renamed by using the name or iname parameter for find.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment