The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
Need Script to check file exist and compare rbknisely UNIX for Dummies Questions & Answers 1 01-16-2008 01:08 AM
How to check a file exist and do a copy of other files ahjiefreak Shell Programming and Scripting 6 12-20-2007 12:07 AM
Have a shell script check for a file to exist before processing another file heprox Shell Programming and Scripting 3 11-14-2006 03:26 AM
how to check if directory/file exist using c/c++ steven88 High Level Programming 2 01-03-2006 02:55 AM
how to check if directory/file exist using c/c++ steven88 Shell Programming and Scripting 1 01-02-2006 10:45 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-27-2002
gusla gusla is offline
Registered User
  
 

Join Date: Feb 2002
Posts: 31
Unhappy how to check if the file exist or not?

say i would like to check if the file is existed before i use rm command. How can i do it?

i know if i can use find, but i would like to have a good interface (in a shell script)



thks
  #2 (permalink)  
Old 03-27-2002
LivinFree's Avatar
LivinFree LivinFree is offline Forum Advisor  
Goober Extraordinaire
  
 

Join Date: Jul 2001
Location: Portland, OR, USA
Posts: 1,584
See the man page for test.

if [ -s $file_name ]; then
echo Yay
else
echo Boo
fi

That will Yay if the file exists, and has a size greater than zero, and Boo if the file does not exist, or has a 0 length.
  #3 (permalink)  
Old 03-27-2002
krylin krylin is offline
Registered User
  
 

Join Date: Mar 2002
Location: Germany
Posts: 4
You should try the following code:

test -e $file_name && echo "file exists"
  #4 (permalink)  
Old 03-27-2002
gusla gusla is offline
Registered User
  
 

Join Date: Feb 2002
Posts: 31
thk

u both
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 On




All times are GMT -4. The time now is 11:20 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-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0