I want to remove the timestamp from all the files in a directory
Let’s say I have below files
ABC.xml_202401012300
XYZ.xml_202401022300
I want to remove all after xml_
This means I’m expecting
ABC.xml
XYZ.xml
I tried bellow code but did not work :
rename 's/xml_.*$/.xml/' *
>Solution :
In general you can use mv to rename a file in Linux shell. If you want to rename mutliple xml files, you can do it the following way:
for f in *.xml_*; do mv "$f" "${f%_*}"; done
Here %_* is a pattern remover which says remove everything after the underscore symbol.