O'Reilly logo

Linux and Unix Shell Programming by David Tansley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

17.1. Testing for a file status

There are two general formats of the test and you can use either:

test condition 

or

[ condition ] 

Please note the use of a space each side of the condition when using square brackets.

The conditions to which you can test the file’s status are quite long, but Table 17.1 lists the most common ones.

Table 17.1. File status tests
-d This is a directory
-f This is a regular file
-L This is a symbolic link
-r This file is readable
-s This file has a size greater than zero, not empty
-w This file is writeable
-u This file has the suid bit set
-x This is executable

We will use both test methods to test if the file scores.txt is writeable. We will use the last status command to test it. Remember a zero status is OK, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required