Determine whether the shell file directory or file exists

1, the file descriptor

- E determines whether the object exists
 - D determines whether the object is present, and is a directory
 - F determines whether the object is present, and is a regular file
 - L is determined whether the object is present, and is a symbolic link
 - H determines whether the object is present, and is a soft link
 - s is determined whether the object exists, and the length is not 0
 - R & lt determines whether the object exists and is readable
 - W determines whether the object exists, and is writable
 - X determines whether the object exists, and may perform
 - O determines whether the object exists, and belong to The current user
 - G determines whether the object exists, and the group belonging to the current user
 if the determination -nt file1 than file2 [ " / Data / file1 " -nt " / Data / file2 " ]
 -ot determines whether file1 file2 older than [ " / Data / file1 " -ot " / Data / file2 " ]

2, Example

Whether there is a directory of the current directory jar

if [ -d "jar" ];
then 
    echo "yes"
else
    echo "no"
fi

Whether there is a file in the current directory jar.sh

if [ ! -f "jar.sh" ];
then
    echo "yes"
else
    echo "no"
fi

NOTES:

[! -F "jar.sh"] before and after the [] syntax requires spaces, otherwise it will error

Guess you like

Origin www.cnblogs.com/kingsonfu/p/11457047.html