Home > Operation and Maintenance > Linux Operation and Maintenance > Determine whether the file exists in linux

Determine whether the file exists in linux

(*-*)浩
Release: 2019-11-08 09:22:51
Original
4015 people have browsed it

Determine whether the file exists in linux

#In Linux shell, -f is generally used to determine whether the file exists; -d is used to determine the directory.

[[ -f 文件名 ]] && echo yes
Copy after login

If yes is printed, it means that the file can be detected by the current user        (Recommended learning: linux operation and maintenance)

-e filename 如果 filename存在,则为真
-d filename 如果 filename为目录,则为真
-f filename 如果 filename为常规文件,则为真
-L filename 如果 filename为符号链接,则为真
-r filename 如果 filename可读,则为真
-w filename 如果 filename可写,则为真
-x filename 如果 filename可执行,则为真
-s filename 如果文件长度不为0,则为真
-h filename 如果文件是软链接,则为真
Copy after login

Common examples

If a file exists, delete it

if [ -f trials ]; then rm ${result_path}trials; fi
Copy after login

If there is no folder, create it

if [ ! -d $result_name ];then
      mkdir -p $result_name
fi
Copy after login

The above is the detailed content of Determine whether the file exists in linux. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template