echo'~/.bash_profile is a file'elseecho'~/.bash_profile is not a file'fi printf'\n'if[-d~/];then echo'~/ is a directory'elseecho'~/ is not a directory'fi -f即判断是否为file, -d即判断是否为directory, 输出结果: 代码语言:javasc
[student@studentvm1 testdir]$ File="TestFile1" ; rm $File ; if [ -s $File ] ; then echo "$File exists and contains data." ; else echo "$File does not exist or is empty." ; fi TestFile1 does not exist or is empty. 现在创建一个空文件用来测试: [student@studentvm1 testdir]...
--cut-dirs=NUMBER ignore NUMBER remote directory components HTTP options: --http-user=USER set http user to USER --http-password=PASS set http password to PASS --no-cache disallow server-cached data --default-page=NAME change the default page name (normally this is 'index.html'.) -E, ...
1判断是否是文件夹https://blog.csdn.net/StephenHendery/article/details/79049521import os if os.path.isdir(path): print "it's a directory" elif os.path.isfile(path): print "it's a normal file" else: 删除文件夹 删除文件 文件类型
touchtest.shfilename="test.sh"iftest -f"$filename";thenecho"It's a regular file."fi 运行上面代码的输出结果为: It's a regular file. 另一个重要的选项是 -d,它用来检查一个路径是不是目录: dirname="/bin"iftest -d"$dirname";thenecho"It's a directory."fi ...
Check if a Directory Exists in Bash To check if adirectoryexists, switch the-foption on thetestcommand with-d(for directory). For example: test -d /tmp/testCopy echo $?Copy The output is1, which means that the directory doesn't exist. Create the directory using themkdir commandand reru...
the first one will be made active. The default installation directory is: ~/n which can be overridden by setting environment variable N_PREFIX to an absolute path before invocation; either way, however, the installation directory must either not exist yet or be empty. If your shell is bash,...
This shell function will install (if needed) and nvm use the specified Node version when an .nvmrc is found, and nvm use default otherwise.Put this into your $HOME/.zshrc to call nvm use automatically whenever you enter a directory that contains an .nvmrc file with a string telling nvm ...
In order to check if a directory exists in Bash, you have to use the “-d” option and specify the directory name to be checked. if [[ -d "$DIRECTORY" ]] then echo "$DIRECTORY exists on your filesystem." fi As an example, let’s say that you want to check with Bash if the...
- Test if the specified variable has an empty value: [[ -z $variable ]] - Test if the specified [f]ile exists: [[ -f path/to/file ]] - Test if the specified [d]irectory exists: [[ -d path/to/directory ]] - Test if the specified file or directory [e]xists: ...