Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 08-10-2012
Registered User
 
Join Date: Nov 2011
Posts: 36
Thanks: 8
Thanked 1 Time in 1 Post
How to check if the same file exists multiple times?

Hi Team ,

Is there a way I can check to see if the same file say , test.dat exists multiple times in the directory path ?

Please help.

Thanks
Megha
Sponsored Links
    #2  
Old 08-10-2012
bartus11's Avatar
Registered User
 
Join Date: Apr 2009
Posts: 3,139
Thanks: 3
Thanked 954 Times in 933 Posts
Try:
Code:
find /directory -type f -name test.dat

Sponsored Links
    #3  
Old 08-10-2012
Registered User
 
Join Date: Nov 2011
Location: New Delhi
Posts: 42
Thanks: 4
Thanked 4 Times in 4 Posts

Code:
ls test.dat | wc -l

This will give you the count of occurances of the file.
If it returns zero then no file present.
    #4  
Old 08-10-2012
Mead Rotor
 
Join Date: Aug 2005
Location: Saskatchewan
Posts: 16,371
Thanks: 490
Thanked 2,534 Times in 2,417 Posts
That is useless because you can't have more than one file of the same name in the same folder. It will always be either zero, or one.
Sponsored Links
    #5  
Old 08-10-2012
Registered User
 
Join Date: Feb 2007
Posts: 84
Thanks: 3
Thanked 15 Times in 15 Posts
If you are looking for files with the same name and content then:

Code:
find . -type f -name test.dat -exec cksum {} +

Sponsored Links
    #6  
Old 08-10-2012
Registered User
 
Join Date: Nov 2011
Posts: 36
Thanks: 8
Thanked 1 Time in 1 Post
HiCorona688

I do agree with you but I am developing a script that handles exceptions like these just in case.

Thanks everyone.

Megha
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
File exists, but cannot be opened.How to check- whether it could be opened to read when it exists rxg Shell Programming and Scripting 2 05-10-2012 02:15 PM
Check to see if a file exists? buechler66 Shell Programming and Scripting 5 06-28-2011 10:38 PM
check a file is exists in multiple tar file? k_manimuthu Shell Programming and Scripting 7 03-03-2011 12:27 AM
Check if file exists + ulp :S ruben.rodrigues Programming 2 02-22-2010 02:28 AM
FTP check if file exists and log it gseyforth Shell Programming and Scripting 1 08-12-2009 03:40 AM



All times are GMT -4. The time now is 06:41 AM.