Notes

File Test Operators

Edit on GitHub

Bash Scripting

File Test Operators

Returns true if

  • -e and -a file exists
  • -s file is not zero size i.e. not empty
  • -f file is a regular file i.e. not a directory
  • -d file is a directory
  • -h and -L file is a sympbolic link

Check if a file exists

1if (-e foo.txt ); then
2    echo "foo.txt already exists!"
3else
4    // Do something
5fi