1.准备工作
打开终端窗口,依次输入以下命令:
root@cg:~/Desktop# cd ~/base
root@cg:~/base# mkdir dirandfile
root@cg:~/base# cd dirandfile
root@cg:~/base/dirandfile#
在当前目录下新建文件夹dirandfile,作为本实验的工作目录。
2.mkdir(创建目录)
语法:
mkdir [-mp] 目录名称
选项和参数:
-m :配置文件的权限
-p :递归地创建目标目录及全部的上层目录
示例:
root@cg:~/base/dirandfile# mkdir test
root@cg:~/base/dirandfile# mkdir test1/test2/test3/test4
mkdir: cannot create directory 'test1/test2/test3/test4': No such file or directory
root@cg:~/base/dirandfile# mkdir -p test1/test2/test3/test4
root@cg:~/base/dirandfile#
可以看到有了-p选项之后,可以递归地创建出所需要目录的上层目录。
root@cg:~/base/dirandfile# ls -l
total 8
drwxr-xr-x 2 root root 4096 Feb 16 14:42 test
drwxr-xr-x 3 root root 4096 Feb 16 14:43 test1
root@cg:~/base/dirandfile# mkdir -m 711 test2
root@cg:~/base/dirandfile# ls -l
total 12
drwxr-xr-x 2 root root 4096 Feb 16 14:42 test
drwxr-xr-x 3 root root 4096 Feb 16 14:43 test1
drwx--x--x 2 root root 4096 Feb 16 14:44 test2
root@cg:~/base/dirandfile#
如果没有设置-m选项,那么该目录将被设置为默认权限,在上例中该目录通过-m 711设置为了drwxr-sr-x权限。
3.ls(列出目录)
语法:
ls [-aAdfFhilnrRSt] 目录名称
ls [–color={never,auto,always}] 目录名称
ls [–full-time] 目录名称
选项和参数:
-a :全部的文件,包括隐藏文件
-d :仅列出目录
-l :列出详细的文件属性
示例:
root@cg:~/base/dirandfile# ls -l
total 12
drwxr-xr-x 2 root root 4096 Feb 16 14:42 test
drwxr-xr-x 3 root root 4096 Feb 16 14:43 test1
drwx--x--x 2 root root 4096 Feb 16 14