Bash: Check if file exists
26 July 2024 (Updated 18 May 2025)
Check if file exists:
if [ -f /tmp/foo.txt ]; then
echo "File found!"
fi
Check if file doesn’t exist:
if [ ! -f /tmp/foo.txt ]; then
echo "File not found!"
fi
Tagged:
Bash