I have few files like file.docs, file.md, file.txt, file.xmls and I want to rename it as report.md, report.md, report.txt and so on... So how should I do this through shell script?
CodePudding user response:
Using rename:
rename file report file.*
This would also rename eg. file.test.md to report.test.md, which may or may not be desired behaviour.
If your rename implementation supports regex, you can use an expression which avoids this. In bash you can do shopt -s extglob; rename file report file. ([^.]) to preclude report.test.md from being passed to rename.
CodePudding user response:
Traditional way to solve this without any non-standard apps:
for file in *.txt
do
mv $file `basename $file .txt`.md
done
