How to determine whether a folder or file exists in shell
How to judge the existence of folders or files in shell? in view of this problem, this article introduces the corresponding analysis and solutions in detail, hoping to help more partners who want to solve this problem to find a more simple and easy way.
Create if the folder does not exist
If [!-d "/ data/"]; thenmkdir / dataelseecho "folder already exists" fi
Delete if the file exists
If [!-f "/ data/filename"]; thenecho "File does not exist" elserm-f / data/filenamefi
Determine whether the folder exists
If [- d "/ data/"]; thenecho "folder exists" elseecho folder does not exist "fi"
Determine whether the file exists or not
If [- f "/ data/filename"]; thenecho "file exists" elseecho "file does not exist" fi
File comparator
-e determines the existence of the object-d determines the existence of the object, and judges the existence of the object for the directory-f, determines the existence of the object for the regular file-L, and judges the existence of the object for the symbolic link-h, and judges the existence of the object for the soft link-s, and determines the existence of the object for the length not 0murr, and determines whether the object exists for readable-w. And can write-x to determine whether the object exists, and executable-O to determine whether the object exists, and belongs to the current user-G to determine whether the object exists. And belongs to the current user group-nt to determine whether file1 is newer than file2 ["/ data/file1"-nt "/ data/file2"]-ot to determine whether file1 is older than file2 ["/ data/file1"-ot "/ data/file2"] this is the answer to the question about how to determine whether a folder or file exists in shell. I hope the above content can be helpful to you, if you still have a lot of questions unsolved. You can follow the industry information channel for more related knowledge.