Monday, May 6, 2024
 Popular · Latest · Hot · Upcoming
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 686  / 2 Years ago, sat, may 7, 2022, 7:11:39

Background: I am trying to find music files that are mentioned in an xml file to organize my music playlists. I'm writing a script to pull out the filenames from the xml tag to automatically find the files.


My music lives in $musicroot, so I'm issuing find there. But I can't find the following file because of the [] characters.


find $musicroot -name "R. Kelly - Step In The Name Of Love [mp3clan.com].mp3" -type f

returns nothing, but if I escape the [] then it works.


find $musicroot -name "R. Kelly - Step In The Name Of Love [mp3clan.com].mp3" -type f
/mnt/Data/Dynamic/Multimedia/Music/Not Desi/Party/R. Kelly - Step In The Name Of Love [mp3clan.com].mp3

Note that in my script, the song file is iterated over in a loop of songs and exists in a variable $song. Not sure if that makes a difference.


I'd really like to be able to just pass in the filenames into find in my scripts without having to worry about escaping characters like this, but I can't seem to find anything on this online. Probably because it's hard to search for find as find is such a common English word.


Is this possible?


More From » bash

 Answers
6

grep has a --fixed-strings option that does what you want and you can use it with find:


find $musicroot -type f | grep --fixed-strings "R. Kelly - Step In The Name Of Love [mp3clan.com].mp3"

[#124] Sunday, May 8, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
wenceslockro

Total Points: 494
Total Questions: 127
Total Answers: 97

Location: Chad
Member since Mon, Dec 5, 2022
1 Year ago
wenceslockro questions
Sat, May 22, 21, 03:26, 3 Years ago
Mon, Nov 22, 21, 10:31, 3 Years ago
Tue, May 16, 23, 02:58, 1 Year ago
;