linux基础命令-mkdir/tree/rmdir

命令行的展开

~: 展开为用户的主目录

~USERNAME: 展开为指定用户的主目录

{}:可承载一个以逗号分隔的列表,并将其展开为多个路径

[root@host01 tmp]# mkdir   -vp /tmp/{china/{Beijing,Shanghai},usa,english} 
mkdir: created directory `/tmp/china'
mkdir: created directory `/tmp/china/Beijing'
mkdir: created directory `/tmp/china/Shanghai'
mkdir: created directory `/tmp/usa'
mkdir: created directory `/tmp/english'

命令的执行结果状态

bash使用特殊变量$? 保存最后一条命令的执行状态结果

1)成功 0

2)失败 1-255

[root@host01 tmp]# mkdir /tmp/test
[root@host01 tmp]# echo $?
0
[root@host01 tmp]# mkdir /tmp/test
mkdir: cannot create directory `/tmp/test': File exists
[root@host01 tmp]# echo $?
1
[root@host01 tmp]# 

 

程序执行有两类结果

1)程序的返回值

2)程序的运行状态结果(只有两种状态)

mkdir 创建目录

-p:同时创建父目录

-v:显示创建过程

-m MODE : 创建目录时直接指定权限

[root@host01 ~]# mkdir /tmp/a
[root@host01 ~]# mkdir /tmp/a/b/c
mkdir: cannot create directory `/tmp/a/b/c': No such file or directory
[root@host01 ~]# mkdir  -pv  /tmp/a/b/c                                        #路径不存在的目录创建时会报错,要加-p参数将想应的路径一起创建
mkdir: created directory `/tmp/a/b'
mkdir: created directory `/tmp/a/b/c'
[root@host01 ~]# tree /tmp/
/tmp/
├── a
│   └── b
│       └── c
└── yum.log

3 directories, 1 file
[root@host01 ~]# ls -d /tmp/a/
/tmp/a/
[root@host01 ~]# ll -d /tmp/a/
drwxr-xr-x. 3 root root 4096 Aug 22 04:36 /tmp/a/
[root@host01 ~]# mkdir  -m 644 /tmp/a/a1                      #mkdir -m 权限  路径   创建指定权限的目录
[root@host01 ~]# ll -d /tmp/a/a1/
drw-r--r--. 2 root root 4096 Aug 22 04:39 /tmp/a/a1/
[root@host01 ~]# mkdir  -v  {x,y}-{a,b}
mkdir: created directory `x-a'
mkdir: created directory `x-b'
mkdir: created directory `y-a'
mkdir: created directory `y-b'
[root@host01 ~]# ls
anaconda-ks.cfg  install.log  install.log.syslog  x-a  x-b  y-a  y-b
[root@host01 ~]# rmdir  {x,y}-{a,b} -v
rmdir: removing directory, `x-a'
rmdir: removing directory, `x-b'
rmdir: removing directory, `y-a'
rmdir: removing directory, `y-b'
[root@host01 ~]# 

 

 rmdir  删除空目录

[root@host01 tmp]# ls
a  yum.log
[root@host01 tmp]# rmdir -v a/
rmdir: removing directory, `a/'
rmdir: failed to remove `a/': Directory not empty
[root@host01 tmp]# ll ./a/
total 8
drw-r--r--. 2 root root 4096 Aug 22 04:39 a1
drwxr-xr-x. 3 root root 4096 Aug 22 04:36 b
[root@host01 tmp]# rmdir /tmp/a/a1/ 
a/         .ICE-unix/ yum.log    
[root@host01 tmp]# rmdir /tmp/a/a1/ 
a/         .ICE-unix/ yum.log    
[root@host01 tmp]# rmdir /tmp/a/a1/  -v
rmdir: removing directory, `/tmp/a/a1/'
[root@host01 tmp]# 

 

 tree

-d:只显示目录

-L level : 指定显示的层级数目

-P  pattern  :只显示由指定pattern匹配到的路径

[root@host01 tmp]# tree -d  /boot/
/boot/
├── efi
│   └── EFI
│       └── redhat
├── grub
└── lost+found

5 directories
[root@host01 tmp]# tree -L 1  /boot/
/boot/
├── config-2.6.32-696.el6.x86_64
├── efi
├── grub
├── initramfs-2.6.32-696.el6.x86_64.img
├── lost+found
├── symvers-2.6.32-696.el6.x86_64.gz
├── System.map-2.6.32-696.el6.x86_64
└── vmlinuz-2.6.32-696.el6.x86_64

3 directories, 5 files
[root@host01 tmp]# 

 

posted @ 2017-08-21 21:28  JUSTZHI  阅读(319)  评论(0编辑  收藏  举报