-x—Determines whether execute permission is set for a file
-z—Determines whether the file size is zero
The following examples are based on a shell program called compare3,
which is in a directory with a file called file1 and a subdirectory dir1
under the current directory. Assume that file1 has a permission of r-x
(read and execute permission), and dir1 has a permission of rwx (read,
write, and execute permission).
The following is the code for the compare3 shell program:
Click here to view code image
#!/bin/tcsh
if (-d dir1) then
echo "dir1 is a directory"
else
echo "dir1 is not a directory"
endif
if (-f dir1) then
echo "file1 is a regular file"
else
echo "file1 is not a regular file"
endif
if (-r file1) then
echo "file1 has read permission"
else
echo "file1 does not have read permission"
endif
if (-w file1) then
echo "file1 has write permission"
else
echo "file1 does not have write permission"
endif
if (-x dir1) then
echo "dir1 has execute permission"
else
echo "dir1 does not have execute permission"
endif
if (-z file1) then
echo "file1 has zero length"
else
echo "file1 has greater than zero length"
endif