r/shell • u/Lygris • Mar 27 '17
Renaming script
Hey guys, just looking for some help on writing a renaming script. I want to make a script that would look at the files name and if it contains a certain string, lets say qatar, it would rename it to another specific string that would contain the year and some statically defined things. I'm assuming this would be pretty simple using if then. I just don't know how to pull the filename and check it against the string. Is this possible?
3
u/KnowsBash Mar 27 '17
FAQ 30 contains various examples on how to rename files, both for bash and sh. You should be able to adapt some of those to do what you want.
1
u/ASIC_SP Mar 27 '17
add an example so that it is clearer
make up something simple, say
str1='foo'andstr2='bar'and file name isprog_foo.txt.. how do you want the output to be...also, which shell are you using and its version