BashScripts.org
http://bashscripts.org/forum/

Remove a specific extension from all files in the directory
http://bashscripts.org/forum/viewtopic.php?f=7&t=72
Page 1 of 1

Author:  crouse [ Tue May 17, 2005 8:05 pm ]
Post subject:  Remove a specific extension from all files in the directory

Code:
#!/bin/sh
for file in *.xyz; do
  newname=`echo $file | sed -e 's/\.xyz//'`
  mv -f $file $newname
done


replace .xyz with the name of the extension you want to remove...

Author:  crouse [ Tue May 17, 2005 8:05 pm ]
Post subject: 

shorter version....... a one liner cut-n-paste into the terminal

Code:

for filename in *.xyz; do mv $filename ${filename%.xyz}; done

Author:  crouse [ Tue May 17, 2005 8:06 pm ]
Post subject: 

jbsnake
Moderator

From: Georgia, U.S.A.
Registered: Nov 11th, 2004
Posts: 102


this should remove all three letter extensions from all files in the directory with a three letter extension :)

Code:

for filename in *.???; do mv $filename ${filename:0:${#filename}-4}; done




_______________________________________
Arch Linux 0.7 Kernel 2.6.11.7-ARCH

Page 1 of 1 All times are UTC - 6 hours
© 2000, 2002, 2005, 2007 phpBB Group • http://www.phpbb.com