bin ---- 命令,二進制文件的存放目錄 boot ----- 系統引導程序+系統的內核 dev ---- 設備 硬盤,光驅 etc ---- 存儲系統或者服務的配置文件 home ---- 普通用的家目錄,貧民窟 lib ----- 庫文件存放目錄 lib64 ---- 庫文件的存放目錄(64位系統) media ---- linux識別的設備,比如u盤等,掛這個目錄 mnt ----- 臨時的掛載點目錄 opt ----- 第三方的軟件安裝在整理 proc ----- 虛擬目錄,顯示內存中的信息(進場,內核的信息) root ----- root的家目錄 相當於皇宮 run ----- 放的啟動的東西 sbin --- 超級命令,只用root用戶才能用的命令 srv ----- service的縮寫,存放的是一些啟動后需要的數據 sys ------ 虛擬目錄,內存信息 tmp ----- 臨時文件的存放位置 usr ---- 存放用戶的程序 var ----- 存放經常變化的文件,比如日志等
解釋:pwd = print working directory 顯示當前所在的目錄 [root@localhost run] # pwd /run [root@localhost network-scripts]# pwd /etc/sysconfig/network-scripts
解釋: cd ---> change directory 改變目錄信息 ##注意點 /目錄 表示絕對路徑 ; 目錄 表示相對路徑 #絕對路徑的方式 [root@localhost run]# cd /etc/sysconfig/network-scripts/ [root@localhost network-scripts]# pwd /etc/sysconfig/network-scripts [root@localhost network-scripts]# cd /etc [root@localhost etc]# cd /etc [root@localhost etc]# cd /home [root@localhost home]# pwd /home #相對路徑的方式 [root@localhost home]# cd /etc [root@localhost etc]# cd sysconfig/ [root@localhost sysconfig]# pwd /etc/sysconfig # 快速回到進入自己的家目錄 [root@localhost sysconfig]# cd ~ [root@localhost ~]# pwd /root [root@localhost ~]# cd /root [root@localhost ~]# pwd /root [root@localhost ~]# [root@localhost ~]# cd /etc/sysconfig/network-scripts/ [root@localhost network-scripts]# cd # 回到家目錄 [root@localhost ~]# # 快速回到自己進過的目錄 [root@localhost ~]# cd /etc/sysconfig/ [root@localhost sysconfig]# cd /bin [root@localhost bin]# pwd /bin [root@localhost bin]# cd - /etc/sysconfig [root@localhost sysconfig]# pwd /etc/sysconfig [root@localhost sysconfig]# #返回當前路徑的上一級目錄 [root@localhost lib]# cd /etc/sysconfig/network-scripts/ [root@localhost network-scripts]# pwd /etc/sysconfig/network-scripts [root@localhost network-scripts]# cd ../ [root@localhost sysconfig]# pwd /etc/sysconfig [root@localhost sysconfig]# cd /etc/sysconfig/network-scripts/ [root@localhost network-scripts]# cd ../../ [root@localhost etc]# pwd /etc [root@localhost etc]# cd /etc/sysconfig/network-scripts/ [root@localhost network-scripts]# cd ../../../../../../../../../ [root@localhost /]# pwd /
mkdir ---> make directory [root@localhost /]# cd /oldboy -bash: cd: /oldboy: No such file or directory [root@localhost /]# mkdir /oldboy [root@localhost /]# cd /oldboy/ [root@localhost oldboy]# pwd /oldboy #用-p參數創建多級目錄 [root@localhost oldboy]# mkdir /oldboy/olddog/jason mkdir: cannot create directory ‘/oldboy/olddog/jason’: No such file or directory [root@localhost oldboy]# mkdir /oldboy/olddog [root@localhost oldboy]# mkdir /oldboy/olddog/jason [root@localhost oldboy]# cd /oldboy/olddog/jason/ [root@localhost jason]# pwd /oldboy/olddog/jason [root@localhost jason]# cd / [root@localhost /]# mkdir -p /oldboy/oldgirl/tank [root@localhost /]# cd /oldboy/oldgirl/tank/ [root@localhost tank]# pwd /oldboy/oldgirl/tank #我們在創建目錄的時候最好是用絕對路徑
[root@localhost tank]# cd /oldboy/ [root@localhost oldboy]# pwd /oldboy [root@localhost oldboy]# touch oldboy.txt [root@localhost oldboy]# ls oldboy.txt olddog oldgirl [root@localhost oldboy]# touch /oldboy/olddog/jj [root@localhost oldboy]# ls /oldboy/olddog/ jason jj #在linux里面不會通過后綴名來區分文件的類型,但是我們約定,你什么樣的文件,就用什么后綴名,免得搞不清楚
ls ----> list [root@localhost /]# cd oldboy/ [root@localhost oldboy]# ls oldboy.txt olddog oldgirl [root@localhost oldboy]# ls ol # 判斷有沒有改文件或文件夾 ls: cannot access ol: No such file or directory [root@localhost oldboy]# ls -l total 0 -rw-r--r--. 1 root root 0 Mar 24 18:09 oldboy.txt drwxr-xr-x. 3 root root 29 Mar 24 18:10 olddog drwxr-xr-x. 3 root root 18 Mar 24 18:06 oldgirl [root@localhost oldboy]# ls -ltr total 0 drwxr-xr-x. 3 root root 18 Mar 24 18:06 oldgirl -rw-r--r--. 1 root root 0 Mar 24 18:09 oldboy.txt drwxr-xr-x. 3 root root 29 Mar 24 18:10 olddog [root@localhost oldboy]# ls -lt total 0 drwxr-xr-x. 3 root root 29 Mar 24 18:10 olddog -rw-r--r--. 1 root root 0 Mar 24 18:09 oldboy.txt drwxr-xr-x. 3 root root 18 Mar 24 18:06 oldgirl # ls -l 默認是創建時間最新到最老排序(測試是按照文件名排序) # ls -lt 創建時間最新到最老排序 # ls -ltr 創建時間最老到最新排序 ls -a 表示查看當前文件夾底下的所有文件,包括隱藏文件
# cat 是查看文件信息 [root@localhost oldboy]# cat /oldboy/oldboy.txt 123 [root@localhost oldboy]# cat oldgirl.txt 456 #查看多個文件的文件信息 [root@localhost oldboy]# cat oldboy.txt oldgirl.txt 123 456 # 將文件中的內容讀取出來,放入到另一個文件中 [root@localhost oldboy]# cat oldboy.txt oldgirl.txt > jason.txt # 創建並覆蓋寫入 >>為接着寫入 [root@localhost oldboy]# cat jason.txt 123 456
# 直接輸出信息 [root@localhost oldboy]# echo "hello world" hello world # 將echo的內容寫入到文件 ,> 是覆蓋寫入,>> 是追加寫入 [root@localhost oldboy]# echo "hello world" > lxx.txt # 創建並覆蓋寫入 [root@localhost oldboy]# ls jason.txt lxx.txt oldboy.txt olddog oldgirl oldgirl.txt [root@localhost oldboy]# cat lxx.txt hello world [root@localhost oldboy]# echo "hello world" > lxx.txt [root@localhost oldboy]# cat lxx.txt hello world [root@localhost oldboy]# echo "hello world" >> lxx.txt [root@localhost oldboy]# cat lxx.txt hello world hello world
# cp --->copy 語法格式: cp 參數(可選) 要復制的信息 復制到什么位置 # 在復制文件。在復制文件的時候,要復制的文件不要加/,一般是只能復制目錄的時候加/ [root@localhost oldboy]# cp /etc/hosts /oldboy/ [root@localhost oldboy]# ls hosts jason.txt lxx.txt oldboy.txt olddog oldgirl oldgirl.txt [root@localhost oldboy]# cat hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 [root@localhost oldboy]# cp /etc/hosts /oldboy/ # 復制文件夾已存在該文件 cp: overwrite ‘/oldboy/hosts’? y # 是否覆蓋 # 復制文件夾 [root@localhost sysconfig]# cp /etc/sysconfig/ /oldboy/oldgirl cp: omitting directory ‘/etc/sysconfig/’ [root@localhost sysconfig]# cp -r /etc/sysconfig/ /oldboy/oldgirl #復制整個文件夾 -r遞歸里面所有 [root@localhost sysconfig]# cd /oldboy/oldgirl [root@localhost oldgirl]# ls sysconfig tank [root@localhost oldgirl]# cd /oldboy/oldgirl/sysconfig/ [root@localhost sysconfig]# pwd /oldboy/oldgirl/sysconfig cp :的參數 -r 進行遞歸復制 -p 拷貝是時候屬性保存不變 -d 和鏈接相關的文件 -a == -drp # 全部 # 利用cp做備份 [root@localhost oldboy]# cat jason.txt 123 456 [root@localhost oldboy]# cp jason.txt jason.txt.bak # 一般備份文件以.bak命名 [root@localhost oldboy]# ls hosts jason.txt jason.txt.bak lxx.txt oldboy.txt olddog oldgirl oldgirl.txt [root@localhost oldboy]# rm -rf jason.txt [root@localhost oldboy]# ls hosts jason.txt.bak lxx.txt oldboy.txt olddog oldgirl oldgirl.txt [root@localhost oldboy]# cp jason.txt.bak jason.txt [root@localhost oldboy]# ls hosts jason.txt jason.txt.bak lxx.txt oldboy.txt olddog oldgirl oldgirl.txt [root@localhost oldboy]# cat jason.txt 123 456 # 如果cp的時候,多個文件覆蓋,會出現多次確定,如何避免 [root@localhost oldboy]# cp -r /etc/sysconfig/ /oldboy/oldgirl cp: overwrite ‘/oldboy/oldgirl/sysconfig/ip6tables-config’? y cp: overwrite ‘/oldboy/oldgirl/sysconfig/iptables-config’? y cp: overwrite ‘/oldboy/oldgirl/sysconfig/cbq/avpkt’? ^C #解決辦法 \cp 不重復提示 [root@localhost oldboy]# \cp -r /etc/sysconfig/ /oldboy/oldgirl
mv --move 對文件或者文件夾進行剪切(移動) 語法格式: mv 要移動的文件或者文件夾 移動要什么位置 #在根目錄創建test文件夾,然后創建heihei.txt [root@localhost oldboy]# mkdir /test [root@localhost oldboy]# cd /test [root@localhost test]# touch heihei.txt # 將 /test/heihei.txt文件 剪切(移動)到/oldboy/shanghai/的文件夾, [root@localhost test]# mv /test/heihei.txt /oldboy/shanghai/ mv: cannot move ‘/test/heihei.txt’ to ‘/oldboy/shanghai/’: Not a directory #創建/oldboy/shanghai文件夾 [root@localhost test]# mkdir /oldboy/shanghai [root@localhost test]# mv /test/heihei.txt /oldboy/shanghai/ [root@localhost test]# cd /oldboy/shanghai [root@localhost shanghai]# ls heihei.txt #原來的/test/heihei.txt文件消失 [root@localhost shanghai]# cd /test [root@localhost test]# ls # 將 /test/heihei.txt文件 剪切(移動)到/oldboy/shanghai,如果不加/,表示將heihei.txt文件內容寫入 shanghai,文件,並將名字改成shanghai # 在linux系統沒有重命名這個東西,我們可以同mv 命令實現 [root@localhost oldboy]# ls hosts jason.txt jason.txt.bak lxx.txt oldboy.txt olddog oldgirl oldgirl.txt shanghai [root@localhost oldboy]# mv lxx.txt lxxsb.txt [root@localhost oldboy]# ls hosts jason.txt jason.txt.bak lxxsb.txt oldboy.txt olddog oldgirl oldgirl.txt shanghai
rm --->remove 語法:rm 參數 要刪除的數據信息 #刪除文件 [root@localhost ~]# cd /oldboy/ [root@localhost oldboy]# ls hosts jason.txt jason.txt.bak lxxsb.txt oldboy.txt olddog oldgirl oldgirl.txt shanghai [root@localhost oldboy]# rm jason.txt.bak rm: remove regular file ‘jason.txt.bak’? y [root@localhost oldboy]# ls hosts jason.txt lxxsb.txt oldboy.txt olddog oldgirl oldgirl.txt shanghai # 刪除文件夾 [root@localhost oldboy]# rm shanghai rm: cannot remove ‘shanghai’: Is a directory [root@localhost oldboy]# rm -r shanghai rm: descend into directory ‘shanghai’? y rm: remove regular empty file ‘shanghai/heihei.txt’? y rm: remove directory ‘shanghai’? y #強行刪除 [root@localhost oldboy]# ls hosts jason.txt lxxsb.txt oldboy.txt olddog oldgirl oldgirl.txt [root@localhost oldboy]# rm -f oldboy.txt # -f不提醒,保存刪除文件不存在 [root@localhost oldboy]# rm -rf olddog [root@localhost oldboy]# ls hosts jason.txt lxxsb.txt oldgirl oldgirl.txt #centos7這個命令會保護 rm -rf / #rm -rf /* 不受保護
vim三種模式切換
#安裝之前先切換鏡像源 https://developer.aliyun.com/mirror/centos?spm=a2c6h.13651102.0.0.3e221b11yCmuQx # 要用vim要安裝 #命令:yum -y install vim 或者 yum install vim -y # -y表示確定 # vim 是編輯器,他有三種狀態 1 正常模式 vim 文件 進入后就vim的正常模式,從正常如何進入編輯模式,輸入 i,o,a,I,O,A,R,都可以,但是 我們只要記住一個i,因為方便記憶。 正常模式底下的命令: 拷貝: yy 粘貼:p # 光標所在行復制,並在光標下一行粘貼 拷貝當前行向下2行,並粘貼 拷貝2行:2yy 粘貼:p 刪當前行: 刪除:dd 刪除當前的下兩行: 刪除:2dd
刪除下方所有行:dG 光標移動到最后一行:G 光標移到首行:gg ggdG即全刪 光標移到第二行:2gg 撤回:u 2 插入模式 進入編輯模式,就可以直接輸入內容。 3 命令模式 1 查找內容: :/關鍵字 2 取消高亮: :nohl 3 顯示行號: :set nu 4 取消行號 :set nonu 5 沒有修改情況下退出 :q 6 如果修改了,但我們不想保存, :q! 7 如果修改,並且想保存, :wq # 如果發現vim 不能編輯這個文件 # 原因為linux非正常關機時產生的.swp文件 # 我在這個文件所在目錄執行: ls -a # 你會發現有一個 .文件名.swp的隱藏文件 .開頭為隱藏文件 #我們執行刪除命令將其刪除:rm -rf .文件名.swp