Linux--基礎命令(2)
阿新 • • 發佈:2021-12-11
Linux基礎(2)
在Linux中沒有提示就是最好的結果
1、複製
copy 的縮寫 cp 格式: cp [引數] [被複制檔案的路徑] [複製到新的路徑] 引數: -r : 遞迴複製 -a : 抱枕某些屬性不變 案例1 : 將 /root目錄下的anaconda-ks.cfg複製到 /tmp目錄 [root@localhost China No.1 ~]#cp /root/anaconda-ks.cfg /tmp [root@localhost China No.1 ~]#ls /tmp 1.txt anaconda-ks.cfg 案例2 : 將 /root目錄下的test資料夾及其內部檔案複製到 /tmp中 [root@localhost China No.1 ~]#cp -r /root/test /tmp [root@localhost China No.1 ~]#ll /tmp total 16 -rw-r--r--. 1 root root 0 Dec 10 06:21 1.txt -rw-------. 1 root root 1704 Dec 10 06:06 anaconda-ks.cfg -rw-r--r--. 1 root root 0 Dec 10 03:01 anacond-ks.cfg drwxr-xr-x. 2 root root 6 Dec 10 03:05 host -rw-r--r--. 1 root root 158 Jun 7 2013 hosts drwxr-xr-x. 2 root root 6 Dec 10 03:02 test 案例3 : 將 /etc/hosts 和 /etc/resolv.conf 複製到 /tmp目錄中 [root@localhost China No.1 ~]#cp -ra /etc/hosts /etc/resolv.conf /tmp cp: overwrite ‘/tmp/resolv.conf’? y [root@localhost China No.1 ~]#ll /tmp total 16 -rw-------. 1 root root 1704 Dec 10 06:06 anaconda-ks.cfg -rw-r--r--. 1 root root 0 Dec 10 03:01 anacond-ks.cfg -rw-r--r--. 1 root root 158 Jun 7 2013 hosts 補充 :Esc + . 是上一條命令的最後一個元素 ls -l 等價於ll linux中的連線相當於快捷方式 stat : 檢視檔案詳細資訊
2、移動
移動檔案相當於剪下
格式:
mv [移動檔案的原路徑] [移動檔案的新路徑]
案例1:
將 /root目錄下的1.txt移動到 /opt目錄中
[root@localhost China No.1 ~]#touch 1.txt
[root@localhost China No.1 ~]#mv /root/1.txt /opt
[root@localhost China No.1 ~]#ls /opt
1.txt
3、刪除
刪除檔案有兩種方式: 1.物理刪除:之間刪除檔案 2.邏輯刪除:將檔案隱藏,沒有直接刪除 rm: 是一個物理刪除的命令 格式: rm [引數] [需要刪除檔案的路徑] 引數: -f : 不提示直接刪除 -r : 遞迴刪除目錄及其內容 -i : 每次移除前提示 案例1: 將 /root目錄下的1.txt刪除 [root@localhost China No.1 ~]#rm 1.txt rm: remove regular empty file ‘1.txt’? y [root@localhost China No.1 ~]#rm -f 1.txt 補充:在Linux系統中,不能夠直接刪除資料夾 Linux中禁止使用 rm -rf /* 解決rm命令誤操作 將rm命令改為另一個名稱 which :檢視命令存放地址
4、系統別名
alias
格式:
alias xxx='命令'
alisa : 檢視系統別名
alisa rm='xxx' : 設定系統別名
不使用別名,就在命令前加 \
[root@localhost China No.1 ~]#\rm -rf host
5、vi / vim編輯器
vim是vi的升級版編輯器。 1、安裝vim yum install vim -y 2、開啟編輯檔案 [root@localhost China No.1 ~]# vim 1.txt 3、vi編輯器中有三種模式 命令模式 末行模式 編輯模式 4、進入編輯模式 i : 在游標之前輸入 o :在游標處新建立一行 a :在游標之後輸入 5、儲存並退出 1、進入末行模式 2、操作 w : 儲存 q : 退出 ! : 強制(編寫的內容全部放棄) 6、解決vim編輯異常 1、刪除.1.txt.swp 2、繼續編輯(-r) [root@localhost China No.1 ~]# vim -r 1.txt 3、放棄編輯(-n) [root@localhost China No.1 ~]# vim -n 1.txt 7、游標快速移動快捷方式 ①. 快速切換游標到底行 G ②. 快速切換游標到首行 gg ③. 快速跳轉到行首 0 ④. 快速跳轉到行尾 $ ⑤. 快速跳轉到指定行 1、進入末行模式 2、輸入跳轉的行數 3、回車 ⑥. 快速複製文字內容資訊 yy nyy : 向下複製n行 ⑦. 快速貼上文字內容 p : 在游標的下一行貼上 P :在游標的上一行貼上 ⑧. 刪除文字內容 dd : 刪除游標所在行 ndd : 向下刪除n行 ⑨. 回撤 u ⑩. 撤回回撤 ctrl + r ⑪. 顯示行號 1、進入末行模式 2、輸入set nu 3、回車 ⑫. 取消行號 1、進入末行模式 2、輸入set nonu 3、回車 ⑬. 搜尋內容 1、進入命令模式 2、輸入/ 3、輸入搜尋的內容 4、回車 n : 下一個 N :上一個 :set ic : 忽略大小寫 ⑭. 視覺化編輯 1、ctrl + v 2、編輯:Shift + i 3、按 Esc鍵退出即可 知識儲備 實時監控檔案內容變化: tail -f [要監控的檔案] 演示vim編輯異常 1、檢視vim程序 [root@localhost China No.1 ~]# ps -ef | grep vim 2、殺死vim程序 [root@localhost China No.1 ~]# kill -9 pid 批量複製 [root@localhost China No.1 ~]# while true;do echo "Hello World" >> 1.txt; done