- which 能夠查看命令所在的路徑
- which查詢的路徑是經過如下的路徑,進行查詢
[root@aminglinux-01 ~]# echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@hf-01 ~]# which ls 查看ls所在路徑 alias ls='ls --color=auto' /usr/bin/ls [root@hf-01 ~]# ls /usr/bin/ls /usr/bin/ls [root@hf-01 ~]# cp /usr/bin/ls /tmp/ls2 複製/usr/bin/ls路徑到/tmp/ls2下 [root@hf-01 ~]# /tmp/ls2 使用命令/tmp/ls2查看結果,會發現和ls命令出來的結果同樣 anaconda-ks.cfg [root@hf-01 ~]# ls anaconda-ks.cfg [root@ahf-01 ~]# ls2 執行ls2命令,會提示未找到命令,由於這個命令不在上述目錄裏面 -bash: ls2:未找到命令 [root@hf-01 ~]# PATH=$PATH:/tmp/ 若想直接運行ls2命令,須要改變環境變量 從新給PATH賦值 [root@hf-01 ~]# echo $PATH 會發現多出了/tmp/ /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/tmp/ [root@hf-01 ~]# ls2 這時在運行發現就能夠執行了 anaconda-ks.cfg [root@hf-01 ~]# which ls2 /tmp/ls2
1.在系統 vi /etc/profile (在開機、打開終端都會加載這個命令) 2.結尾處加上PATH=$PATH:/tmp/ 並保存退出 3.在使用cat /etc/profile查看下是否加載成功 4.這時echo $PATH會獲得/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/tmp/:/root/bin 如今無論哪個終端均可以執行ls2命令,都會執行成功
若不想要這個ls2命令了,有兩種方法。mysql
方法一:從新賦值linux
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin (去除:/tmp/) 這時在執行ls2命令,就會失效
方法二:從新編輯文件/etc/profileredis
快捷鍵dd命令,刪除PATH=$PATH:/tmp/並:wq保存 在去新建終端,執行echo $PATH 就會發現/tmp/目錄消失了
cp = copysql
將源文件 拷貝成目標文件 cp -r 拷貝目錄 統一約定, 使用cp 和其餘命令的時候,把 路徑後的/補充完整 !$ 上一條命令中最後的一個參數,以空格或歎號分割 [root@hf-01 ~]# which cp alias cp='cp -i' /usr/bin/cp 這裏會看到cp 命令默認帶有一個 -i 選項, 它是屬於安全選項,詢問操做是否進行下一步操做 若不想複製的時候,天天去詢問,能夠按以下複製 [root@hf-01 ~]# /usr/bin/cp /etc/passwd /tmp/1.txt
[root@hf-01 ~]# cp /etc/passwd /tmp/1.txt 拷貝文件直接複製便可 cp:是否覆蓋"/tmp/1.txt"? y [root@hf-01 ~]# cp -r /tmp/aminglinux/ /tmp/amning 拷貝目錄須要加-r選項 [root@hf-01 ~]# cp -r /tmp/aminglinux/ /tmp/aming1/ [root@hf-01 ~]# tree !$ 這表示上一條命令的最後一條參數 tree /tmp/aming1/ /tmp/aming1/ └── 2 └── 2.txt 1 directory, 1 file [root@hf-01 ~]# !tree tree /tmp/aming1/ /tmp/aming1/ └── 2 └── 2.txt 1 directory, 1 file [root@hf-01 ~]# tree /tmp/aming1/ /tmp/aming1/ └── 2 └── 2.txt 1 directory, 1 file [root@hf-01 ~]# cp -r /tmp/aminglinux/ /tmp/aming1/ [root@hf-01 ~]# ls /tmp/aming1/ 2 aminglinux 這說明,當目標目錄已經存在的時候,他會把源目錄放在目標目錄下面去, 若是目標目錄不存在,他會把源目錄拷貝過來,並修更名稱 [root@hf-01 ~]# tree /tmp/aming1/ /tmp/aming1/ ├── 2 │ └── 2.txt └── aminglinux └── 2 └── 2.txt 3 directories, 2 files [root@hf-01 ~]# cp -r /tmp/aminglinux/ /tmp/aming1/ cp:是否覆蓋"/tmp/aming1/aminglinux/2/2.txt"? n 當再次拷貝相同目錄的時候,就會提示是否須要覆蓋,這時由於源目錄已經存在
在cp拷貝目錄的時候,在目錄後面統一加上/,由於在後面有一種命令中加/和不加/是有很大區別的安全
- 當目標目錄已經存在的時候,他會把源目錄放在目標目錄下面去,若是目標目錄不存在,他會把源目錄拷貝過來,並修更名稱
- 當再次拷貝相同目錄的時候,就會提示是否須要覆蓋,這時由於源目錄已經存在
[root@hf-01 ~]# mv anaconda-ks.cfg anaconda-ks.cfg.1 這裏就是直接修改文件名 [root@hf-01 ~]# ls anaconda-ks.cfg.1 [root@hf-01 ~]# cd /tmp/ [root@hf-01 tmp]# ls 1.txt aming1 aminglinux amning mysql.sock [root@hf-01 tmp]# mv aming1/ aming/ [root@hf-01 tmp]# ls aming aminglinux amning mysql.sock [root@hf-01 tmp]# mv aming/ aming2/ 若把目錄移動到當前一個不存在的目錄,則會修更名稱 [root@hf-01 tmp]# ls aming2 aminglinux amning mysql.sock [root@hf-01 tmp]# mv aming2/ aminglinux/ 若是目標目錄存在了,就會把源目錄放到目標目錄下面去 [root@hf-01 tmp]# ls aminglinux/ 2 aming2
cat 這個查看文件內容的 -A 顯示文件的全部文件(包括字符) -n 顯示行號 tac 倒序查看文件內容,與cat相反 more 也是用來查看文件內容,可是不會像cat同樣一下所有顯示出來,他的顯示方式爲一屏一屏的顯示, (可以使用空格鍵查看下一行或ctrl+b 能夠往前看,內容查看完之後會自動結束命令的運行) wc -l 能夠查看文件的行數 [root@localhost ~]# wc -l anaconda-ks.cfg.1 51 anaconda-ks.cfg.1 顯示改文件的行數
[root@localhost ~]# wc -l anaconda-ks.cfg.1 51 anaconda-ks.cfg.1 [root@localhost ~]# cat /etc/passwd >> anaconda-ks.cfg.1 這就是把/etc/passwd中的文件內容增長到anaconda-ks.cfg.1文件中去 [root@localhost ~]# cat /etc/passwd >> anaconda-ks.cfg.1 [root@localhost ~]# wc -l anaconda-ks.cfg.1 93 anaconda-ks.cfg.1 [root@localhost ~]# cat /etc/passwd >> anaconda-ks.cfg.1 [root@localhost ~]# cat /etc/passwd >> anaconda-ks.cfg.1
[root@localhost ~]# more anaconda-ks.cfg.1 #version=DEVEL # System authorization information auth --enableshadow --passalgo=sha512 # Use CDROM installation media cdrom # Use graphical install 此處省略....
head 查看文件的前 10行 (默認10行) -n 數字 (指定查看文件的多少行) tail 查看文件的尾部,最後 10行 -f 動態顯示文件 -n 數字 顯示文件以數字爲單位的行數(頭幾行,爲幾行)
[root@localhost ~]# head anaconda-ks.cfg.1 #version=DEVEL # System authorization information auth --enableshadow --passalgo=sha512 # Use CDROM installation media cdrom # Use graphical install graphical # Run the Setup Agent on first boot firstboot --enable ignoredisk --only-use=sda [root@localhost ~]# head -n 2 anaconda-ks.cfg.1 #version=DEVEL # System authorization information [root@localhost ~]# tail -n 2 anaconda-ks.cfg.1 sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin chrony:x:997:995::/var/lib/chrony:/sbin/nologin