Skip to content
Advertisement

find command not printing files with .wav extension as specified

I’ve tried using this command to recursively search a folder and print .wav files, showing only the file names (not the location):

find /location/Master_Folder/ -type f -printf "%fn" -iname *.wav > Wav_files.txt

I’ve also tried putting .wav in double quotes like so:

find /location/Master_Folder/ -type f -printf "%fn" -iname "*.wav" > Wav_files.txt

When I check the Wav_files.txt file there are also .xml files listed. I only intend to print the .wav files- What have I done wrong?

Advertisement

Answer

find /location/Master_Folder/ -type f -iname '*.wav' -printf "%fn"  > Wav_files.txt

Put the conditions (-type and -iname) before the actions (-printf). find evaluates generally left to right, so the -printf happened before the -iname was checked in your original command lines.

Also, I tend to use single quotes '' around patterns in find just so I don’t surprise myself if I ever search for a filename containing a $ (which would cause expansion within ""). 🙂

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement