[ … ] or test is the command used to test information about files.
e.g.:
$ [ -f file ] # true if file is an ordinary file $ [ ! -f file ] # true if file is NOT an ordinary file $ [ -d file ] # true if file is a directory $ [ -u file ] # true if file has SUID permission $ [ -g file ] # true if file has SGID permission $ [ -x file ] # true if file exists and is executable $ [ -r file ] # true if file exists and is readable $ [ -w file ] # true if file exists and is writeable $ [ file1 -nt file2 ] # true if file1 is newer than file2
Important Notes:
– Use spaces after the ‘[‘ and before the ‘]’.
– Use spaces around operators.