Mass Renaming Files: Difference between revisions

Jump to navigation Jump to search
no edit summary
mNo edit summary
No edit summary
 
(3 intermediate revisions by 3 users not shown)
Line 24: Line 24:
=== In the Bash shell ===
=== In the Bash shell ===


  OLDIFS=$IFS; IFS="\n"; for file in *.php; do newfile=`echo $file | sed -e 's/\.php$/\.gif/'`; mv $file $newfile; done; IFS=$OLDIFS
  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]]
7

edits

Navigation menu