在Linux系统中咱们之因此可以直接使用命令是由于命令的绝对路径在环境变量里面,若是咱们将该命令的绝对路径移出环境变量则不能直接使用。在实验以前讲一个which命令,这个命令能够用来查看一个命令的绝对路径和是否作过别名bash
[root@localhost ~]# which ls alias ls='ls --color=auto' /usr/bin/ls [root@localhost ~]# which mkdir /usr/bin/mkdir [root@localhost ~]# which rm alias rm='rm -i' /usr/bin/rm [root@localhost ~]# echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin [root@localhost ~]# ^C [root@localhost ~]#
在上面的代码中咱们看到ls =ls --color=auto /usr/bin/ls 。是说这个ls命令实际上是/usr/bin/ls命令颜色自动显示,上面代码中的echo是用来输出$PATH的值。若是咱们把ls命令移出/usr/bin 到/root下,会出现怎样的状况呢?less
[root@localhost ~]# mv /usr/bin/ls /root [root@localhost ~]# ls -bash: /usr/bin/ls: 没有那个文件或目录
能够看到ls命令再也不生效,而使用绝对路径/root/ls 命令会生效,那怎样才能使ls再次生效呢?能够把/root/ls加入到环境变量中去,其操做以下code
root@localhost ~]# PATH=$PATH:/root [root@localhost ~]# echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/root [root@localhost ~]# ls 22 anaconda-ks.cfg ls
为了避免影响使用,咱们把ls文件还原ip
在前面一段代码中咱们还使用到了mv命令,mv=move 移动的意思 ,使用格式为:mv [参数] [源文件或源目录] [目标文件或目标目录]字符串
[root@localhost ~]# mkdir /tmp/11 [root@localhost ~]# mkdir /tmp/11/22 [root@localhost ~]# mkdir /tmp/33 [root@localhost ~]# mv /tmp/11/22 /tmp/33 [root@localhost ~]# tree /tmp /tmp ├── 11 ├── 33 │ └── 22 ├── ks-script-PUqKsg └── yum.log 3 directories, 2 files [root@localhost ~]# mv /tmp/33/22 /tmp/11/44 [root@localhost ~]# tree /tmp /tmp ├── 11 │ └── 44 ├── 33 ├── ks-script-PUqKsg └── yum.log 3 directories, 2 files [root@localhost ~]# touch /tmp/11/44/123 [root@localhost ~]# !tree tree /tmp /tmp ├── 11 │ └── 44 │ └── 123 ├── 33 ├── ks-script-PUqKsg └── yum.log 3 directories, 3 files [root@localhost ~]# mv /tmp/11/44/123 /tmp/33 [root@localhost ~]# !tree tree /tmp /tmp ├── 11 │ └── 44 ├── 33 │ └── 123 ├── ks-script-PUqKsg └── yum.log 3 directories, 3 files [root@localhost ~]# !touch touch /tmp/11/44/123 [root@localhost ~]# !tree tree /tmp /tmp ├── 11 │ └── 44 │ └── 123 ├── 33 │ └── 123 ├── ks-script-PUqKsg └── yum.log 3 directories, 4 files [root@localhost ~]# mv /tmp/11/44/123 /tmp/33/123 mv:是否覆盖"/tmp/33/123"? y [root@localhost ~]# !tree tree /tmp /tmp ├── 11 │ └── 44 ├── 33 │ └── 123 ├── ks-script-PUqKsg └── yum.log 3 directories, 3 files
cp命令=copy 格式为copy[参数] [源文件] [目标文件]变量
[root@localhost ~]# !tree tree /tmp /tmp ├── 11 │ └── 44 ├── 33 │ └── 123 ├── ks-script-PUqKsg └── yum.log 3 directories, 3 files [root@localhost ~]# cp /tmp/33/123 /tmp/555 [root@localhost ~]# !tree tree /tmp /tmp ├── 11 │ └── 44 ├── 33 │ └── 123 ├── 555 ├── ks-script-PUqKsg └── yum.log 3 directories, 4 files [root@localhost ~]# cp /tmp/33 /tmp/55 cp: 略过目录"/tmp/33" [root@localhost ~]# cp -r /tmp/33 /tmp/55 [root@localhost ~]# !tree tree /tmp /tmp ├── 11 │ └── 44 ├── 33 │ └── 123 ├── 55 │ └── 123 ├── 555 ├── ks-script-PUqKsg └── yum.log 4 directories, 5 files
这几个命令都是用来查看文件内容的命令,格式为cat [参数] [文件名], 不加任何参数就会把文件里全部的内容都抛到屏幕上file
more命令会分屏显示内容,看完一屏后可使用空格键看下一屏,Ctrl +d 能够向上翻屏 ,Ctrl+f能够向下翻屏。若是想提早退出,可使用q键。搜索
less命令跟more命令同样会分屏显示内容。yum