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 |
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 :) |
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.
|
I'm assuming you mean you have all those directories together (in the same root/parent dir), as in:
Code:
music/album1 Code:
album1/album.jpg --> album1/covers.jpg Code:
|
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'. |
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! |
Quote:
is this what you are looking for? Code:
find /path/to/dir -type f -name album.jpg -execdir cp album.jpg covers.jpg \; |
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=' Wow, crts's code is better... find is amazing. |
Quote:
Bingo!! that was it, spaces between . Thanks alot! very helpful. No way I could have come up with this. Thanks again all of you |
wait a sec. it did not do all of them though.
|
Quote:
Have you tried the 'find' from post #7? |
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? |
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 |
this are two consecutive directories:
Quote:
|
Then try this
Code:
find /your/music/dir -type f -name album.jpg -exec sh -c 'cp "$1" $(dirname "$1")/covers.jpg' {} {} \; |
All times are GMT -5. The time now is 04:56 PM. |