Difference between revisions of "Mass Renaming Files"

From Redbrick Wiki
Jump to navigation Jump to search
 
Line 1: Line 1:
== Mass Renaming Files
+
== Mass Renaming Files ==
  
=== Introduction
+
=== 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.
 
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.
Line 9: Line 9:
 
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
  
=== 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 ===
  
 
  OLDIFS=$IFS; IFS="\n"; for file in *.php; do newfile=`echo $file | sed -e 's/\.php$/\.gif/'`; mv $file $newfile; done; IFS=$OLDIFS
 
  OLDIFS=$IFS; IFS="\n"; for file in *.php; do newfile=`echo $file | sed -e 's/\.php$/\.gif/'`; mv $file $newfile; done; IFS=$OLDIFS

Revision as of 09:20, 8 February 2006

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

Using mmv

mmv '*.php' '#1.gif'

Using rename

rename 's/\.php$/.gif/' *.php

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