Menu

11 October 2007

How to change extention of multilple files at once in shell

keywords : files, shell , backup extension

1 Add a extension (for example .old ) to selected files
=========================================
======= content of file ./backup ======

#!/bin/bash
for FILE in *.$1 ;do cp $FILE $FILE.old; done
exit 0
--------- end of file ---------------------
usage
./backup html

------------------
result : all .html files are now .html.old
=================

2 . Remove the extension to selected files

======== content of file ./unbackup =====
#!/bin/bash
for FILE in *.old ; do cp $FILE `basename $FILE .old`; done
exit 0
------------------------------
usage
./unbackup
all .html.old files are now copied to .html
------------------

3 . Remove all backup files

rm *.old
Post a Comment