>PATH说简单点就是一个字符串变量(该字符串内容是一个命令的绝对路径),当输入命令的时候LINUX会去查找PATH里面记录的路径。centos
PATH这个变量包含了一系列由冒号分隔开的目录,系统就从这些目录里寻找可执行文件。若是你输入的可执行文件(例如ls、rm)不在这些目录中,系统就没法执行它(除非你输入这个命令的完整路径,如/bin/ls)。安全
# echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin 默认
当一个命令在PATH中存在的时候,无需使用其绝对路径,eg:rm、ls、cd等等。bash
# PATH=$PATH:/tmp/ # echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/tmp/
注: 以上只是临时增长一个变量。若是想要永久添加变量还须要执行如下命令:less
# vi /etc/profile 编辑配置文件,在该文件内容最后一行添加PATH=$PATH:/tmp/
eg2: 删除环境变量
方法1:ssh
# PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin 让PATH等于其默认值便可! # echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin 默认
方法2:post
# vi /etc/profile 编辑该配置文件,在内容中删除“PATH=$PATH:/tmp/”便可!
cp=copy
语法: cp [选项] [源文件] [目标文件]
选项:
-r 拷贝目录
-i 安全选项,相似于rm命令,若是遇到一个存在的文件,会询问是否覆盖。centos系统默认cp=cp -i。
注: 当目标目录已存在的时候,cp命令会把源目录放到目标目录下面;当目标目录不存在的时候,cp命令会把源目录重命名后放到目标目录的位置!spa
例如我想把 test1 拷贝成 test2,这样便可cp test1 test2;code
例如我想把 test1 拷到 test2,但test2存在,这样test22会被放到test21下面;文档
!$ 表示上一个命令的最后一个参数;字符串
在对目录文件进行编辑的时候,命令末尾加"/";对非目录文件进行编辑的时候没必要加!
# mkdir dira dirb 建立目录dira和dirb # ls anaconda-ks.cfg dira dirb install.log install.log.syslog # mv dira dirc 移动目录dira到dirc目录(该目录不存在)下 # ls anaconda-ks.cfg dirb dirc install.log install.log.syslog 目标文件dirc为目录,而且目标目录不存在,至关于把dira重命名为dirc
2)目标文件是目录,并且目标文件存在(=移动)
# mv dirc dirb 移动目录dirc到目录dirb(两个目录均存在) # ls anaconda-ks.cfg dirb install.log install.log.syslog # ls dirb dirc 目标文件dirc为目录,且目标目录存在,则会把dirc移动到dira目录里
3)目标文件不是目录不存在 (=重命名--把源文件命名为目标文件的名字)
# touch filed 建立文件filed # ls anaconda-ks.cfg dirb filed install.log install.log.syslog # mv filed filee 把源文件filed移动到filee # ls anaconda-ks.cfg dirb filee install.log install.log.syslog 目标文件filee不是目录且不存在,至关于把filed文件重命名为filee
4)目标文件不是目录存在
①移动至某目录下(=移动)
# mv filee dirb 移动文件filee到dirb下 # ls anaconda-ks.cfg dirb install.log install.log.syslog # ls dirb dirc filee 目标文件不是目录,且存在则会把源文件移动
②移动至另外一个非目录目标文件 (=删除源文件)
[root@3 dir1]# ls dir2 file1 file2 [root@3 dir1]# mv file2 file1 移动非目录文件file2到非目录文件file2 mv:是否覆盖"file1"? y [root@3 dir1]# ls dir2 file1 移动非目录文件file2到非目录文件file1,至关于删除文件file2(源文件)
mv bash mvtest/1 将文件bash移动到目录mvtest下并改名为1
mv test/ test1/ 将目录test改名为test1
PS :(与cp命令相同,若是目标目录存在,则会把原目录放到目标目录下,若是目标目录不存在,则把原目录改名为目标目录名字)
mv mvtest.txt mvtest2.txt 将文件mvtest改名为mvtest2
# echo 'aaaaa'>dirb/filee 将“aaaaa”写入filee文件 # echo 'ccccc'>>dirb/filee 将“ccccc”写入filee文件 # cat dirb/dilee aaaaa ccccc # cat -n dirb/dilee 1 aaaaa 2 ccccc
注: “>>”和“>”都是从新定向的做用,即把前面输出的东西输入到后面的文件中,只不过“>>”是追加的意思,而使用“>”时,若是文件中有内容会把内容删除,“>>”则不会。
2)-A 显示全部东西出来,包括特殊字符
eg:
# cat -A dirb/filee aaaaa$ ccccc$ 在此"$"是结束符号
# tac dirb/filee ccccc aaaaa
# head /etc/passwd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt mail:x:8:12:mail:/var/spool/mail:/sbin/nologin operator:x:11:0:operator:/root:/sbin/nologin # head -n3 !$ head -n3 /etc/passwd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin
# tail /etc/passwd ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin nobody:x:99:99:Nobody:/:/sbin/nologin systemd-bus-proxy:x:999:997:systemd Bus Proxy:/:/sbin/nologin systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin dbus:x:81:81:System message bus:/:/sbin/nologin polkitd:x:998:996:User for polkitd:/:/sbin/nologin tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin postfix:x:89:89::/var/spool/postfix:/sbin/nologin sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin chrony:x:997:995::/var/lib/chrony:/sbin/nologin # tail -n3 /etc/passwd postfix:x:89:89::/var/spool/postfix:/sbin/nologin sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin chrony:x:997:995::/var/lib/chrony:/sbin/nologin