Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I ran across this post: How can I retain the console input in mplayer when reading from stdin?

But the answer there doesn't work for me.

I'm running the following command:

ls -l | grep -e mp3 -e wav | awk '{i=index($0,$9); $0=substr($0,i); printf "./"$0"\n"}' | grep " " | mplayer -playlist -

and this works fine. (minus controls)

I try this: (as proposed in the above question)

ls -l | grep -e mp3 -e wav | awk '{i=index($0,$9); $0=substr($0,i); printf "./"$0"\n"}' | grep " " | mplayer -playlist /dev/fd/3 3<&0 </dev/tty

and it gives me this:

Playing /dev/fd/./Pink Floyd - Another Brick in the Wall.mp3.
File not found: '/dev/fd/./Pink Floyd - Another Brick in the Wall.mp3'
Failed to open /dev/fd/./Pink Floyd - Another Brick in the Wall.mp3.

can someone explain what I am doing wrong (and how to fix it?)

Currently running ubuntu 12.10 using sh.

share|improve this question
up vote 2 down vote accepted

It's just that your file paths are relative, and mplayer seems to interpret that as relative to the playlist's location (and not your working directory or whatever). For a zeroth approximation, you can replace "./" with your current directory, but what I'd find easier is to use

find "$(pwd)"  -maxdepth 1 -name \*.mp3 -o -name \*.wav | mplayer -playlist /dev/fd/3 3<&0 0</dev/tty

(So your ls,grep,awk is replaced by this find. Admittedly, I've not double-checked completely if it is entirely equivalent. Removing the -maxdepth would make it recurse into subdirectories, which might be what you want anyway? man find is your friend here.)

share|improve this answer
Worked great for me. Was not aware of $(pwd) though, so thanks! It's a wonder how you learn something new about linux every day :P – Tyzoid Nov 9 '12 at 19:55

mplayer thinks relative paths in the playlist are relative to the directory where the playlist is. Try using absolute paths; change your awk script to something like

awk -v dir="$(pwd)" '{ ... ; printf dir "/" $0 "\n" }'
share|improve this answer
Thanks for the awk alternative. I think that using one "find" command would be more efficient than using a ls, grep, and awk combined (plus it gives for recursive searching). – Tyzoid Nov 9 '12 at 19:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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