1、查看命令帮助的几种方法
a.[命令] --help 适用于一般命令,非内置命令
b.man [命令] 适用于一般命令,非内置命令
c.help [命令] 适用于内置命令
d. info
2、pwd:【print name of current/working directory】
注释:打印当前目录,进入别人电脑操作,要先查看当前所在位置。
pwd == pwd -L(等价参数-L)
-L --logical
-P --physical
3、mkdir:【Create the DIRECTORY(ies), if they do not already exist.】 MaKe DIRectory 的缩写
Usage:mkdir [option] ... Driectory ..... 可以创建多个目录
-m, --mode=MODE set file mode (as in chmod), not a=rwx - umask #创建目录,并加上权限,一般不使用它,使用chmod来创建权限 -p, --parents no error if existing, make parent directories as needed -v, --verbose print a message for each created directory #查看创建过程 -Z set SELinux security context of each created directory to the default type
示例如下:
root@zhu-K53SJ:/oldboy# cd /;mkdir oldboy #正常创建目录,如果文件已经存在,则报错 mkdir: 无法创建目录"oldboy": 文件已存在 root@zhu-K53SJ:/# cd /;mkdir -p oldboy #参数-p,如果文件存在,创建目录不会报错;如果文件不存在,可以递归的创建目录
root@zhu-K53SJ:/oldboy# mkdir -p test/alex/sb
root@zhu-K53SJ:/oldboy# mkdir -pv test/{1..3}/{4..6} #递归的创建目录,并查看目录的创建过程
root@zhu-K53SJ:/oldboy/test# mkdir test{1..6} #有规律的创建目录,可以使用{min..max}
root@zhu-K53SJ:/oldboy/test# ls
test1 test2 test3 test4 test5 test6
root@zhu-K53SJ:/oldboy/test# tree
.
├── test1
├── test2
├── test3
├── test4
├── test5
└── test6
4、echo 【Write arguments to the standard output】 将参数写入标准输出
echo {1..10} 打印一行数据,1-10
root@zhu-K53SJ:/oldboy/test# echo {1..10} #非常常用的方法,打印一行数字1-10 1 2 3 4 5 6 7 8 9 10 root@zhu-K53SJ:/oldboy/test# echo {1..3}{4..6} 14 15 16 24 25 26 34 35 36
5、cd change directory 【Change the shell working directory.】
cd: cd [-L|[-P [-e]] [-@]] [dir]
cd ../ 切换到上级目录 cd ../../.. 根目录就不能切换了,顶点 cd -切换到上一次的目录 cd ~ 切换到家目录(root目录)
.. 上一级目录
- 上一次目录
~ 代表家目录
6、tree 【tree - list contents of directories in a tree-like format.】以树的形式显示目录结构
tree 以树一样来显示文件的目录 lang=en 设置字符显示格式,临时生效,要想永久生效,就要修改配置文件
参数:
-a All files are listed. #-a是显示隐藏文件,以.开始的文件和目录 -d List directories only. #-d仅仅显示目录,不显示文件 -l Follow symbolic links like directories.
-i Don't print indentation lines. #不显示前面的横线 -f Print the full path prefix for each file. #-f 为每个文件显示完整的路径 -x Stay on current filesystem only. -L level Descend only level directories deep. #-L level 显示oldboy的层级
-F Appends '/', '=', '*', '@', '|' or '>' as per ls -F. #显示目录,目录后面会加上/
参数实例:
root@zhu-K53SJ:~# tree /oldboy #查看oldboy目录下面的文件,Linux系统中,以.形式开始是隐藏 /oldboy ├── test │ ├── 1 │ │ ├── 4 │ │ ├── 5 │ │ └── 6 │ ├── 2 │ │ ├── 4 │ │ ├── 5 │ │ └── 6 │ └── 3 │ ├── 4 │ ├── 5 │ └── 6 └── test.sh 13 directories, 1 file
root@zhu-K53SJ:~# tree -a /oldboy #-a 参数显示隐藏文件,.开始的文件是隐藏文件
/oldboy
├── .sh
├── test
│ ├── 1
│ │ ├── 4
│ │ ├── 5
│ │ └── 6
│ ├── 2
│ │ ├── 4
│ │ ├── 5
│ │ └── 6
│ └── 3
│ ├── 4
│ ├── 5
│ └── 6
└── test.sh
root@zhu-K53SJ:~# tree -L 2 /oldboy #显示前两层目录结构
/oldboy
├── test
│ ├── 1
│ ├── 2
│ └── 3
└── test.sh
root@zhu-K53SJ:~# tree -F /oldboy #-F是为了区分文件或目录,目录后面都有/斜杠,文件是没有的,就能区分出来文件和目录。
/oldboy
├── test/
│ ├── 1/
│ │ ├── 4/
│ │ ├── 5/
│ │ └── 6/
│ ├── 2/
│ │ ├── 4/
│ │ ├── 5/
│ │ └── 6/
│ ├── 3/
│ │ ├── 4/
│ │ ├── 5/
│ │ └── 6/
│ └── alex.txt
└── test.sh
7、touch
作用:(1)文件不存在,创建新文件 ;(2)文件存在,更新时间戳
参数:
-a 只更改访问时间(Recent access) -c, --no-create 不创建任何文件 -d, --date=字符串 使用指定字符串表示时间而非当前时间 -f (忽略) -h, --no-dereference 会影响符号链接本身,而非符号链接所指示的目的地 (当系统支持更改符号链接的所有者时,此选项才有用) -m 只更改修改时间 (modify time) -r, --reference=FILE use this file's times instead of current time -t STAMP use [[CC]YY]MMDDhhmm[.ss] instead of current time --time=WORD change the specified time: WORD is access, atime, or use: equivalent to -a WORD is modify or mtime: equivalent to -m
参数实例:
root@zhu-K53SJ:~/test# touch oldboy.txt #创建目录,如果文件存在,更新时间戳 root@zhu-K53SJ:~/test# touch oldboy.txt oot@zhu-K53SJ:~/test# touch 1.txt 2.txt #批量创建目录方法1,不常用 root@zhu-K53SJ:~/test# touch {3..5}.txt #批量创建目录方法2,要掌握这种方法{min..max}来创建 root@zhu-K53SJ:~/test# ls 1.txt 2.txt 3.txt 4.txt 5.txt dir1 dir2 dir3 dir4 dir5 oldboy.txt
更改文件的时间戳
root@zhu-K53SJ:~/test# stat oldboy.txt #查看文件属性 文件:'oldboy.txt' 大小:0 块:0 IO 块:4096 普通空文件 设备:801h/2049d Inode:8389405 硬链接:1 权限:(0644/-rw-r--r--) Uid:( 0/ root) Gid:( 0/ root) 最近访问:2017-10-14 22:08:11.193012120 +0800 最近更改:2017-10-14 22:08:11.193012120 +0800 最近改动:2017-10-14 22:08:11.193012120 +0800 创建时间:-
路径:
相对路径:不从/根开始 例如:test 相对路径是相对与当前的路径,当前工作的目录,相对路径 注意,切换目录的时候,相对切换
绝对路径:从/根开始 例如:/oldboy/test