Checking Multiple File existance in a UNIX folder(Note: File names are all different)

HI Guys,

I have some 8 files with different name and extensions. I need to check if they are present in a specific folder or not and also want that script to show me which all are not present. I can write if condition for each file but from a developer perspective , i feel that is not a good option. Please suggest some ideas on how to do it.

Your reply is appriciated : Thanks Shankar

It is easy to see what files are there. You then need to walk through the list and see which file wasn't found.

echo `ls . | egrep "listener.ora|sqlnet.ora|tnsnames.ora|missingfile.txt"`
1 Like

If you have those filenames in a file a simple grep can do what you want. For example:

$ cat f.txt
a
b
d
e
$ ls -1 folder
a
b
c
d
$ grep -v "^$(ls -1 folder)$" f.txt
e
$

File c is not present in the file and ignored. File e is missing in folder.

1 Like

Thanks a lot Cero and gandolf989. It helps! :wink: