首页 技术 正文
技术 2022年11月16日
0 收藏 643 点赞 5,137 浏览 3381 个字

mkdir命令用于创建目录,如同一路径下创建单个或多个目录、递归创建目录,但同路径下不能创建同名目录,且目录名区分大小写。

【命令】

mkdir

【用途】

  创建目录(单个目录/多个目录)

【语法】

mkdir [选项]…目录名…

【示例】

  切换到当前目录:/usr/local/linuxStudy,所有示例在此路径下操作。

[root@testserver linuxStudy]# pwd
/usr/local/linuxStudy

例1.创建单个目录dir1

[root@testserver linuxStudy]# mkdir dir1
[root@testserver linuxStudy]# ls
dir1

例2.一次创建多个目录:dir2,dir3

[root@testserver linuxStudy]# mkdir dir2 dir3
[root@testserver linuxStudy]# ls
dir1 dir2 dir3

例3.同路径下创建同名目录:dir1–>创建失败,同路径下不能创建同名目录

[root@testserver linuxStudy]# mkdir dir1
mkdir: cannot create directory `dir1': File exists

例4.-p参数,创建多层目录dir4/dir5(dir4目录不存在时,同时创建dir4、dir5目录;dir4目录存在时,则只创建dir5目录)

[root@testserver linuxStudy]# mkdir dir4/dir5                           #未加-p参数,上层目录不存在时,创建目录失败
mkdir: cannot create directory `dir4/dir5': No such file or directory
[root@testserver linuxStudy]# mkdir -p dir4/dir5 #-p:上层目录不存在时,同步创建
[root@testserver linuxStudy]# ls -R #-R:递归列出当前目录下所有的目录、文件
.:
dir1 dir2 dir3 dir4./dir1:./dir2:./dir3:./dir4:
dir5./dir4/
dir5:
[root@testserver linuxStudy]#

例5:-v参数,对于每个创建的目录,打印一条信息

[root@testserver linuxStudy]# mkdir -v dir6
mkdir: created directory `dir6'
[root@testserver linuxStudy]# mkdir -v dir7 dir8
mkdir: created directory `dir7'
mkdir: created directory `dir8'

例6.-m参数,创建目录的同时设置文件权限(同chmod命令)

[root@testserver linuxStudy]# mkdir -m o-rw dir10  #创建dir10目录,other用户去掉rw权限
[root@testserver linuxStudy]# ll
total
drwxr-xr-x root root May : dir1
drwxrwx--x 2 root root 4096 May 9 15:08 dir10
drwxr-xr-x root root May : dir2
drwxr-xr-x root root May : dir3
drwxr-xr-x root root May : dir4
drwxr-xr-x root root May : dir6
drwxr-xr-x root root May : dir7
drwxr-xr-x root root May : dir8
drwxrwxrwx root root May : dir9
[root@testserver linuxStudy]# mkdir -m dir11 #创建dir11目录,设置user、group、other用户权限分别为5、1、1(读权限4,写权限2,执行权限1,用户具备多种权限时值相加)
[root@testserver linuxStudy]# ll
total
drwxr-xr-x root root May : dir1
drwxrwx--x root root May : dir10
dr-x--x--x 2 root root 4096 May 9 15:09 dir11
drwxr-xr-x root root May : dir2
drwxr-xr-x root root May : dir3
drwxr-xr-x root root May : dir4
drwxr-xr-x root root May : dir6
drwxr-xr-x root root May : dir7
drwxr-xr-x root root May : dir8
drwxrwxrwx root root May : dir9

【帮助文档】

Linux环境下输入 man mkdir,查看find命令的帮助文档(ps:英文渣渣咬咬牙啃一啃帮助文档。不要偷懒,多看官方文档。注释部分为个人添加。)

[root@testserver local]# man mkdir
MKDIR() User Commands MKDIR()NAME
mkdir - make directories #创建目录SYNOPSIS
mkdir [OPTION]... DIRECTORY...DESCRIPTION
Create the DIRECTORY(ies), if they do not already exist. #目录已存在时,创建目录失败 Mandatory arguments to long options are mandatory for short options too. -m, --mode=MODE
set file mode (as in chmod), not a=rwx - umask #设置文件权限,而不是默认权限a=rwx -p, --parents
no error if existing, make parent directories as needed
#父目录不存在时,创建所需的父目录 -v, --verbose
print a message for each created directory #对每一个创建的目录打印1条信息 -Z, --context=CTX
set the SELinux security context of each created directory to CTX --help display this help and exit --version
output version information and exitAUTHOR
Written by David MacKenzie.REPORTING BUGS
Report mkdir bugs to bug-coreutils@gnu.org
GNU coreutils home page: <http://www.gnu.org/software/coreutils/>
General help using GNU software: <http://www.gnu.org/gethelp/>
Report mkdir translation bugs to <http://translationproject.org/team/>COPYRIGHT
Copyright © Free Software Foundation, Inc. License GPLv3+: GNU GPL version or later
<http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permit-
ted by law.SEE ALSO
mkdir() The full documentation for mkdir is maintained as a Texinfo manual. If the info and mkdir programs are prop-
erly installed at your site, the command info coreutils 'mkdir invocation' should give you access to the complete manual.GNU coreutils 8.4 November MKDIR()
(END)

【写在末尾】

文章如有错误之处,欢迎评论指正。

有兴趣可关注同名微信公众号“粒粒的测试笔记”,号内会分享各种测试相关知识,感谢关注。

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,022
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,513
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,359
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,142
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,773
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,851