【每天一个Linux命令】19. 创建文件夹目录命令mkdir

命令用途

 
mkdir 命令用来创建指定的名称的目录

使用说明


1.  创建目录的用户在当前目录中具有写权限
2. 指定的目录名不能是当前目录中已有的目录。

命令实例

0. 帮助文件

bixiaopeng@bixiaopengtekiMacBook-Pro testshell$mkdir --help



用法:mkdir [选项]... 目录...

若指定目录不存在则创建目录。

长选项必须使用的参数对于短选项时也是必需使用的。

-m, --mode=模式 设置权限模式(类似chmod),而不是rwxrwxrwx 减umask

-p, --parents 需要时创建目标目录的上层目录,但即使这些目录已存在也不当作错误处理

-v, --verbose 每次创建新目录都显示信息

-Z, --context=CTX 将每个创建的目录的SELinux 安全环境设置为CTX

--help 显示此帮助信息并退出

--version 显示版本信息并退出

1. 创建一个空的文件夹

#mkdir 文件名

bixiaopeng@bixiaopengtekiMacBook-Pro testshell$ mkdir empty

bixiaopeng@bixiaopengtekiMacBook-Pro testshell$ ls -al

total 0

drwxr-xr-x  3 bixiaopeng  staff  102 Sep 27 16:43 .

drwxr-xr-x@ 7 bixiaopeng  staff  238 Sep 18 15:43 ..

drwxr-xr-x  2 bixiaopeng  staff   68 Sep 27 16:43 empty

2. 创建多级目录

#mkdir -p 文件夹1/文件夹2/文件夹3

bixiaopeng@bixiaopengtekiMacBook-Pro testshell$ mkdir -p dir/dir1/dir2/dir3

bixiaopeng@bixiaopengtekiMacBook-Pro testshell$ ls -al

total 0

drwxr-xr-x  4 bixiaopeng  staff  136 Sep 27 16:44 .

drwxr-xr-x@ 7 bixiaopeng  staff  238 Sep 18 15:43 ..

drwxr-xr-x  3 bixiaopeng  staff  102 Sep 27 16:44 dir

drwxr-xr-x  2 bixiaopeng  staff   68 Sep 27 16:43 empty

bixiaopeng@bixiaopengtekiMacBook-Pro testshell$ cd dir/dir1/dir2/dir3

bixiaopeng@bixiaopengtekiMacBook-Pro dir3$ ls -al

total 0

drwxr-xr-x  2 bixiaopeng  staff   68 Sep 27 16:44 .

drwxr-xr-x  3 bixiaopeng  staff  102 Sep 27 16:44 ..

bixiaopeng@bixiaopengtekiMacBook-Pro dir3$ pwd

/Users/bixiaopeng/Projects/testshell/dir/dir1/dir2/dir3

3.创建文件夹后对文件夹赋权限

#mkdir -m 权限 文件夹

bixiaopeng@bixiaopengtekiMacBook-Pro testshell$ mkdir -m 777 method

bixiaopeng@bixiaopengtekiMacBook-Pro testshell$ ls -al method

bixiaopeng@bixiaopengtekiMacBook-Pro testshell$ ls -al

total 0

drwxr-xr-x  5 bixiaopeng  staff  170 Sep 27 16:49 .

drwxr-xr-x@ 7 bixiaopeng  staff  238 Sep 18 15:43 ..

drwxr-xr-x  3 bixiaopeng  staff  102 Sep 27 16:44 dir

drwxr-xr-x  2 bixiaopeng  staff   68 Sep 27 16:43 empty

drwxrwxrwx  2 bixiaopeng  staff   68 Sep 27 16:49 method

 

4.创建目录显示目录信息

 

#mkdir -v 文件夹

bixiaopeng@bixiaopengtekiMacBook-Pro testshell$ mkdir -v vdir

mkdir: created directory 'vdir'

bixiaopeng@bixiaopengtekiMacBook-Pro testshell$ ls -al

total 0

drwxr-xr-x  6 bixiaopeng  staff  204 Sep 27 16:51 .

drwxr-xr-x@ 7 bixiaopeng  staff  238 Sep 18 15:43 ..

drwxr-xr-x  3 bixiaopeng  staff  102 Sep 27 16:44 dir

drwxr-xr-x  2 bixiaopeng  staff   68 Sep 27 16:43 empty

drwxrwxrwx  2 bixiaopeng  staff   68 Sep 27 16:49 method

drwxr-xr-x  2 bixiaopeng  staff   68 Sep 27 16:51 vdir


【每天一个Linux命令】19. 创建文件夹目录命令mkdir

 



你可能感兴趣的:(linux命令)