Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Remove everything after `xml_` in all filenames in directory

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_

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading