Check If a File or Directory Exist using Bash. How?

In Bash scripts is very common to check if a file or a directory exist.

How do you check if a file or a directory exists using Bash?

In Linux everything is a file. You can use the test command followed by the operator -f to test if a file exists and if it’s a regular file. In the same way the test command followed by the operator -d allows to test if

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Claudio Sabato

Claudio Sabato

141 Followers

I’m a Tech Lead, Software Engineer and Programming Coach. I want to help you in your journey to become a Super Developer!