LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-08-2009, 12:46 PM   #1
stratotak
Member
 
Registered: Sep 2005
Distribution: Today Debian . Tomorrow ..??
Posts: 386

Rep: Reputation: 39
copying folder and changing extension of files in it?


IM trying to figure out the command I would use to copy contents of a folder and change the extension of the files within the folders.For example..I have main folder.. Folder A..in that folder are folders..folder 1,folder 2,folder 3,etc..and in each folder are files.I need to change the extensions of the files from .ewav to .wav..and keep the folder structure.
 
Old 03-08-2009, 07:32 PM   #2
yancek
LQ Guru
 
Registered: Apr 2008
Distribution: PCLinux, Slackware
Posts: 7,216

Rep: Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348
To rename your files with '.ewav' extension to files with '.wav' extension:

rename .ewav .wav *.ewav

This will work in the directory in which you run the command. I don't understand what you are trying to do with the copy command, copy what to where?? If you need to rename files with this extension in multiple folders?? Not sure how you would do that with a single command.
 
Old 03-09-2009, 03:52 AM   #3
stratotak
Member
 
Registered: Sep 2005
Distribution: Today Debian . Tomorrow ..??
Posts: 386

Original Poster
Rep: Reputation: 39
Well..Im getting closer to figuring it out..trying different variations of commands..hers a test folder of what im trying to do..maybe someone else knows how to get the rest of the way..I figured out how to copy folder and keep folder structure intact..just having issue with renaming the files to just change there extension..
Code:
strat@debian:~$ ls -R pack
pack:
[SP] Engl Pro 4x12 V30                   [SP] Mesa Oversized 4x12 V30
[SP] Framus 4x12 V30                     [SP] Mesa Trad 4x12 V30
[SP] Marshall 1960A 4x12 V30 + G12 (XP)

pack/[SP] Engl Pro 4x12 V30:
Engl Pro 4x12 V30 SM57 Between 01.wav  Engl Pro 4x12 V30 SM57 New 03.wav
Engl Pro 4x12 V30 SM57 Between 02.wav  Engl Pro 4x12 V30 SM57 New 04.wav
Engl Pro 4x12 V30 SM57 Between 03.wav  Engl Pro 4x12 V30 SM57 New 05.wav
Engl Pro 4x12 V30 SM57 Between 04.wav  Engl Pro 4x12 V30 SM57 New 06.wav
Engl Pro 4x12 V30 SM57 Center 01.wav   Engl Pro 4x12 V30 SM57 New 07.wav
Engl Pro 4x12 V30 SM57 Center 02.wav   Engl Pro 4x12 V30 SM57 New 08.wav
Engl Pro 4x12 V30 SM57 Center 03.wav   Engl Pro 4x12 V30 SM57 New 09.wav
Engl Pro 4x12 V30 SM57 Center 04.wav   Engl Pro 4x12 V30 SM57 New 10.wav
Engl Pro 4x12 V30 SM57 Center 05.wav   Engl Pro 4x12 V30 SM57 New 11.wav
Engl Pro 4x12 V30 SM57 New 01.wav      Engl Pro 4x12 V30 SM57 New 12.wav
Engl Pro 4x12 V30 SM57 New 02.wav

pack/[SP] Framus 4x12 V30:
Framus 4x12 V30 SM57 01.wav

pack/[SP] Marshall 1960A 4x12 V30 + G12 (XP):
Marshall 1960A V30 SM57 - 01.wav

pack/[SP] Mesa Oversized 4x12 V30:
Mesa Oversized 4x12 V30 SM57 01.wav  Mesa Oversized 4x12 V30 SM57 07.wav
Mesa Oversized 4x12 V30 SM57 02.wav  Mesa Oversized 4x12 V30 SM57 08.wav
Mesa Oversized 4x12 V30 SM57 03.wav  Mesa Oversized 4x12 V30 SM57 09.wav
Mesa Oversized 4x12 V30 SM57 04.wav  Mesa Oversized 4x12 V30 SM57 10.wav
Mesa Oversized 4x12 V30 SM57 05.wav  Mesa Oversized 4x12 V30 SM57 11.wav
Mesa Oversized 4x12 V30 SM57 06.wav

pack/[SP] Mesa Trad 4x12 V30:
Mesa Trad 4x12 V30 SM57 01.wav  Mesa Trad 4x12 V30 SM57 05.wav
Mesa Trad 4x12 V30 SM57 02.wav  Mesa Trad 4x12 V30 SM57 06.wav
Mesa Trad 4x12 V30 SM57 03.wav  Mesa Trad 4x12 V30 SM57 07.wav
Mesa Trad 4x12 V30 SM57 04.wav  Mesa Trad 4x12 V30 SM57 08.wav
strat@debian:~$ cp -r pack  backup
strat@debian:~$ ls -R backup
backup:
[SP] Engl Pro 4x12 V30                   [SP] Mesa Oversized 4x12 V30
[SP] Framus 4x12 V30                     [SP] Mesa Trad 4x12 V30
[SP] Marshall 1960A 4x12 V30 + G12 (XP)

backup/[SP] Engl Pro 4x12 V30:
Engl Pro 4x12 V30 SM57 Between 01.wav  Engl Pro 4x12 V30 SM57 New 03.wav
Engl Pro 4x12 V30 SM57 Between 02.wav  Engl Pro 4x12 V30 SM57 New 04.wav
Engl Pro 4x12 V30 SM57 Between 03.wav  Engl Pro 4x12 V30 SM57 New 05.wav
Engl Pro 4x12 V30 SM57 Between 04.wav  Engl Pro 4x12 V30 SM57 New 06.wav
Engl Pro 4x12 V30 SM57 Center 01.wav   Engl Pro 4x12 V30 SM57 New 07.wav
Engl Pro 4x12 V30 SM57 Center 02.wav   Engl Pro 4x12 V30 SM57 New 08.wav
Engl Pro 4x12 V30 SM57 Center 03.wav   Engl Pro 4x12 V30 SM57 New 09.wav
Engl Pro 4x12 V30 SM57 Center 04.wav   Engl Pro 4x12 V30 SM57 New 10.wav
Engl Pro 4x12 V30 SM57 Center 05.wav   Engl Pro 4x12 V30 SM57 New 11.wav
Engl Pro 4x12 V30 SM57 New 01.wav      Engl Pro 4x12 V30 SM57 New 12.wav
Engl Pro 4x12 V30 SM57 New 02.wav

backup/[SP] Framus 4x12 V30:
Framus 4x12 V30 SM57 01.wav

backup/[SP] Marshall 1960A 4x12 V30 + G12 (XP):
Marshall 1960A V30 SM57 - 01.wav

backup/[SP] Mesa Oversized 4x12 V30:
Mesa Oversized 4x12 V30 SM57 01.wav  Mesa Oversized 4x12 V30 SM57 07.wav
Mesa Oversized 4x12 V30 SM57 02.wav  Mesa Oversized 4x12 V30 SM57 08.wav
Mesa Oversized 4x12 V30 SM57 03.wav  Mesa Oversized 4x12 V30 SM57 09.wav
Mesa Oversized 4x12 V30 SM57 04.wav  Mesa Oversized 4x12 V30 SM57 10.wav
Mesa Oversized 4x12 V30 SM57 05.wav  Mesa Oversized 4x12 V30 SM57 11.wav
Mesa Oversized 4x12 V30 SM57 06.wav

backup/[SP] Mesa Trad 4x12 V30:
Mesa Trad 4x12 V30 SM57 01.wav  Mesa Trad 4x12 V30 SM57 05.wav
Mesa Trad 4x12 V30 SM57 02.wav  Mesa Trad 4x12 V30 SM57 06.wav
Mesa Trad 4x12 V30 SM57 03.wav  Mesa Trad 4x12 V30 SM57 07.wav
Mesa Trad 4x12 V30 SM57 04.wav  Mesa Trad 4x12 V30 SM57 08.wav
strat@debian:~$ rename backup/*/*.wav  *.txt
Bareword found where operator expected at (eval 1) line 1, near "] Engl"
	(Missing operator before Engl?)
Bareword found where operator expected at (eval 1) line 1, near "12 V30"
	(Missing operator before V30?)
Bareword found where operator expected at (eval 1) line 1, near "12 V30"
	(Missing operator before V30?)
Number found where operator expected at (eval 1) line 1, near "Between 01"
	(Do you need to predeclare Between?)
syntax error at (eval 1) line 1, near "] Engl Pro "
strat@debian:~$
Im stuck at renaming part..Im not even sure that is the correct command..and Im assuming the errors I am getting are from the files having spaces in there names..First question is can I easily get rid of the spaces and replace them with a "_"..and then if that rename command is right.This is just a test trying to figure out the right commands..Im not trying to change a.wav to a text file..Its just the extension I used..could have been .mp3,.avi...etc..And If i can get the rename command i should be able to do this with just one command.
Code:
  cp -r   backup && rename ????????
Question marks are the unknown correct command

Last edited by stratotak; 03-10-2009 at 05:31 AM.
 
Old 03-09-2009, 04:00 AM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
I don't know whether rename will handle the wildcards gracefully,
but you got the syntax round the wrong way ...

rename .wav .txt backup/*/*.wav
 
Old 03-09-2009, 05:05 AM   #5
stratotak
Member
 
Registered: Sep 2005
Distribution: Today Debian . Tomorrow ..??
Posts: 386

Original Poster
Rep: Reputation: 39
well little by little im getting closer..lol..after googling a bit i found command to remove spaces..
Code:
rename -v 's/\ /\_/g' *
the "*" is how deep the folder structure it goes..
http://zona90.wordpress.com/2008/11/...inux-commands/
still have issue with renaming though

Code:
strat@debian:~$ ls -R pack
pack:
[SP]_Engl_Pro_4x12_V30  [SP]_Framus_4x12_V30  [SP]_Marshall_1960A_4x12_V30_+_G12_(XP)  [SP]_Mesa_Oversized_4x12_V30  [SP]_Mesa_Trad_4x12_V30

pack/[SP]_Engl_Pro_4x12_V30:
Engl_Pro_4x12_V30_SM57_Between_01.wav  Engl_Pro_4x12_V30_SM57_Center_02.wav  Engl_Pro_4x12_V30_SM57_New_02.wav  Engl_Pro_4x12_V30_SM57_New_07.wav  Engl_Pro_4x12_V30_SM57_New_12.wav
Engl_Pro_4x12_V30_SM57_Between_02.wav  Engl_Pro_4x12_V30_SM57_Center_03.wav  Engl_Pro_4x12_V30_SM57_New_03.wav  Engl_Pro_4x12_V30_SM57_New_08.wav
Engl_Pro_4x12_V30_SM57_Between_03.wav  Engl_Pro_4x12_V30_SM57_Center_04.wav  Engl_Pro_4x12_V30_SM57_New_04.wav  Engl_Pro_4x12_V30_SM57_New_09.wav
Engl_Pro_4x12_V30_SM57_Between_04.wav  Engl_Pro_4x12_V30_SM57_Center_05.wav  Engl_Pro_4x12_V30_SM57_New_05.wav  Engl_Pro_4x12_V30_SM57_New_10.wav
Engl_Pro_4x12_V30_SM57_Center_01.wav   Engl_Pro_4x12_V30_SM57_New_01.wav     Engl_Pro_4x12_V30_SM57_New_06.wav  Engl_Pro_4x12_V30_SM57_New_11.wav

pack/[SP]_Framus_4x12_V30:
Framus_4x12_V30_SM57_01.wav

pack/[SP]_Marshall_1960A_4x12_V30_+_G12_(XP):
Marshall_1960A_V30_SM57_-_01.wav

pack/[SP]_Mesa_Oversized_4x12_V30:
Mesa_Oversized_4x12_V30_SM57_01.wav  Mesa_Oversized_4x12_V30_SM57_04.wav  Mesa_Oversized_4x12_V30_SM57_07.wav  Mesa_Oversized_4x12_V30_SM57_10.wav
Mesa_Oversized_4x12_V30_SM57_02.wav  Mesa_Oversized_4x12_V30_SM57_05.wav  Mesa_Oversized_4x12_V30_SM57_08.wav  Mesa_Oversized_4x12_V30_SM57_11.wav
Mesa_Oversized_4x12_V30_SM57_03.wav  Mesa_Oversized_4x12_V30_SM57_06.wav  Mesa_Oversized_4x12_V30_SM57_09.wav

pack/[SP]_Mesa_Trad_4x12_V30:
Mesa_Trad_4x12_V30_SM57_01.wav  Mesa_Trad_4x12_V30_SM57_03.wav  Mesa_Trad_4x12_V30_SM57_05.wav  Mesa_Trad_4x12_V30_SM57_07.wav
Mesa_Trad_4x12_V30_SM57_02.wav  Mesa_Trad_4x12_V30_SM57_04.wav  Mesa_Trad_4x12_V30_SM57_06.wav  Mesa_Trad_4x12_V30_SM57_08.wav
strat@debian:~$ rename .wav .txt  backup/*/*.wav
syntax error at (eval 1) line 1, near "."
strat@debian:~$
 
Old 03-09-2009, 05:35 AM   #6
Junior Hacker
Senior Member
 
Registered: Jan 2005
Location: North America
Distribution: Debian testing Mandriva Ubuntu
Posts: 2,687

Rep: Reputation: 61
In the past, I would download my updates on high speed internet at a different location because one of my residences has dial-up. I would use firefox in Debian, but downloaded to a FAT32 USB stick, for some reason it would download the file with correct name but would add a second extension, example:

package.rpm became package.rpm.rpm

This is how I would rename the files to remove the second extension, this command would have to be run from the directory containing the double extension files:

for i in *.rpm.rpm; do mv "$i" "`basename $i .rpm.rpm`.rpm"; done

Try adding this (below) to your command, make sure to have a recursive option in the right place to do it recursively.

for i in *.ewav; do mv "$i" "`basename $i .ewav`.wav"; done
 
Old 03-09-2009, 05:39 AM   #7
Junior Hacker
Senior Member
 
Registered: Jan 2005
Location: North America
Distribution: Debian testing Mandriva Ubuntu
Posts: 2,687

Rep: Reputation: 61
BTW:
Using that command does not require you to remove spaces as the wildcard (*) is before the extension.
 
Old 03-09-2009, 06:28 AM   #8
stratotak
Member
 
Registered: Sep 2005
Distribution: Today Debian . Tomorrow ..??
Posts: 386

Original Poster
Rep: Reputation: 39
but that way wont do multiple directories?I would have to cd into each directory where files are.Which isnt bad if it 1-2-3 directories but like 20 or so..I found this way of doing it but cant seem to get the context right..Ill have to work on it later..His uses "f" instead of "i"
http://thetechforums.net/howToLinux/?p=19
Folder Im going to convert has like 30-40 folders or so and some folders contain 1-2 .ewav files and some contain 10 or so..so cding into each directory and doing this is quite tedious..I might just have to boot into windows to do this..I had done this before last year or so and used a free utility to rename .ewav to .wav .. it was just a matter selecting folder and right click..and it handled all the files in subfolders.

Last edited by stratotak; 03-09-2009 at 06:39 AM.
 
Old 03-09-2009, 07:30 AM   #9
stratotak
Member
 
Registered: Sep 2005
Distribution: Today Debian . Tomorrow ..??
Posts: 386

Original Poster
Rep: Reputation: 39
ok..just incase anyone else needs to change alot of files extensions in multiple directories..I downloaded a little windows app that works perfect in wine..just drag and drop folder onto it and it works perfect..its called ezXTN..
http://www.sph.sc.edu/comd/rorden/ezxtn.html
 
Old 03-09-2009, 07:37 AM   #10
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671
This might work for you:
eval $(find test/ -type f -name "*.ewav" | sed -n '/ewav/s/\(.*\).ewav/mv "\1.ewav" "\1.wav/p"')

If the list is very long, then instead of using eval, redirect the output to a script and execute the script.
 
Old 03-09-2009, 07:49 AM   #11
stratotak
Member
 
Registered: Sep 2005
Distribution: Today Debian . Tomorrow ..??
Posts: 386

Original Poster
Rep: Reputation: 39
yeah..but that sure is alot to type.and to remember.its kinda hard to beat drag&drop..like i said..that little windows app works great in wine..tried another one called extension changer..works well under wine to..Would think that someone would have developed at little app to do this in linux..??
 
Old 03-09-2009, 08:06 AM   #12
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 840

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
i believe there's an application called Bulk Rename or something like that that could do that
i guess it's part of kde but i'm not sure about that
 
Old 03-09-2009, 08:17 AM   #13
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959
The perl rename command is probably the easiest way to rename files, as has been mentioned above. It's syntax is pretty much identical to sed.

Another way you could do it is with parameter substitution.

Code:
for i in *; do

mv $i ${i%.ewav}.wav

done
You can replace * with whatever command you use to generate the filelist, of course, such as "$(find .)".
 
Old 03-09-2009, 11:46 AM   #14
stratotak
Member
 
Registered: Sep 2005
Distribution: Today Debian . Tomorrow ..??
Posts: 386

Original Poster
Rep: Reputation: 39
I searched through synaptic and found a few rename apps..PyRenamer seems to be what i was looking for.It will do everything I need,I can set it to do a directory and all its subfolders...it will remove spaces and replace with "_"..and change extension all with 1 click..
 
Old 03-09-2009, 12:49 PM   #15
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671
Quote:
Originally Posted by stratotak View Post
yeah..but that sure is alot to type.and to remember.its kinda hard to beat drag&drop..like i said..that little windows app works great in wine..tried another one called extension changer..works well under wine to..Would think that someone would have developed at little app to do this in linux..??
All you have to do is make a oneliner script from it, and copy it to your ~/bin/ directory. Then run the script when you need to.

No need to use a windows app. You never know where it's been!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
automatically inherit parent folder permissions when copying files teixeira Linux - Newbie 3 07-08-2008 12:21 PM
Copying Files having a certain Extension using java MRMadhav Programming 1 06-13-2006 07:30 AM
Changing extension of multiple files harisund Programming 17 06-01-2006 10:59 AM
changing extension of multiple files shaggystyle Linux - General 5 01-29-2004 12:35 PM
I have 8 character file name, no extension files being created in my dbaseIII+ folder bonzo Linux - General 2 01-22-2004 06:49 AM


All times are GMT -5. The time now is 03:55 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration