Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

For example, I want to use mplayer to play the music of several dirs, type like this in bash:

$find './l_music/La Scala Concert 03 03 03' './l_music/Echoes The Einaudi Collection' './l_music/Ludovico Einaudi - The Royal Albert Hall Concert [2 CD] (2010)' -name '*.mp3' | xargs mplayer

Well, You Know, the find command return path, which dir and file always have space, the pipe right command mplayer do not accept those mp3 path.

I think that if wrap the find return strings with single/double quotation marks (\'or\") to feed to mplayer, the problem will be solved.

But how can I do to solve the problem just use bash command, do not use bash or perl scripts, while can give me one perl line command use Perl Command-Line Options.

share|improve this question

closed as off topic by Ward, Lucas Kauffman, Scott Pack, Magellan, mdpc Oct 30 '12 at 16:27

Questions on Server Fault are expected to relate to professional server, networking, or related infrastructure administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

add comment

1 Answer 1

up vote 1 down vote accepted

Use the -print0 option in find which will separate the filenames using a null character instead of a space.

In xargs use -0 which tells it that the filesnames it will receive as input are separated by nulls.

Your example command then becomes:

find './l_music/La Scala Concert 03 03 03' './l_music/Echoes The Einaudi Collection' './l_music/Ludovico Einaudi - The Royal Albert Hall Concert [2 CD] (2010)' -name '*.mp3' -print0 | xargs -0 mplayer

See also: How can I handle spaces in file names when using xargs on find results?

share|improve this answer
    
Thank you very much, it is what I need. –  infantcoder Sep 27 '12 at 2:30
    
gosh!! ^_^ why the mplayer is out of key control after use the command? –  infantcoder Sep 27 '12 at 2:54
    
@infantcoder: I can't say. That would be a question better answered on superuser.com or unix.stackexchange.com. –  Starfish Sep 27 '12 at 3:03
    
pretty guy, Thank you very very much, I will do. –  infantcoder Sep 27 '12 at 3:08
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.