Skip to content

Instantly share code, notes, and snippets.

@MaskeZen
Created August 8, 2019 15:09
Show Gist options
  • Save MaskeZen/2aff0eb69a71164af67d055d668e4d69 to your computer and use it in GitHub Desktop.
Save MaskeZen/2aff0eb69a71164af67d055d668e4d69 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