LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Terminal error (https://www.linuxquestions.org/questions/linux-newbie-8/terminal-error-4175479840/)

kilee 10-06-2013 09:18 PM

Terminal error
 
I'm trying to move all mp3 I have to a single folder using the following

find / -iname "*.mp3" -type f | xargs -I '{}' mv {} /mnt/mp3

(posted here
But I receive the following error:

xargs: unmatched single quote; by default quotes are special to xargs unless you use the -0 option

It actually doesn't find any mp3 (which actually exists)

Is there any error in the argument?

Thanks for your help!

graeyhat 10-06-2013 09:32 PM

null.

SAbhi 10-06-2013 10:19 PM

Quote:

Originally Posted by kilee (Post 5041191)
I'm trying to move all mp3 I have to a single folder using the following

find / -iname "*.mp3" -type f | xargs -I '{}' mv {} /mnt/mp3

(posted here
But I receive the following error:

xargs: unmatched single quote; by default quotes are special to xargs unless you use the -0 option

Code:

find / -iname “*.mp3″ -type f -print0| xargs -0 -I ‘{}’ mv {} /mnt/mp3
Then add a -0 to check if previous command succeed, it should work now.

SAbhi 10-06-2013 10:20 PM

Quote:

Originally Posted by graeyhat (Post 5041195)
I would suggest removing the quotes. Change "*.mp3" to *.mp3.

try not to suggest an option that you did'nt tried or not certain what it'll do.

graeyhat 10-06-2013 10:35 PM

Sorry SAbhi. Your right. I edited my comment as 'Null.'.

jpollard 10-06-2013 10:36 PM

One thing that can cause this is if a file name has an apostrophe in it. With the quotes around "*.mp3" (which is valid, as it prevents the shell from interpreting it at the wrong time). The expansion, however, with xargs WOULD generate an error.

Another thing that would cause problems is spaces in the file name...

One thing you can try is to use a "set -vx" just before running the command. This turns on debugging in the shell and it will show everything that is done to the command line...

kilee 10-07-2013 10:38 AM

Thanks for your comments
I putted some mp3 files in my desktop. Tried to move them to Music

The results are these:

kilee@lap:~$ find /home/ki/Desktop/ -iname "*.mp3" -type f | xargs -0 -I '{}' mv {} /home/luis/Music/
find /home/luis/Desktop/ -iname "*.mp3" -type f | xargs -0 -I '{}' mv {} /home/luis/Music/
+ xargs -0 -I '{}' mv '{}' /home/luis/Music/
+ find /home/luis/Desktop/ -iname '*.mp3' -type f
mv: cannot stat ‘/home/luis/Desktop/01 - Locked Out Of Heaven.mp3\n/home/luis/Desktop/09 PSY - Gangnam Style.mp3\n/home/luis/Desktop/05 - One More Night.mp3\n’: No such file or directory

Just in case it is important, I'm using a xubuntu 13.04 2gb ram.

Thanks again for your help!

SAbhi 10-07-2013 10:43 AM

Quote:

Originally Posted by kilee (Post 5041552)

kilee@lap:~$ find /home/ki/Desktop/ -iname "*.mp3" -type f | xargs -0 -I '{}' mv {} /home/luis/Music/
find /home/luis/Desktop/ -iname "*.mp3" -type f | xargs -0 -I '{}' mv {} /home/luis/Music/
+ xargs -0 -I '{}' mv '{}' /home/luis/Music/
+ find /home/luis/Desktop/ -iname '*.mp3' -type f
mv: cannot stat ‘/home/luis/Desktop/01 - Locked Out Of Heaven.mp3\n/home/luis/Desktop/09 PSY - Gangnam Style.mp3\n/home/luis/Desktop/05 - One More Night.mp3\n’: No such file or directory

Thanks again for your help!


ok that happen when you dont see what actually is provided to you, please see my last post... i gave a whole command.
run it as it is but change the dir location.
Below again:
Code:

find / -iname “*.mp3″ -type f -print0| xargs -0 -I ‘{}’ mv {} /mnt/mp3

Firerat 10-07-2013 01:23 PM

for something like this, use find's exec

Code:

find / -iname "*.mp3" -type f -exec mv {} /mnt/mp3/ ';'
it is a good idea to have a trailing / on the directory
if the dir "mp3" did not exist you would end up moving the first file to file "/mnt/mp3"
then overwrite it with the next.... and so on


for more complex 'operations' use while read.

Code:

while read File;do
  .. some commands that work on "${File}"
done <<< $(find / -iname "*.mp3" -type f)


kilee 10-07-2013 07:49 PM

Thanks a lot
This worked perfect: find / -iname "*.mp3" -type f -exec mv {} /mnt/mp3/ ';'

JJJCR 10-07-2013 08:27 PM

Quote:

Originally Posted by Firerat (Post 5041632)
for something like this, use find's exec

Code:

find / -iname "*.mp3" -type f -exec mv {} /mnt/mp3/ ';'

hi Firerat, care to explain the code in a human readable way.

this curly braces {} and the ';' <-- what function does it perform?

Thanks. :)

JJJCR 10-07-2013 08:32 PM

did some Googling, just share it with anyone interested or who can simplified it or give further details:

This action works like this:

-exec command {} ;

where command is the name of a command, {} is a symbolic representation of the current
pathname
and the semicolon is a required delimiter indicating the end of the command.

Firerat 10-07-2013 09:09 PM

yeap ;)

Code:

man find
is a good read...

, note .. you must escape the ; , either \; or with ';'
I tend ti use ';' as on my keyboard ; and ' are next to each other ;)



you can also have + on the end

make a dir, ( easy to delete later )
cd into it
Code:

touch foo{1,2,3}
find -name "foo*" -exec echo {} ';'
find -name "foo*" -exec echo {} +

you should see the difference

kilee 10-08-2013 04:46 PM

Thank you all.

This has helped me a lot!
One aditional question. Is it possible to define a list of extensions extensions? let's say using this with the find command?

--include-from=/Users/me/Desktop/list.txt --include=*/ --exclude=*

Where List.txt includes all the possible extensions I need to move?

THanks!

kilee 10-08-2013 04:59 PM

Just to let you know, it doesnt work!


All times are GMT -5. The time now is 12:13 AM.