Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
You need to find non existing files? – Florin Asăvoaie Apr 23 '14 at 14:53
Hi Florin, i need to find existing and non existing files, thanks for your comment. – ravasquezgt Apr 23 '14 at 14:54
How can you find a file that does not exist? – Florin Asăvoaie Apr 23 '14 at 15:01
I want the log of the command or script to say that the file doesn't exist – ravasquezgt Apr 23 '14 at 17:00
up vote 1 down vote accepted
while read -r FILE
  FOUND="$(find . -name "$FILE" -print -quit)"
  if [ "x$FOUND" != "x" ]
    echo "FOUND: $FILE"
    echo "NOT FOUND: $FILE"
done <filelist.txt
share|improve this answer
Thanks works like a charm. – ravasquezgt Apr 23 '14 at 20:21

This is harder than it seems

while read -r file
    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.

share|improve this answer
I will give a try to what you post, thanks for your help. – ravasquezgt Apr 23 '14 at 17:59

May I try to understand your question.

You have a list that contains file names that your are searching for. And you want a list of files that are not yet present?

Is that correct?

So assuming TEST is the file containig your search-list then you might use this:

ALIST=$(cat TEST | sort);BLIST=$(ls -1 | sort);comm -3 <( echo "${ALIST[*]}" ) <( echo "${BLIST[*]}" )

cheers Nick

share|improve this answer
Its 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. – ravasquezgt Apr 23 '14 at 17:58
A bit of explanation regarding my answer: ALIST and BLISt are arrays. And comm -3 shows differences of the two contained in the second expression. – Nicolaie Apr 24 '14 at 16:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.