'OpenSuse Linux Find a File by a String Inside the Filename

In Linux OpenSuse I want to search for a file with a string of characters inside the filename

The path where it should search: /var/spool/asterisk/monitorDONE

Under monitorDONE there are subfolders (MP3, OGG, ORIG, GSM, FTP ...), so the file is located under one of these folders but not sure which one

The filetype is not defined as it may be .mp3 .wav .gsm or any other audio file

The file name is as this 00000000-000000_7857565221_0000.xxx

Zeros are any digits and xxx are letters

Now how should the command be? I found some examples of find command on the internet but this is so specific in this case, can anybody complete this command to meet the search criteria?

find -type f /var/spool/asterisk/monitorDONE

Thanks



Solution 1:[1]

find /var/spool/asterisk/monitor -type f -name '*-*_*_*.*' -print | \
  grep -E '[[:digit:]]+-[[:digit:]]+_[[:digit:]]+_[[:digit:]]+.[[:alpha:]]+' | xargs fgrep -l DONE

Find is somewhat limited in the wildcards it supports so we pipe the output through grep to look for exact filename matches. If the number of digits is constant then replace "+" with "{x}" where x is the number of digits. After filtering through grep, the list of files is then dumped as parameters to fgrep which output the name of any file that contains the string DONE. grep could be used instead of fgrep, but fgrep is faster unless regular expressions are needed. For example, if the number of digits is always the same, replace [[:digit:]]+ with [[:digit:]]{8} if it is always 8 numbers. [[:digit:]] is the equivalent of [0-9].

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Aaron Williams