The UNIX and Linux Forums  

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


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 !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Checking the existence of a file.. igandu Shell Programming and Scripting 7 06-13-2007 12:47 AM
checking file existence DILEEP410 Shell Programming and Scripting 3 01-24-2007 08:43 AM
File existence problem anormal UNIX for Dummies Questions & Answers 2 05-15-2006 09:54 AM
File existence mpang_ Shell Programming and Scripting 2 03-27-2006 08:27 AM
Searching for the existence of a file sbhan UNIX for Advanced & Expert Users 2 10-14-2002 01:02 PM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-02-2006
Registered User
 

Join Date: Aug 2005
Location: Pittsburgh, PA
Posts: 25
Question Loop for file existence

I wasn't sure if I should post it here of in the Shell Script category, but I figured it was definitely a newbie question.

I'm trying to write a script that will check for the existence of a specific file (or for any files within the directory) and then take specific actions. I've removed all the extra processing in the loop, comments, and variables. I'm just trying to get my basic loop to work.

I did check the FAQ's but I think this is even too basic a question for there. Anyone's assistance with this would be appreciated.


#!/bin/sh

if (test.dat exists in current directory)
then
echo "test.dat exists!" |mail noone@domain.com
else
echo "test.dat does not exist!" |mail noone@domain.com
fi
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 02-02-2006
Registered User
 

Join Date: Sep 2004
Location: Mumbai-India
Posts: 151
Use the following if

if [ -f file_name ]
then
# File Exists
else
# File does not exist
fi
Reply With Quote
  #3 (permalink)  
Old 02-02-2006
Registered User
 

Join Date: Aug 2005
Location: Pittsburgh, PA
Posts: 25
What does the -f mean before the filename? I did receive and proper response e-mail when I used this. I also just tried "ls filename" and had the same result.

If I were to look for the existence of any file in that directory, would I just replace the filename with * ?


Thanks again!
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 12:30 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0