Languages
[Edit]
EN

Bash - check if file exists

5 points
Created by:
Pearl-Hurley
559

In this short article we would like to show how to check if file exists using Bash and test command.

Simple solution:

#!/bin/bash

if [ -e "path/to/my/file/or/directory" ]
then
	echo "File exists";
fi

Alternative solution

#!/bin/bash

if test -e "path/to/my/file/or/directory"
then
	echo "File exists";
fi

 

Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Bash

Bash - check if file exists
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join