Microwave Biscuit

Bash Script to check for a file

Posted in Linux, ubuntu by microwavebiscuit on February 26, 2007

Occasionally I need to find out if a file DOES exist and/or a file DOESN’T exist.

Here are a couple of snippets to do just that:


if [ ! -f filename] ; #File that you are looking for isn't there
do stuff
fi

And the opposite:

if [ -e filename]; #File is there
do stuff
fi

Using code like this can help determine if there an error file was generated during a process or if you are expecting a file to be there that isn’t.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: