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

And the opposite:

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

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.

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: