Bash command line file exists if condition

Check if File Exists Using if Condition in Bash

This article introduces how to check if a file exists using an if condition in the Bash command line of Linux computers and servers.

Shou Arisaka
1 min read
Oct 21, 2025

This article introduces how to check if a file exists using an if condition in the Bash command line of Linux computers and servers.

if [ ! -f file.md ]
then
echo "Not existing."
fi

Check if File Exists Using if Condition

if [ -f file.md ]
then
echo "Existing."
fi

Check if Multiple Files Exist Using if Condition

if [ -f file1.md ] && [ -f file2.md ]
then
echo "Existing."
fi

Summary

We introduced how to check if a file exists using an if condition in the command line. There are many scenes where file if checks are performed, so it’s convenient to remember.

For example, you can perform processing like creating a file if it doesn’t exist. Or you could also perform processing like deleting a file if it exists.

That’s all.

Share this article

Shou Arisaka Oct 21, 2025

🔗 Copy Links