Linux命令之mkdir
mkdir [选项] 目录
若指定目录不存在则创建目录
(1).常用选项
1 2 3 4 5 | -m,--mode=模式 设置权限模式(类似chmod),而不是rwxrwxrwx减umask -p,--parents 需要时创建目标目录的上层目录,但即使这些目录已存在也不当作错误处理 -v,--verbose 每次创建新目录都显示信息 -Z,--context=CTX 将每个创建的目录的SELinux安全环境设置为CTX --version 显示版本信息并退出 |
(2).实例
当前目录下创建一个新文件夹
1 2 3 4 5 6 | [ root@CentOS6 桌面]# ll 总用量 0 [ root@CentOS6 桌面]# mkdir mainDir [ root@CentOS6 桌面]# ll 总用量 4 drwxr-xr-x. 2 root root 4096 4月 8 09:49 mainDir |
在当前目录下创建一个新的文件夹,并输出信息
1 2 3 4 5 6 | [ root@CentOS6 桌面]# mkdir –v secondDir Mkdir:已创建目录“secondDir” [ root@CentOS6 桌面]# ll 总用量 8 drwxr-xr-x. 2 root root 4096 4月 8 09:49 mainDir drwxr-xr-x. 2 root root 4096 4月 8 10:02 secondDir |
在指定目录下创建文件夹,该文件夹只有创建者自己有读写执行权限
1 2 3 4 5 6 7 8 9 10 11 | [ root@CentOS6 桌面]# mkdir –m 700 thirdDir/test7 [ root@CentOS6 桌面]# cdthirdDir/ [ root@CentOS6 桌面]# ll 总用量 28 drwxr-xr-x. 2 root root 4096 4月 8 10:15 test1 drwxr-xr-x. 2 root root 4096 4月 8 10:15 test2 drwxr-xr-x. 2 root root 4096 4月 8 10:15 test3 drwxr-xr-x. 2 root root 4096 4月 8 10:47 test4 drwxr-xr-x. 2 root root 4096 4月 8 10:47 test5 drwxr-xr-x. 2 root root 4096 4月 8 10:47 test6 drwx------. 2 root root 4096 4月 8 12:31 test7 |
在当前目录下创建一个新的文件夹,且包含多个子文件夹,另外-p选项支持多层级目录
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | [ root@CentOS6 桌面]# mkdir –p thirdDir/{test1,test2,test3} [ root@CentOS6 桌面]# ll 总用量 12 drwxr-xr-x. 2 root root 4096 4月 8 09:49 mainDir drwxr-xr-x. 2 root root 4096 4月 8 10:02 secondDir drwxr-xr-x. 5 root root 4096 4月 8 10:15 thirdDir [ root@CentOS6 桌面]# cd thirdDir [ root@CentOS6 thirdDir]# ll 总用量 12 drwxr-xr-x. 2 root root 4096 4月 8 10:15 test1 drwxr-xr-x. 2 root root 4096 4月 8 10:15 test2 drwxr-xr-x. 2 root root 4096 4月 8 10:15 test3 [ root@CentOS6 thirdDir]# cd .. [ root@CentOS6 桌面]# mkdir thirdDir/{test4,test5,test6} [ root@CentOS6 桌面]# ll 总用量 12 drwxr-xr-x. 2 root root 4096 4月 8 09:49 mainDir drwxr-xr-x. 2 root root 4096 4月 8 10:02 secondDir drwxr-xr-x. 5 root root 4096 4月 8 10:15 thirdDir [ root@CentOS6 桌面]# cd thirdDir [ root@CentOS6 thirdDir]# ll 总用量 12 drwxr-xr-x. 2 root root 4096 4月 8 10:15 test1 drwxr-xr-x. 2 root root 4096 4月 8 10:15 test2 drwxr-xr-x. 2 root root 4096 4月 8 10:15 test3 drwxr-xr-x. 2 root root 4096 4月 8 10:47 test4 drwxr-xr-x. 2 root root 4096 4月 8 10:47 test5 drwxr-xr-x. 2 root root 4096 4月 8 10:47 test6 |
在当前目录下创建指定文件夹,该文件夹只有创建者自己有读写执行权限,同组用户可读和执行权限
1 2 3 4 5 6 7 8 9 10 11 | [ root@CentOS6 桌面]# mkdir -pm 750 bin/os_1 [ root@CentOS6 桌面]# ll 总用量 16 drwxr-xr-x. 3 root root 4096 4月 8 12:54 bin drwxr-xr-x. 2 root root 4096 4月 8 09:49 bin drwxr-xr-x. 2 root root 4096 4月 8 10:02 bin drwxr-xr-x. 9 root root 4096 4月 8 12:31 bin [ root@CentOS6 桌面]# cd bin [ root@CentOS6 bin]# ll 总用量 4 drwxr-x---. 2 root root 4096 4月 8 12:54 os_1 |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· .NET Core 中如何实现缓存的预热?
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
· 【译】Visual Studio 中新的强大生产力特性