find ~ -iname "*.mp3"

I want to find all .mp3 files in my home directory and onwards.

Here are some of the results:

/home/koshy/Music/These Boots Are Made for Walkin Nancy Sinatra.mp3 /home/koshy/Music/alicia keys - Killing me softly (live at Showcase).mp3

Notice how the spaces in them are not escaped?

Once I have the files, I want to copy one or two of them to a new location. But then I was forced to manually change file name, which can be exceedingly tedious:

cp /home/koshy/Music/alicia\ keys\ -\ Killing\ me\ softly\ (live\ at\ Showcase).mp3 .

(Note how the spaces are now escaped)?

Surely there is a better way?

  • cp 'some file name.mp3' . or cp "file $name.mp3" . (remember to escape metacharacter and control operator too) – bac0n May 28 '20 at 5:50

Try this one:

$ find Downloads/ -iname "* *" -print0 | xargs -0 ls 
'Downloads/Cloud/Multi-Runtime Microservices Architecture.pdf'

$ cp 'Downloads/Cloud/Multi-Runtime Microservices Architecture.pdf' .

More ways to do it.

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.