LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   Xargs and spaces in file path (http://www.linuxquestions.org/questions/linux-software-2/xargs-and-spaces-in-file-path-611146/)

mgichoga 01-04-2008 12:30 PM

Xargs and spaces in file path
 
I'm trying to delete some mp3 from my backup server to free up some space and was using locate and xargs to do this. This works well except when there is a space in the file path. How can I pass the file path to xargs with quotes so the rm command can be able to parse the file path. this is what the command I'm issuing

locate *.mp3 | xargs rm

Dinithion 01-04-2008 12:59 PM

Try:
locate --print0 *.mp3 | xargs -0 -n 10 echo

I'm not sure if it will work. It works here in small scale, but when I push the whole locate trough, it gives a error msg. Anyway, the --print0 option sends a ascii0 at the end of the filename, and -0 option on xargs uses this null as a argument seperator. Finally -n limits the execution to 10 files at a time.

If it works, change echo with rm :)

Tinkster 01-04-2008 01:57 PM

Or
Code:

locate \.mp3|xargs -i rm "{}"
might work .... (untested!)



Cheers,
Tink


All times are GMT -5. The time now is 04:56 PM.