echo $PATH 打印當前的環境變量
PATH=$PATH:路徑 定義環境變量linux
[root@linux-128 ~]# which ls alias ls='ls --color=auto' /usr/bin/ls /usr/bin/
[root@linux-128 ~]# echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@linux-128 ~]# cp /usr/bin/ls /tmp/ls2 [root@linux-128 ~]# which ls2 /usr/bin/which: no ls2 in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)
[root@linux-128 ~]# /tmp/ls2 anaconda-ks.cfg [root@linux-128 ~]# /tmp/ls2 /usr/ bin etc games include lib lib64 libexec local sbin share src tmp
[root@linux-128 ~]# PATH=$PATH:/tmp/ [root@linux-128 ~]# ls2 /usr/ bin etc games include lib lib64 libexec local sbin share src tmp
[root@linux-128 ~]# vi /etc/profile 在最後面添加一行PATH=$PATH:/tmp/ for i in /etc/profile.d/*.sh ; do if [ -r "$i" ]; then if [ "${-#*i}" != "$-" ]; then . "$i" else . "$i" >/dev/null fi fi done unset i unset -f pathmunge PATH=$PATH:/tmp/
[root@linux-128 ~]# ls2 anaconda-ks.cfg
[root@linux-128 ~]# PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin [root@linux-128 ~]# echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
cp定一個規矩,拷貝目錄,都要加上/;安全
[root@linux-128 test]# ls 111 test1 test2 [root@linux-128 test]# touch 1.txt [root@linux-128 test]# cp 1.txt 2.txt [root@linux-128 test]# ls 111 1.txt 2.txt test1 test2
[root@linux-128 test]# cp -r test1/ 333/ [root@linux-128 test]# ls 111 1.txt 2.txt 333 test1 test2
[root@linux-128 test]# cp 1.txt 2.txt cp:是否覆蓋"2.txt"? [root@linux-128 test]# echo '111'>> 1.txt // >>追加劇定向 [root@linux-128 test]# echo '222'>> 2.txt [root@linux-128 test]# cat 1.txt 111 [root@linux-128 test]# cat 2.txt 222 [root@linux-128 test]# /bin/cp 1.txt 2.txt //用絕對路徑就不會提示覆蓋 [root@linux-128 test]# cat 2.txt 111
[root@linux-128 test]# cp -v 2.txt 111/ "2.txt" -> "111/2.txt"
[root@linux-128 test]# ls 222 2.txt 333 test1 test2 [root@linux-128 test]# mv 222 111 [root@linux-128 test]# ls 111 2.txt 333 test1 test2 意思:將目錄222重命名爲111;源目錄消失
[root@linux-128 test]# ls 111 2.txt 333 test1 test2 [root@linux-128 test]# mv 111 333 [root@linux-128 test]# ls 2.txt 333 test1 test2 [root@linux-128 test]# ls 333 111 意思:將目錄111移動到目錄333下
[root@linux-128 test]# ls 2.txt 333 test1 test2 [root@linux-128 test]# mv 2.txt 3.txt [root@linux-128 test]# ls 333 3.txt test1 test2 意思:將文件2.txt重名命爲3.txt;源文件消失
[root@linux-128 test]# ls 1.txt 333 3.txt test1 test2 [root@linux-128 test]# mv 1.txt 3.txt mv:是否覆蓋"3.txt"? y [root@linux-128 test]# ls 333 3.txt test1 test2 意思:將文件1.txt重命名爲3.txt,源文件消失
[root@linux-128 ~]# cat -n /etc/passwd 1 root:x:0:0:root:/root:/bin/bash 2 bin:x:1:1:bin:/bin:/sbin/nologin 3 daemon:x:2:2:daemon:/sbin:/sbin/nologin 4 adm:x:3:4:adm:/var/adm:/sbin/nologin 5 lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin 6 sync:x:5:0:sync:/sbin:/bin/sync 7 shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown 8 halt:x:7:0:halt:/sbin:/sbin/halt 9 mail:x:8:12:mail:/var/spool/mail:/sbin/nologin 10 operator:x:11:0:operator:/root:/sbin/nologin
[root@linux-128 ~]# cat -A /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$
[root@linux-128 ~]# tac /tmp/test/3.txt operator:x:11:0:operator:/root:/sbin/nologin mail:x:8:12:mail:/var/spool/mail:/sbin/nologin halt:x:7:0:halt:/sbin:/sbin/halt shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown sync:x:5:0:sync:/sbin:/bin/sync lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin bin:x:1:1:bin:/bin:/sbin/nologin root:x:0:0:root:/root:/bin/bash
查看一個文件的內容,當文件內容太多,一屏顯示不能顯示時,按空格能夠據需查看bash
和more命令同樣,直接跟文件名,可是比more功能更多less
用於顯示文件的前10行,後面直接跟文件名;ssh
[root@linux-128 ~]# head -n2 /tmp/test/3.txt root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin
[root@linux-128 ~]# head –n 5 /tmp/test/3.txt 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 [root@linux-128 ~]# head -5 /tmp/test/3.txt 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
[root@linux-128 ~]# tail /etc/passwd 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 wuzhou:x:1000:1000::/home/wuzhou:/bin/bash
[root@linux-128 ~]# tail -n2 /etc/passwd chrony:x:997:995::/var/lib/chrony:/sbin/nologin wuzhou:x:1000:1000::/home/wuzhou:/bin/bash