chmod u+x script.sh
mkdir /path/to/directory
检查磁盘空间。如果磁盘空间不足,创建目录会失败,需检查磁盘剩余空间并清理无用文件。
使用sudo命令以管理员身份运行脚本。然后,可以创建所需的目录:
sudo bash script.sh
以下是示例脚本,用于在当前目录下创建名为"testdir"的目录:
#!/bin/bash if [ ! -d "testdir" ]; then mkdir testdir echo "Directory created." else echo "Directory already exists." fi
使用chmod命令增加脚本的权限,确保脚本可以执行:
chmod u+x script.sh
运行脚本:
bash script.sh
如果一切正常,将在当前目录下创建名为"testdir"的目录,同时在终端中显示"Directory created."的消息。