Tuesday, March 07, 2006

unix tip: file test operators

i always keep forgetting these file test operators, so i decided to paste it here for my future reference :)
-r file check if file is readable.
-w file check if file is writable.
-x file check if we have execute access to file.
-f file check if file is an ordinary file (as opposed to a
directory, a device special file, etc.)
-s file check if file has size greater than 0.
-d file check if file is a directory.
-e file check if file exists. Is true even if file is a
directory.

example:
if [ -s file ]
then
such and such
fi

for more info, go here http://www.tldp.org/LDP/abs/html/fto.html

1 comment:

Vijay Bhaskar said...

Thanks for posting the useful test operators. For more file test operators check the following link:
file test operators in unix bash script