Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
ACTIONS
-exec command ;
Execute command; true if 0 status is returned. All following
arguments to find are taken to be arguments to the command until
an argument consisting of ‘;’ is encountered. The string ‘{}’
is replaced by the current file name being processed everywhere
it occurs in the arguments to the command, not just in arguments
where it is alone, as in some versions of find. Both of these
constructions might need to be escaped (with a ‘\’) or quoted to
protect them from expansion by the shell. The command is exe-
cuted in the starting directory.
so then I would type:
find /usr/music -iname "*.mp3" -exec cp '*.mp3' /usr/music
1) I'm sorry for confusing you with /usr/music and /mnt/music.. you have, of course, to use /mnt/music. I use /usr/music because I have my music in this directory...
2) cp works in way " cp source destination"
3) that '{}' means actual file name which have file utility currently found. It's bit tricky if you have never used it so little example how it works (with my directory structure):
bash-2.05b# pwd
/usr/music/Gang Starr/The Ownerz
bash-2.05b# find . -iname "*.mp3" -exec echo '{}' is current filename ';'
(...)
./04 - Sabotage.mp3 is current filename
./05 - Rite Where U Stand featuring Jadakiss.mp3 is current filename
./06 - Skillz.mp3 is current filename
(...)
which means: Find in current directory files ending with mp3 and when you have found, echo their name (which is represented by that '{}'; it's variable containing filename) and 'is current filename' string. That ';' just indicates that -exec command has no other arguments. Very important to realize is fact that '{}' represents just one filename at time.
As indicated in second paragraph cp (mv as well) needs to get source as first argument.
THanks for your help...naah, I noticed the /usr instead of mount...that wasn't it. THe first command you gave was missing syntax and I was just too noob to see it.
following -exec is now the cp command.
I will try this, without echo -- I don't need to see the command in action -- just results.
Thank you, HLVS.
My understanding of the string:
find /mnt/music -iname "*.ogg" ...find all the files with extension .ogg in the music directory (in all of their folders)...
-exec cp '{}' /mnt/music ';' ...copy all of them (each found one '{}') to the music (root) directory
';', no switches for -exec
Distribution: openSuSE Tumbleweed-KDE, Mint 21, MX-21, Manjaro
Posts: 4,629
Rep:
I knew it, and now I had time to find it:
Code:
cp -r *.ogg .
That's all -- at least as long there are no mp3-files in the target directory "." in which case you might want another option, which prevents overwriting of existing files:
machiner: heh, now i got to look to dictionary for "friggen" word :-)
JZL240I-U: I'm bit unsure about this, since "cp -r *.ogg" should, AFAIK, look for all files/dir in current dir. Not for all files in all nested dirs. I'm currently at work where I don't have access to coreutils-using machine, but I'm pretty sure it doesn't work on FBSD.
Distribution: openSuSE Tumbleweed-KDE, Mint 21, MX-21, Manjaro
Posts: 4,629
Rep:
Nope. -r means recursive (in subdirectories). So it says: copy recursively the *.oggs to "." (the working directory). Works without collision if you have no ogg files here. Use -ru i.e. with the update option, which copies only newer files to "." (since existing files are equally old but not newer they are not copied -- at least thats the theory ).
It's tough asking anything on this forum. I successfully found (recursively -- down in directories) all those files, and now they are in one big directory.
The whole purpose to this (besides learning more about linux and commands) is to convert my .mp3 files.
SOme of the rips I did from my cd's apparently were crummy -- there are skips and/pops in some of my songs....no good. I am reasonably sure that converting them will NOT solve the problem - an absence of data is an absence of data -- but I like to mess around with my computer.
Thanks again.
machiner
HLVS - friggen is simply a colloquial expression roughly meaning the same as another colorful (fu#*ing) expression. It's generally safer to use and conveys the same contextual meaning.
eg: this friggen bites
however, friggen is no replacement for the ever-popular "go f*%$ yourself"
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.