LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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 09-01-2010, 10:18 AM   #1
greenpoise
Member
 
Registered: Feb 2010
Posts: 37

Rep: Reputation: 2
Find and copy in the same directory


I installed a new music application. It reads covers.jpg as the cover of the album, however, my covers files where named album. I dont want to rename, I want to make a copy of album.jpg and if possible as well rename it to covers.jpg. The file has to be in the same folder that it currently is. I have looked around to see how I can do this but have not been able to.


thanks
 
Old 09-01-2010, 10:24 AM   #2
Udi
Member
 
Registered: Jan 2009
Posts: 165

Rep: Reputation: 44
You can use the file browser to create a copy of the file by Ctrl+C Ctrl+V, then rename the new file to cover.jpg.

On the command line, you can copy album.jpg to cover.jpg with this command:

cp album.jpg cover.jpg

Hope it helps
 
Old 09-01-2010, 10:27 AM   #3
greenpoise
Member
 
Registered: Feb 2010
Posts: 37

Original Poster
Rep: Reputation: 2
thanks for the reply. I am looking for a more automated way of doing it. Using the find exec cp commands would prob do it, I just dont know the complete command for it.
 
Old 09-01-2010, 10:48 AM   #4
rikijpn
Member
 
Registered: Jun 2007
Location: Japan
Distribution: Debian lenny, DSL, Solaris 10
Posts: 157

Rep: Reputation: 33
I'm assuming you mean you have all those directories together (in the same root/parent dir), as in:
Code:
music/album1
music/album2
...
music/albumN
And want to change the paths like this:
Code:
album1/album.jpg  --> album1/covers.jpg
If this is the case, you can just use a "for" (in bash) sentence to copy every dir's album.jpg file to the same dir's covers.jpg file, like this:
Code:
 
#cd music
for dir in * ; do cp $dir/album.jpg $dir/covers.jpg ; done
It doesn't check for files in the dirs, and takes all the files in the current dir, so it will return errors if you have a path like "music/file.txt", but it won't delete anything^^.

Last edited by rikijpn; 09-01-2010 at 11:07 AM.
 
Old 09-01-2010, 11:23 AM   #5
tracertong
Member
 
Registered: Jun 2010
Posts: 34

Rep: Reputation: 16
Or better still, wildcard it, as in (to use the example directory structure given above):

#cd music
for dir in album* ; do cp $dir/album.jpg $dir/covers.jpg ; done;

This stops it spidering every single subdirectory: only those that match the pattern 'album-something'.
 
Old 09-01-2010, 12:00 PM   #6
greenpoise
Member
 
Registered: Feb 2010
Posts: 37

Original Poster
Rep: Reputation: 2
It wants to work but it doesnt.

My structure is something like this:

/home/dan/Music/albumA
/home/dan/Music/albumB
/home/dan/Music/albumB/CD1
/home/dan/Music/albumB/CD2
/home/dan/Music/albumC


This is a what is like. It is giving me this errors:

cp: target `Project/cover.jpg' is not a directory
cp: target `(CD2)/cover.jpg' is not a directory
cp: target `CD2/cover.jpg' is not a directory
cp: target `Vavavoom/cover.jpg' is not a directory
cp: target `Contraband/cover.jpg' is not a directory

Thanks alot for the help!
 
Old 09-01-2010, 12:12 PM   #7
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
Quote:
Originally Posted by greenpoise View Post
I installed a new music application. It reads covers.jpg as the cover of the album, however, my covers files where named album. I dont want to rename, I want to make a copy of album.jpg and if possible as well rename it to covers.jpg. The file has to be in the same folder that it currently is. I have looked around to see how I can do this but have not been able to.


thanks
Hi,

is this what you are looking for?
Code:
find /path/to/dir -type f -name album.jpg -execdir cp album.jpg covers.jpg \;

Last edited by crts; 09-01-2010 at 12:14 PM.
 
Old 09-01-2010, 12:19 PM   #8
rikijpn
Member
 
Registered: Jun 2007
Location: Japan
Distribution: Debian lenny, DSL, Solaris 10
Posts: 157

Rep: Reputation: 33
It would be great if you could return the output of a quick "ls" too^^.
I can only guess, you have spaces in your directory names. Also having your locale in another language (do "locale" to check?) may have something to do.
Anyway, if it's only that you have spaces in the dir names, make a script (save this to text to "script.sh" or something) with the following:
Code:
IFS='
'

for dir in * ; do cp $dir/album.jpg $dir/covers.jpg ; done
This sets the internal field separator (IFS) only to newlines (return key), not including spaces as default. I think the parenthesis shouldn't be a problem...

Wow, crts's code is better... find is amazing.
 
Old 09-01-2010, 12:28 PM   #9
greenpoise
Member
 
Registered: Feb 2010
Posts: 37

Original Poster
Rep: Reputation: 2
Quote:
Originally Posted by rikijpn View Post
It would be great if you could return the output of a quick "ls" too^^.
I can only guess, you have spaces in your directory names. Also having your locale in another language (do "locale" to check?) may have something to do.
Anyway, if it's only that you have spaces in the dir names, make a script (save this to text to "script.sh" or something) with the following:
Code:
IFS='
'

for dir in * ; do cp $dir/album.jpg $dir/covers.jpg ; done
This sets the internal field separator (IFS) only to newlines (return key), not including spaces as default. I think the parenthesis shouldn't be a problem...

Wow, crts's code is better... find is amazing.

Bingo!! that was it, spaces between . Thanks alot! very helpful. No way I could have come up with this.


Thanks again all of you
 
Old 09-01-2010, 12:29 PM   #10
greenpoise
Member
 
Registered: Feb 2010
Posts: 37

Original Poster
Rep: Reputation: 2
wait a sec. it did not do all of them though.
 
Old 09-01-2010, 12:41 PM   #11
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
Quote:
Originally Posted by greenpoise View Post
wait a sec. it did not do all of them though.
what was skipped? Show an example that was omitted and then we'll see how to fix it.

Have you tried the 'find' from post #7?

Last edited by crts; 09-01-2010 at 12:42 PM.
 
Old 09-01-2010, 12:46 PM   #12
rikijpn
Member
 
Registered: Jun 2007
Location: Japan
Distribution: Debian lenny, DSL, Solaris 10
Posts: 157

Rep: Reputation: 33
ahaha^^ that's too bad. You should really be a little more specific. Like instead of saying it didn't get all of them, telling which ones it didn't get, or even better, do an "find" in that dir and paste the output here, etc. It's kind of hard keeping guessing^^.

I can only guess, you maybe have some subdirectories in the same directory structure, so the code I gave you wouldn't work right (being that is only reading the files/dirs in the current directory). In that case the script would become kinda long/complicated/plain ugly.

crts's code is most likely to work in such a case too, did you try it?

Last edited by rikijpn; 09-01-2010 at 01:33 PM.
 
Old 09-01-2010, 01:01 PM   #13
greenpoise
Member
 
Registered: Feb 2010
Posts: 37

Original Poster
Rep: Reputation: 2
post 7 throws this:

find: The current directory is included in the PATH environment variable, which is insecure in combination with the -execdir action of find. Please remove the current directory from your $PATH (that is, remove "." or leading or trailing colons)


I do have subdirectories..I tried posting my music library tree but it is too long. let me try a smaller list
 
Old 09-01-2010, 01:03 PM   #14
greenpoise
Member
 
Registered: Feb 2010
Posts: 37

Original Poster
Rep: Reputation: 2
this are two consecutive directories:

Quote:
|-- Dishwalla - Pet Your Friends
| |-- Dishwalla - Pet Your Friends - 01 - Pretty Babies.ogg
| |-- Dishwalla - Pet Your Friends - 02 - Haze.ogg
| |-- Dishwalla - Pet Your Friends - 03 - Counting Blue Cars.ogg
| |-- Dishwalla - Pet Your Friends - 04 - Explode.ogg
| |-- Dishwalla - Pet Your Friends - 05 - Charlie Brown's Parents.ogg
| |-- Dishwalla - Pet Your Friends - 06 - Give.ogg
| |-- Dishwalla - Pet Your Friends - 07 - Miss Emma Peel.ogg
| |-- Dishwalla - Pet Your Friends - 08 - Moisture.ogg
| |-- Dishwalla - Pet Your Friends - 09 - The Feeder.ogg
| |-- Dishwalla - Pet Your Friends - 10 - All She Can See.ogg
| |-- Dishwalla - Pet Your Friends - 11 - Only For so Long.ogg
| |-- Dishwalla - Pet Your Friends - 12 - Interview With St. Etienne.ogg
| |-- Dishwalla - Pet Your Friends.ogg.m3u
| |-- album.jpg
| `-- cover.jpg
|-- Eagles of Death Metal
| |-- Eagles Of Death Metal - Peace Love Death Metal
| | |-- Eagles Of Death Metal - Already Died.mp3
| | |-- Eagles Of Death Metal - Bad Dream Mama.mp3
| | |-- Eagles Of Death Metal - English Girl.mp3
| | |-- Eagles Of Death Metal - Flames Go Higher.mp3
| | |-- Eagles Of Death Metal - I Only Want You.mp3
| | |-- Eagles Of Death Metal - Kiss the Devil.mp3
| | |-- Eagles Of Death Metal - Midnight Creeper.mp3
| | |-- Eagles Of Death Metal - Miss Alissa.mp3
| | |-- Eagles Of Death Metal - San Berdoo Sunburn.mp3
| | |-- Eagles Of Death Metal - So Easy.mp3
| | |-- Eagles Of Death Metal - Speaking In Tongues.mp3
| | |-- Eagles Of Death Metal - Stacks O Money.mp3
| | |-- Eagles Of Death Metal - Stuck In The Metal.mp3
| | |-- Eagles Of Death Metal - Wastin My Time.mp3
| | |-- Eagles Of Death Metal - Whorehoppin (Shit, Goddamn).mp3
| | |-- album.jpg
| | `-- playlist.m3u
 
Old 09-01-2010, 01:10 PM   #15
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
Then try this
Code:
find /your/music/dir -type f -name album.jpg -exec sh -c 'cp "$1" $(dirname "$1")/covers.jpg' {} {} \;
 
  


Reply



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
find files with pattern, then copy those files to another directory ncsuapex Programming 4 08-13-2010 03:38 PM
How to Copy files from local directory to a particular directory using alias dynamics Linux - Newbie 7 09-11-2009 04:19 PM
How to copy files after search in array from this directory to another directory! phanvinhgiap Programming 4 01-04-2009 06:48 PM
How to copy one directory to another directory thru PHP? green_njk Programming 1 01-06-2006 06:55 AM
copy files from directory to directory without subfile ALInux Linux - General 2 06-03-2005 11:51 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:56 AM.

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
Open Source Consulting | Domain Registration