linux: find files from a list in txt, the files contain spaces
10,933
Solution 1
#!/bin/bash
while read -r FILE
do
FOUND="$(find . -name "$FILE" -print -quit)"
if [ "x$FOUND" != "x" ]
then
echo "FOUND: $FILE"
else
echo "NOT FOUND: $FILE"
fi
done <filelist.txt
Solution 2
This is harder than it seems
while read -r file
do
find . -name "$file"
done <txt
will find the files that exist and print the full path for them. Unfortunately find sets $?
to 0
(SUCCESS) even if the file is not found.
Related videos on Youtube
Author by
Vamsi M
I'm a systems administrator with advance knowledge in IT security.
Updated on September 18, 2022Comments
-
Vamsi M almost 2 years
I need to find files from a list in txt (i already have the txt with all the files, are separated with lines), the files contain spaces and the extension of the files are pdf, if you can suggest how to make an output of the command or script to another txt file.
What I try (this one retrieve all the files in the directory and contain spaces, but only the existing ones, i need to find the non existing too):
find . -type f -name *.pdf
Thank's in advance for any help.
-
Florin Asăvoaie about 10 yearsYou need to find non existing files?
-
Vamsi M about 10 yearsHi Florin, i need to find existing and non existing files, thanks for your comment.
-
Florin Asăvoaie about 10 yearsHow can you find a file that does not exist?
-
Vamsi M about 10 yearsI want the log of the command or script to say that the file doesn't exist
-
-
Vamsi M about 10 yearsIts correct I have the list of files and some of those are not yet present, i need to report which of those are there, and which not.
-
Vamsi M about 10 yearsI will give a try to what you post, thanks for your help.
-
Nicolaie about 10 yearsA bit of explanation regarding my answer: ALIST and BLISt are arrays. And comm -3 shows differences of the two contained in the second expression.