Languages
[Edit]
EN

Bash - check if file exists

5 points
Created by:
AnnLen
12070

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

 

Bash

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