check file already exists, other options - shell
by rajesh[ Edit ] 2008-08-08 12:44:06
these are the arguments that can be used while shell scripting
example:
if [ -d name ]
#to check whether given path or string is a directory
-e
file exists
-f
file is a regular file (not a directory or device file)
-s
file is not of size
-d
file is a directory
-b
file is a block device (floppy, cdrom, etc.)
-c
file is a character device (keyboard, modem, sound card, etc.)
-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)
-g
set-group-id (sgid) flag set on file or directory
-u
set-user-id (suid) flag set on file
-k
sticky bit set
-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 condition.
Shell Scripting - File Handling Options