Linux 先查看一下 moot/test/logical 这个名称是否存在; 若不存在,则建立一个文件,,使用touch来建立,建立完成后离开; 如果存在的话,判断该名称是否为文件,若为文件则帆之删 除后建立一个文件,档名为 logical 之后离开; 如果存在的话,而且该名称为目录,则移除此目录!
时间: 2023-08-16 17:03:27 浏览: 49
在 Linux 中,可以使用以下命令来完成这个任务:
```
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` 命令创建一个文件。如果存在,则判断它是文件还是目录。如果是文件,则使用 `rm` 命令删除它,然后使用 `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)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.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)