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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Checking Multiple File existance in a UNIX folder(Note: File names are all different)
# 1  
Old 09-24-2014
Wrench 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
# 2  
Old 09-24-2014
It is easy to see what files are there. You then need to walk through the list and see which file wasn't found.
Code:
echo `ls . | egrep "listener.ora|sqlnet.ora|tnsnames.ora|missingfile.txt"`



Moderator's Comments:
Mod Comment Please use code tags next time for your code and data. Thanks

Last edited by vbe; 09-24-2014 at 10:11 AM.. Reason: code tags!!
This User Gave Thanks to gandolf989 For This Post:
# 3  
Old 09-24-2014
If you have those filenames in a file a simple grep can do what you want. For example:
Code:
$ 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.
This User Gave Thanks to cero For This Post:
# 4  
Old 09-24-2014
Thanks!!

Thanks a lot Cero and gandolf989. It helps! Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Checking of file exist in different folder

Hi All, Seeking for your assistance to compare if the file in working directory is found on the DIR2 directory and if not found move the file in DIR2. ex. WORKING_DIR=/home/dir1/ file1.txt DIR2=/home/admin/users file1.txt what i did was found_nonempty='' for file in... (4 Replies)
Discussion started by: znesotomayor
4 Replies

2. Shell Programming and Scripting

Remove trailing space from file and folder names

I have a folder that contains many sub folders and files. This tree has to be backed up to an archive system. According to the tech support, one of the archives is failing to back up due to the possibility of trailing spaces on file and folder names. Therefore, I would like to have a script... (16 Replies)
Discussion started by: vipertech
16 Replies

3. Shell Programming and Scripting

Awk: File Checking Issues with 9 multiple file

Hi, I have 9 files which are generated dynamically & if there is a some condition which doesn't meet the criteria then file is not created or is of zero size. so further i am unable to consolidate the files based on following code 1 awk -F, -v ptime="201407" 'FNR==1... (3 Replies)
Discussion started by: siramitsharma
3 Replies

4. Shell Programming and Scripting

Renaming File Names in a folder/Dir

Hi Team, I'm new to Unix shell scripting . I've the following requirement A folder contains the list of files with the following format ab.name.11.first ab.name.12.second ab.name.13.third ---------- I have to rename the above file to like below ... (6 Replies)
Discussion started by: smile689
6 Replies

5. Shell Programming and Scripting

Error while checking file existance

Kindly help on below script: << i='find ...' if then echo 'File Exists' else echo 'File Does Not Exist' >> If i has some file name then it runs properly but if i has nothing ( blank value) then it throws an error. I dont exactly remember right now but error seems like:... (2 Replies)
Discussion started by: ravigupta2u
2 Replies

6. Shell Programming and Scripting

Checking the existance of multiple files

I am trying to execute the following command to check the existance of a file (which has a date timestamp on it). If there are more than one file, then also it should give me 'success' result. if then <do some work> else <no files> fi Since there are more than one... (18 Replies)
Discussion started by: vivek_damodaran
18 Replies

7. Shell Programming and Scripting

The checking of folder existance is not working...

Hi all, I have the following code: if ; then echo 'folder not exist'; else echo 'folder exist'; fi The "testing" folder is not exist in /home/batch , but thhe result is 'folder exist'. It seems that the code cannot detect that the folder "testing" not exist. ANybody know the... (1 Reply)
Discussion started by: suigion
1 Replies

8. UNIX for Dummies Questions & Answers

Checking file existance by extension

I'm sure this can't be too tough, but. I want to check the existance of file(s) by extension. There may be 0,1,N files. If any files exist, then remove them. Thanks for any insight. (3 Replies)
Discussion started by: niswonp
3 Replies

9. Shell Programming and Scripting

Multiple file existence and checking file size

I want to check the files in particular directory are more that 0 Bytes i.e, Non zero byte file. The script should print a msg if all the files in that directory are empty( 0 Byte). (2 Replies)
Discussion started by: lathish
2 Replies

10. UNIX for Dummies Questions & Answers

Getting all file names in a folder.

Hi All, I need help to create a shell script that does following: - do ls -1 and let all file names in the current folder - do wc for each file and if wc > 0 then send a mail. I am new to unix and do not know how to get filename one by one in a loop, so that wc can be done. I have done rest... (5 Replies)
Discussion started by: adadevil
5 Replies
Login or Register to Ask a Question