Fork me on GitHub

BASH: rename files

A simple rename example using again the mighty awk and xargs
ls -l *.xml | awk '{print $9}' | xargs -t -i mv {} {}.old

Explanation:
ls -l *.xml -> easy! list the xml files in a folder
awk '{print $9}' -> output just the name of the file
xargs -t -i mv {} {}.old -> rename it adding at the same filename the extension “.old”

I know, I know … my explanation is crap: blame my laziness :)


Responses


  1. for i in *.htm; do mv $i `basename $i .htm` .html; done

    or …

    mmv -v “*.htm” “*#1.html”


    Comment by voku — November 1, 2010 @ 3:19 pm



Leave a comment

(required)

(required)