Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 01-04-2008, 11:30 AM   #1
Registered: Sep 2004
Distribution: Ubuntu
Posts: 42

Rep: Reputation: 16
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
Old 01-04-2008, 11:59 AM   #2
Registered: Oct 2007
Location: Norway
Distribution: Slackware 14.1
Posts: 446

Rep: Reputation: 59
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
Old 01-04-2008, 12:57 PM   #3
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

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



Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
makefiles with spaces in path teuf Programming 7 08-30-2007 03:04 AM
Using xargs to process file from list? jon_k Programming 2 01-14-2007 04:14 PM
tsmbfs simple path name with spaces spooge Linux - Networking 4 08-31-2006 12:32 AM
how to expand wildcards in a path with spaces? sts Linux - General 1 11-12-2005 01:50 PM
using rsync - one of the folders in path has spaces??? jgruss Linux - Networking 10 07-07-2004 07:27 PM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:54 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration