using the mpc search command I can find a the filename of a song like so:

mpc search title 'Two Weeks'

The output would look like this: Grizzly Bear - Two Weeks.mp3

Since I also know the location of the mp3 (MPD Music directory), I know how I could delete the file with another command. But I want to have a one-line command that finds and deletes a music file in my MPD directory.

  • perhaps something as simple as: rm "/path/to/MPD/Music/directory/$(mpc search title 'Two Weeks')" ? – Jeff Schaller Mar 1 '16 at 18:59
  • this could be a little tricky. how would you handle more than 1 results? Would you be willing to delete all the returned results? – nass Mar 1 '16 at 19:00
  • @nass There is also a mpc command called "mpc find", it returns only one result, and only when you query result matches exactly with what you searched for. As I already know a parameter for each item I would search for, I would probably use that command. Although if I want to delete multiple items that, for example are in the same album, I'd have to use mpc search. But yes I would have to be careful with that. – F. Untermoser Mar 1 '16 at 20:20
  • @JeffSchaller Yess thank you, that did it. – F. Untermoser Mar 1 '16 at 20:21

On the assumption that only one filename comes back, you can use something like:

rm "/path/to/MPD/Music/directory/$(mpc search title 'Two Weeks')"

If there are multiple results, this will break.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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