The test
command (written as [
here) has a “not” logical operator, !
(exclamation mark):
if [ ! -f /tmp/foo.txt ]; then
echo "File not found!"
fi
More Related Contents:
- How do I tell if a regular file does not exist in Bash?
- How do I split a string on a delimiter in Bash?
- Correct Bash and shell script variable capitalization
- How do I compare two string variables in an ‘if’ statement in Bash? [duplicate]
- How to manually expand a special variable (ex: ~ tilde) in bash
- How to urlencode data for curl command?
- How to execute a bash command stored as a string with quotes and asterisk [duplicate]
- Delete all but the most recent X files in bash
- Find and Replace Inside a Text File from a Bash Command
- Error handling in Bash [closed]
- Random number from a range in a Bash Script
- Recursively rename files using find and sed
- How can I remove the first line of a text file using bash/sed script?
- How to get the part of a file after the first line that matches a regular expression
- How can I set the current working directory to the directory of the script in Bash?
- Deleting lines from one file which are in another file
- Shell/Bash shortcut for bulk renaming of files in a folder
- Passing arguments by reference
- How to use a bash script variable with sed [duplicate]
- Best way to simulate “group by” from bash?
- Why equal to operator does not work if it is not surrounded by space?
- Determine if a function exists in bash
- How to check the extension of a filename in a bash script?
- Reading input files by line using read command in shell scripting skips last line
- Extract version number from a string
- How to tell if a string is not defined in a Bash shell script
- find difference between two text files with one item per line [duplicate]
- Is there a way to avoid positional arguments in bash?
- Show Hexadecimal Numbers Of a File
- What does `kill -0 $pid` in a shell script do?