0

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.

1 Answers1

1

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?

Starfish
  • 2,716
  • 24
  • 28