Printable Version of Topic

Click here to view this topic in its original format

Linuxhelp _ Programming in Linux _ find command in loop routine - Need Help

Posted by: JClav Feb 2 2017, 04:42 AM


I've been trying to use find in a loop routine to get the path/filenames from a text file containing only filenames.
The text file has multiple filenames which correspond to files in various directories.

I can run a find / -name command on a single value but when I put it in a loop to iterate through all the filenames in a list I cannot get find to output the path/filename into a variable or another text file list.

This is the code I use:

while read xFile; do
echo $xFile
xFl=$(find / -name $xFile)
echo $xFl
done < filelist.txt

The result is that find stores a blank in the xFl variable which would mean that I would only be appending blanks to another text file list.

I need help on this and would appreciate advice and recommendations.


Posted by: michaelk Feb 2 2017, 08:28 AM

filelist.txt contents:

while read xFile; do
echo $xFile
find / -name "$xFile" 2> /dev/null >> /output/file.txt
done < filelist.txt

Without the >> the output file will be overwritten on each iteration of the loop.

Powered by Invision Power Board (
© Invision Power Services (