查看man bash,您可以执行以下操作:
-a file
True if file exists.
-d file
True if file exists and is a directory.
-e file
True if file exists.
-f file
True if file exists and is a regular file.
-u file
True if file exists and its set-user-id bit is set.
-x file
True if file exists and is executable.
-L file
True if file exists and is a symbolic link.
Run Code Online (Sandbox Code Playgroud)
还有很多很多。
您还可以使用file命令(请参阅 参考资料man file)查看文件“内部”以获取更多信息。
与其解析输出ls(这总是导致最终的混淆),不如使用/usr/bin/stat -c "%a %n" filename:
$ stat -c "%a %n" .bashrc
700 .bashrc
Run Code Online (Sandbox Code Playgroud)