use the ouput from a textfile as input for find command
is there any way to use the output from a text file as the input for the find command?
something like cat list-of-files.txt | `find /data/* -name "list-of-files.txt"` |
Code:
for i in $(cat list-of-files); |
Thanks Ozan,
That kinda worked but kept running in an endless loop. Also it displayed a lot of irrelevant files. |
Well, maybe there's a cleaner way to go with xargs but xargs is all magic to me.
|
Yes I tried using xargs but like you say "It's all magic to me"
|
Running a find command for each file in a list sounds very expensive. Consider running find to produce a file of all files, and then use grep to search the files.
Code:
find /data/ -type f >full_list |
Can I rephrase my question? I'm not trying to read what's in the files. I'm trying to copy them. I want to do something like this.
cat list-of files-on-archive-server.txt | find files-on-archive-server.txt | cp files-on-archive-server to production-server. The find and copy part would be like this find . -iname "*filename*" -exec cp {} server/data/found_files \; But I cannot figure out how to use the output from cat as the input for find. Any help would be greatly appreciated. |
Actually this worked, at least a test on my laptop did.
for i in $(cat find-list.txt); do find /home/tim/Documents/ -name "$i" -exec cp {} -a /home/tim/Desktop \; done |
From your initial description, it sounded like you had a list of file names, but not the full pathnames. If the list also has their locations, you don't need to find them
One thing you might need to do is use the `tr' command to make it easier to handle white space and "evil" characters. Code:
cat filelist.txt | tr '\n' '\0' |xargs -0 mv -t /target/directory/ Look at the xargs options to limit how many arguments to handle at once. If your file list is too long you may get an out of memory error from bash. On more thing to consider is if you may find a file whose name begins with a dash. If that is possible, end the command with two dashes. |
All times are GMT -5. The time now is 07:02 AM. |