Tests for existence of files/directories


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Tests for existence of files/directories
# 1  
Old 11-05-2008
Tests for existence of files/directories

Hi,

- The first question I have concerns a very fundamental aspect of a unix OS. Specifically, does unix treat everything as a file (ie a directory is just a type of file)?

- The reason I ask is that I am trying to determine which BASH unary operator I would to use to determine whether or not a directory exists. I am writing a BASH shell script where the user defines a directory in which data files will be placed. I would then like to check that the specified directory exists, and if not the script will error.

I am inclined to use the -d operator (file is a directory). Does this have an implicit test for existence?

The other choice I can think of is the -e operator (file exists). This would assume that unix treats directories as files.

I appreciate any help. Thank you.

Mike
# 2  
Old 11-05-2008
Yes everything is a file. files have "magic" words at the beginning that identifies what the file is.

The -d test is just fine to determine the existence of a directory. After all, some user could have created a regular file by the same name.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Archiving and moving files into directories, creating directories, etc.

how can i move "dataName".sql.gz into a folder called 'database' and then move "$fileName".tar.gz * .htaccess into a folder called 'www' with the entire gzipped file being "$fileName".tar.gz? Is this doable or overly complex. so mydemo--2015-03-23-1500.tar.gz > database -... (5 Replies)
Discussion started by: wyclef
5 Replies

2. Shell Programming and Scripting

Check the Files existence

Hi I have a requirement to check whether the files exists, then it will call other steps in shell script. I did ls *.csv|wc -l if then checking the count of the files should be more than 1 then it will call other steps. I am getting the error that too many arguements as there n... (13 Replies)
Discussion started by: cnrj
13 Replies

3. Shell Programming and Scripting

Check for the existence and add them from 2 different files

Hi, I have two files file1: ALEX DANY GARY TOM MARY HARRIS file2: ALEX 3 ALEX 5 ALEX 0 ALEX 1 ALEX 0 DANY 2 (2 Replies)
Discussion started by: Diya123
2 Replies

4. Shell Programming and Scripting

How to list all the files, directories and sub-directories in the current path except one directory?

Can anyone come up with a unix command that lists all the files, directories and sub-directories in the current directory except a folder called log.? Thank you in advance. (7 Replies)
Discussion started by: Manjunath B
7 Replies

5. Shell Programming and Scripting

test for existence of files with same extension

Hi, I am checking for existence of files with the same extensions #! /usr/bin/ksh txtfiles = '*.txt' if then cp ${dirpath}/${txtfiles} ${dir2path} fi I am getting the following error line 5: [: too many arguments for the if check condition (4 Replies)
Discussion started by: chen.sara
4 Replies

6. UNIX for Dummies Questions & Answers

List directories and sub directories recursively excluding files

Hi, Please help me, how to get all the direcotries, its sub directories and its sub directories recursively, need to exclude all the files in the process. I wanted to disply using a unix command all the directories recursively excluding files. I tried 'ls -FR' but that display files as... (3 Replies)
Discussion started by: pointers
3 Replies

7. Shell Programming and Scripting

Test for existence of files

Hello, Can you please help me to see if log files exist in a directory? I need to scan logs in different directories, so I am using an array to change dynamically. I need help in the if test statement dir=/logs/MSD dir=/logs/UPD countA=1 while (( countA <= ${#dir } )) do cd ${dir}... (1 Reply)
Discussion started by: drbiloukos
1 Replies

8. Shell Programming and Scripting

verifying existence of multiple files

Hi, I have unix script on solaris 5.10. I have to verify existence of 3 files in path and sleep for 1 hour. I have tried for 1 file: if then echo " File is found!" sleep 3600 echo "time delayed" fi Please advice (6 Replies)
Discussion started by: ammu
6 Replies

9. Shell Programming and Scripting

check for FILES existence

hi, I have a list of filenames and I want to verify if they all exist. I know "if filename" would do the trick but how do I go about a list of files? thanks (3 Replies)
Discussion started by: mpang_
3 Replies
Login or Register to Ask a Question