If you are looking for a bash command to check if file exists then you can try the below options,
Option 1: test command with if-then-else-fi
-
Example:
if test -f my-file.txt; then
echo "The file exists!"
else
echo "The file does not exist!"
fi
If you want to look at a specific path,
if test -f /path-to-file/my-file.txt; then
echo "The file exists!"
else
echo "The file does not exist!"
fi
Option 2: Using Square Brackets [ ] in one line
[ -f "data.csv" ] && echo "File exists." || echo "File does not exist."
Using [ -f "file-name.extention" ] we check if the file exists or not and accordingly echo the result. You can make it more short with -1 to indicate the file does not exists and 1 if it does.
[ -f "data.csv" ] && echo "1" || echo "-1"

-
Facing issues? Have Questions? Post them here! I am happy to answer!
More Posts related to Bash,
- Bash Hello World! Script Tutorial
- How to run bash command in background
- How to create new user account in Windows bash
- How to Compare Strings in Bash
- Bash: Allow Command to Fail without exiting Script
- Fix bash: script.sh: Permission denied Error
- Bash getopts Command Example
- How to fix bash ping command not found error
- How to add NewLine Character in Bash Script String
- How to Echo Bash Command to a File
- Bash Command to Find String in a File
- How to open new Terminal using Bash Command
- Bash How to Save Output of a Command to a Variable
- Download a SSL Certificate from a URL in Terminal
- Bash Command to Check IP Address
- Know Bash shell version command
- Bash Command To Check If File Exists
- How to run a Command in Bash Script
- How to Compare two Files in Bash Shell
- How to check if a variable is set in Bash Script or Not
- Convert String from uppercase to lowercase in Bash
- How to see Created Accessed Modified and Changed dates of a file using bash terminal command
- Bash Command To Get Current Time
- Bash command to List Files
- Fix: bash: syntax error near unexpected token
More Posts:
- Install Gradle VS Code for Java Projects - Gradle
- Fix - bash: man: command not found - Linux
- Tomcat Manager Default Username and Password - Tomcat
- Create Symbolic Link using Terminal Command - MacOS
- Create Duplicate Line Visual Studio Code (above or below) Example - HowTos
- Stop a Running Command on macOS Terminal - MacOS
- List of Code Snippets/Templates to Eclipse IDE - Eclipse
- Perform Basic Authentication using cURL with Examples - cURL