Pages

BASH file test operators

Here is a summary of BASH file test operators: 
The general form of a file test operation is -operator "filename"

Operator
Returns true if
-e
File exist
-f
It is a regular file
-d
File is not zero size
-s
File has a size greater than zero
-b
File is a block device
-c
File is a character device
-p
File is a pipe (FIFO)
-h
File is a symbolic link
-L
File is a symbolic link
-S
File is a socket
-t
File (descriptor) is associated with a terminal device
-r
File has read permissions (for current user)
-w
File has write permissions (for current user)
-x
File has execute permissions (for current user)
-g
set-group-id (sgid) flag is set on file or directory
-u
set-user-id (suid) flag is set on file
-k
sticky bit is set
-O
File is owned by the effective user id
-G
File is owned by the effective group id
-N
File modified since it was last read
f1 -nt f2
File f1 is newer than file f2
f1 -ot f2
File f1 is older than file f2
f1 -ef f2
Files f1 and f2 are hard links to the same file
!
"NOT" - returns true if condition is absent

Execute man bash for more information

No comments:

Post a Comment