Mass Renaming Files: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
(4 intermediate revisions by 4 users not shown) | |||
Line 8: | Line 8: | ||
In this scenario, we are going to try and rename all .php files in the current directory so they have a .gif extension | In this scenario, we are going to try and rename all .php files in the current directory so they have a .gif extension | ||
'''WARNING:''' always backup your files | |||
=== Using mmv === | === Using mmv === | ||
mmv '*.php' '#1.gif' | mmv '*.php' '#1.gif' | ||
=== Using rename === | === Using rename === | ||
rename 's/\.php$/.gif/' *.php | rename 's/\.php$/.gif/' *.php | ||
=== In the Bash shell === | === In the Bash shell === | ||
for file in *.php; do mv "$file" "${file%.php}.gif"; done | |||
=== Slightly more complex shell version === | |||
This has the benefit of using a full regular expression in the sed part so you can do much more complex renames, it is also generally more widely available as rename is not available in as many places as ls, awk, sed and sh. | |||
ls *.php | awk '{print("mv "$1" "$1)}' | sed 's/php$/gif/2' | /bin/sh | |||
[[Category:HowTo]] |
Latest revision as of 10:52, 29 November 2007
Mass Renaming Files
Introduction
Mass renaming of files can vary depending on what platform and system you're on. If you're on Unix, and more specifically Unix, the following techniques should be available to you.
If you're using RedBrick then both mmv and rename are available to you.
In this scenario, we are going to try and rename all .php files in the current directory so they have a .gif extension
WARNING: always backup your files
Using mmv
mmv '*.php' '#1.gif'
Using rename
rename 's/\.php$/.gif/' *.php
In the Bash shell
for file in *.php; do mv "$file" "${file%.php}.gif"; done
Slightly more complex shell version
This has the benefit of using a full regular expression in the sed part so you can do much more complex renames, it is also generally more widely available as rename is not available in as many places as ls, awk, sed and sh.
ls *.php | awk '{print("mv "$1" "$1)}' | sed 's/php$/gif/2' | /bin/sh