SHELL determines whether the file directory or file exists

1, file descriptor

-e Determine whether the object exists

-d Determine whether the object exists and is a directory
-f Determine whether the object exists, and it is a regular file
-L Determine whether the object exists and is a symbolic link
-h Determine whether the object exists and is a soft link
-s Determine whether the object exists and the length is not 0
-r Determine whether the object exists and is readable
-w Determine whether the object exists and can be written
-x Determine whether the object exists and is executable
-O Determine whether the object exists and belongs to the current user
-G Determine whether the object exists and belongs to the current user group
-nt Determine whether file1 is newer than file2 ["/data/file1 " -nt "/data/file2"]
-ot Determine whether file1 is older than file2 ["/data/file1 " -ot "/data/file2" ]

2, example

Current Does the directory jar exist under the directory

if [-d "jar" ];

then
echo " yes"
else
echo " no"
fi

Does the file jar.sh exist in the current directory

if [! -f "jar.sh" ];

then
echo " yes"
else
echo " no"
fi

Note:

[! -f “jar.sh” ]’S [] requires spaces before and after the syntax, otherwise an error will be reported

-e Determine whether the object exists

-d Determine whether the object exists and is a directory
-f Determine whether the object exists, and it is a regular file
-L Determine whether the object exists and is a symbolic link
-h Determine whether the object exists and is a soft link
-s Determine whether the object exists and the length is not 0
-r Determine whether the object exists and is readable
-w Determine whether the object exists and can be written
-x Determine whether the object exists and is executable
-O Determine whether the object exists and belongs to the current user
-G Determine whether the object exists and belongs to the current user group
-nt Determine whether file1 is newer than file2 ["/data/file1 " -nt "/data/file2"]
-ot Determine whether file1 is older than file2 ["/data/file1 " -ot "/data/file2" ]

if [-d "jar" ];

then
echo " yes"
else
echo " no"
fi

if [! -f "jar.sh" ];

then
echo " yes"
else
echo " no"
fi

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 5515 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.