Linux Help
guides forums blogs
Home Desktops Distributions ISO Images Logos Newbies Reviews Software Support & Resources Linuxhelp Wiki

Welcome Guest ( Log In | Register )

Advanced DNS Management
New ZoneEdit. New Managment.


Sign Up Now
> find command in loop routine - Need Help
post Feb 2 2017, 04:42 AM
Post #1

Whats this Lie-nix Thing?

Group: Members
Posts: 1
Joined: 2-February 17
Member No.: 19,228


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.

Go to the top of the page
+Quote Post
Start new topic
post Feb 2 2017, 08:28 AM
Post #2

Its GNU/

Group: Support Specialist
Posts: 1,807
Joined: 23-January 03
Member No.: 360

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.
Go to the top of the page
+Quote Post

Posts in this topic

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:


RSS Lo-Fi Version Time is now: 21st July 2018 - 02:38 PM