User Tools

Site Tools


bash:files:rename_files_which_contain_the_old_sub-string_replacing_it_with_the_replacement_sub-string

BASH - Files - Rename files which contain the old sub-string, replacing it with the replacement sub-string

Rename all files which contain the old sub-string, replacing it with the replacement sub-string.

rename old_value replacement_value directory/filename

Rename all files which contain the sub-string 'foo', replacing it with 'bar'

for i in ./*foo*;do mv -- "$i" "${i//foo/bar}";done

Using perl

rename 's/ /-/g' *

As long as you have perl based rename.

You can check:

rename --help

or

rename [-v] [-n] [-f] perlexpr [filenames] 
bash/files/rename_files_which_contain_the_old_sub-string_replacing_it_with_the_replacement_sub-string.txt · Last modified: 2022/06/13 12:50 by peter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki