Linux 先查看一下 moot/test/logical 这个名称是否存在; 若不存在,则建立一个文件,,使用touch来建立,建立完成后离开; 如果存在的话,判断该名称是否为文件,若为文件则帆之删 除后建立一个文件,档名为 logical 之后离开; 如果存在的话,而且该名称为目录,则移除此目录!
时间: 2023-08-16 14:04:25 浏览: 31
你可以通过以下命令来实现该功能:
```
if [ ! -e "moot/test/logical" ]; then
touch moot/test/logical
else
if [ -f "moot/test/logical" ]; then
rm moot/test/logical
touch moot/test/logical
elif [ -d "moot/test/logical" ]; then
rm -r moot/test/logical
fi
fi
```
该脚本首先判断文件或目录 `moot/test/logical` 是否存在,如果不存在,则使用 `touch` 命令创建该文件。如果存在,则进一步判断该名称是文件还是目录。如果是文件,则删除文件后再使用 `touch` 命令创建同名文件。如果是目录,则使用 `rm -r` 命令删除目录。
相关推荐
![exe](https://img-home.csdnimg.cn/images/20210720083343.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)