Register
It is currently Thu Jul 24, 2014 7:03 am

Remove a specific extension from all files in the directory


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Tue May 17, 2005 8:05 pm   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 662
Location: Des Moines, Iowa
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...


Top
 Profile WWW  
 PostPosted: Tue May 17, 2005 8:05 pm   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 662
Location: Des Moines, Iowa
shorter version....... a one liner cut-n-paste into the terminal

Code:

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


Top
 Profile WWW  
 PostPosted: Tue May 17, 2005 8:06 pm   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 662
Location: Des Moines, Iowa
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


Top
 Profile WWW  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Majestic-12 [Bot] and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP