if [[ -f file.txt ]]; then ... fi

Category: Bash Scripting

if [[ -f file.txt ]]; then ... fi

Check if a file exists and is a regular file

Checks if a file exists and is a regular file (not a directory or link). -f is the 'file exists' test.
Looking for more? Search all 7,657 commands — works offline, in English or Spanish, and fixes typos.