0
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?

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

1 Answer 1

1

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .