1. ls
1.1 命令格式
ls [选项] [目录名]
1.2 命令描述
列举目录的内容
1.3 常用选项
-a all 里出所有的目录文件,包括以 . 开头的隐藏文件
[root@test ~]# ls -a
. .. anaconda-ks.cfg .bash_history .bash_logout config
-R 遍历列出所有子目录层
[root@test test]# ls -R
.:
file_test test1
./test1:
test1_1
-t 以文件修改时间排序
[root@test test]# ls -t
test2 test1 file_test
-l 每行只列出一个文件 ,等价于 ll
[root@test test]# ls -l
总用量 0
-rw-r--r--. 1 root root 0 2月 25 22:44 file_test
drwxr-xr-x. 2 root root 21 2月 25 22:45 test1
drwxr-xr-x. 2 root root 6 2月 25 22:45 test2
2. cd
2.1 命令格式
cd [目录名]
2.2 命令描述
切换目录
2.3 实例
(1)cd /tmp 切换到/tmp目录
[root@test /]# pwd
/
[root@test /]# cd /tmp
[root@test tmp]# pwd
/tmp
(2)cd ~ 切换到当前用户的home目录
[root@test tmp]# cd ~
[root@test ~]# pwd
/root
(3)cd … 返回上级目录
[root@test test1]# pwd
/test/test1
[root@test test1]# cd ..
[root@test test]# pwd
/test
(4)cd !$ 切换到上一个命令的参数对应的目录
[root@test /]# ls /test
file_test test1 test2
[root@test /]# cd !$
cd /test
[root@test test]#
3.cat
3.1 命令格式
mkdir [选项] 目录名
3.2 命令描述
切换目录
3.3 常见参数
-m=mode
为目录指定访问权限,与chmod类似。
-p 如果目录已经存在,则不会有错误提示。若父目录不存在,将会创建父目录。该选项常用于创建级联目录。
3.4 实例
(1)创建一个目录,默认权限是777-umask
[root@test test]# umask
0022
[root@test test]# mkdir /test/test3
[root@test test]# ls -l
总用量 0
-rw-r--r--. 1 root root 0 2月 25 22:44 file_test
drwxr-xr-x. 2 root root 21 2月 25 22:45 test1
drwxr-xr-x. 2 root root 6 2月 25 22:45 test2
drwxr-xr-x. 2 root root 6 2月 26 07:28 test3 # 权限=777-022=755
(2) 创建多个目录
[root@test test]# pwd
/test
[root@test test]# mkdir test4 test5 test6
[root@test test]# ls -l
总用量 0
-rw-r--r--. 1 root root 0 2月 25 22:44 file_test
drwxr-xr-x. 2 root root 21 2月 25 22:45 test1
drwxr-xr-x. 2 root root 6 2月 25 22:45 test2
drwxr-xr-x. 2 root root 6 2月 26 07:28 test3
drwxr-xr-x. 2 root root 6 2月 26 07:31 test4
drwxr-xr-x. 2 root root 6 2月 26 07:31 test5
drwxr-xr-x. 2 root root 6 2月 26 07:31 test6
(3)级联创建
[root@test test]# mkdir test4/{test4_1,test4_2,test4_3} # 同时创建多个同级目录,可以也可使用mkdir test4/test4_1 test4/test4_2 test4/test4_3
[root@test test]# pwd
/test
[root@test test]# cd test4/
[root@test test4]# ls -l
总用量 0
drwxr-xr-x. 2 root root 6 2月 26 07:33 test4_1
drwxr-xr-x. 2 root root 6 2月 26 07:33 test4_2
drwxr-xr-x. 2 root root 6 2月 26 07:33 test4_3
# 完整的例子
mkdir -p project/src/{main/com/test/{controller,service/impl,dao,vo,po},test} #-p:如果不存在父级目录,会先创建
(4)指定权限创建目录
mkdir -m=rw test4/test4_4 -- 读写 # -m=rw表示所有者、所在组、其它组的权限都为rw,即555。而umask=022,所以最终权限为555-022=544(为什么不为533看下面的umask介绍)
[root@test test4]# ls -l
总用量 0
drwxr-xr-x. 2 root root 6 2月 26 07:35 test4_1
drwxr-xr-x. 2 root root 6 2月 26 07:35 test4_2
drwxr-xr-x. 2 root root 6 2月 26 07:35 test4_3
drw-r--r--. 2 root root 6 2月 26 07:38 test4_4
4. 附加
4.1 umask(非重点)
https://www.cnblogs.com/zhaojiedi1992/p/zhaojiedi_linux_001.html
https://blog.51cto.com/xeoon/1761139