These are the options to
be used in conditional statement to check file attributes.
file exists
example:
if [ -b "$filename" ]
then
echo "$filename exist."
fi
-a
file exists
This is same in effect to –e, but now it is
discouraged to use.
file is a regular file (not a
directory or device file)
-s
file is not zero size
-d
file is a directory
-b
file is a “block device”
-p
file is a “pipe”
-h
file is a “symbolic link”
-L
file is a symbolic link
-S
file is a “socket”
-r
file has read permission (for the user
running the test)
-w
file has write permission (for the user running
the test)
-x
file has execute permission (for the user
running the test)
-k
sticky bit set
Commonly known as the sticky bit, the save-text-mode flag
is a special type of file permission. If a file has this flag set, that file
will be kept in cache memory, for quicker access.
-O
you are owner of file
-G
group-id of file same as yours
-N
file modified since it was last read
f1 -nt f2
file f1 is newer than f2
f1 -ot f2
file f1 is older than f2
f1 -ef f2
files f1 and f2 are hard links to
the same file
!
"not" -- reverses the sense of
the tests above (returns true if condition absent).
No comments:
Post a Comment