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



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
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Rate Thread 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
Sponsored Links
  #2 (permalink)  
Old 02-02-2006
Registered User
 

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

if [ -f file_name ]
then
# File Exists
else
# File does not exist
fi
  #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!
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


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 04:47 AM
checking file existence DILEEP410 Shell Programming and Scripting 3 01-24-2007 12:43 PM
File existence problem anormal UNIX for Dummies Questions & Answers 2 05-15-2006 01:54 PM
File existence mpang_ Shell Programming and Scripting 2 03-27-2006 12:27 PM
Searching for the existence of a file sbhan UNIX for Advanced & Expert Users 2 10-14-2002 05:02 PM



All times are GMT -4. The time now is 12:44 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2010. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0