Testing existence of a file /directory


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Testing existence of a file /directory
# 1  
Old 03-09-2006
Testing existence of a file /directory

hey guys
How can i test existence of a file /directory in a directory in a script

thanks
# 2  
Old 03-09-2006
Quote:
Originally Posted by ajaya
hey guys
How can i test existence of a file /directory in a directory in a script
Look into man test.

Code:
if [ -f /home/user/.bashrc ] ; then
  echo "File exists"
else
  echo "File does not exist"
fi

# 3  
Old 03-17-2006
additionally u can test if it's a directory with -d option

if [ -d /home/user/tstdir ]
then
echo "tstdir exists"
else
echo "tstdir doesn't exist"
fi
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to check the files existence inside a directory.

Hello Folks, On Below Script, I want to apply condition. Condition that it check the directory for files if not found keep checking. Once directory have files and founded do the calculation and finish the code. Script to check the files existence inside a directory, If not then keep... (16 Replies)
Discussion started by: sadique.manzar
16 Replies

2. Shell Programming and Scripting

File existence

Hope someone can help me on this In a directory ,files are dynamically generated.I need a script to do the following if files are not received for more than 2 hours or if the received file is empty then do something How can I put that in a script.Thank you eg. in cd /dir_name the... (13 Replies)
Discussion started by: haadiya
13 Replies

3. UNIX for Dummies Questions & Answers

File and directory testing

original post -- I have a korn shell script that does some things that depend on creating and writing a file in a directory. I'm looking for a more elegant/efficient way to do the check than what I'm using now: if ] then print "Creating ${STGDIR}/${SHOW}" mkdir... (3 Replies)
Discussion started by: Dalej
3 Replies

4. Shell Programming and Scripting

PERL: testing directory on windows platform

Hi Gurus, kindly analyse the following for me, please OS: Windows 7 Code location: C:\ Output: "Program Files not being recognised" "System Volume Information is a directory" "Windows not being recognised" main { my @dirlist = <*>; foreach my $fn... (0 Replies)
Discussion started by: biglau
0 Replies

5. Shell Programming and Scripting

bash script for testing existence of files/folders and creating if neither exist

Hi, I am new to shell-scripting, and doing a lot of reading. I am having some trouble getting started with a simple testing of scripting. I have been experimenting with if, loops, for, test, etc., but still unsure. I seem to have the hang of it when it comes to creating a single file or... (6 Replies)
Discussion started by: me2
6 Replies

6. Shell Programming and Scripting

testing if a file is a directory

i have written this simple script called isdir.sh #! /bin/bash dir=$1 _ls=`ls $dir` for file in $_ls do if then echo "D $file" fi donethe output is not right. for example $ ./isdir.sh src ***no output*** but i have in ~/src some directories drwxr-xr-x 2... (5 Replies)
Discussion started by: and77
5 Replies

7. Shell Programming and Scripting

Facing problem in checking the directory existence

Hi All, I have a written a scell script which checks the existence of a directory. The dierctory name is read from property file. Though the dierctory exists but it says - it does not exist-- Find my code below -- #! /bin/ksh #Tibco Properties file is inclusion .... (5 Replies)
Discussion started by: supriyabv
5 Replies

8. Shell Programming and Scripting

shell :: check directory existence

Hi All, I have shell script and I need to check if some directory exist. I'm don't have the information if that directory is written in upper case or lowcase or mixed. Is there anyway to check the existence of that directory by ignoring case senestive? Thanks (3 Replies)
Discussion started by: Alalush
3 Replies

9. Shell Programming and Scripting

Syntax prob. Passing a directory to $1 and testing it.

I'm running this simple little test: #!/bin/sh if ; then echo $1 else echo "Usage:`basename $0` dir" fi echo "The end of the script." The idea is, to test if you have passed a dir to the script. The problem is, it seems to exit the if statement when $1 is null: ... (3 Replies)
Discussion started by: benjo
3 Replies

10. Shell Programming and Scripting

File existence using ls

Hi I want to check a particular file is available or not. But i know only the pattern of that file sat AB1234*.txt.I need the latest file name and it ll be used in the script. How can i do this using ls -ltr command. Thanks, LathishSundar V (2 Replies)
Discussion started by: lathish
2 Replies
Login or Register to Ask a Question