Linux系列:Linux常用磁盤命令、文件命令!

      網友投稿 798 2025-03-31

      目錄


      1、知識引入

      2、linux操作系統的產生過程

      3、linux優點

      4、linux體系結構

      5、linux內核及發行版本

      6、文件系統和目錄結構

      7、終端和常用命令

      8、磁盤命令

      9、文件命令

      10、其他常用命令

      11、案例講解

      1、知識引入

      windows 桌面系統/服務器端

      linux 服務器端

      mac/unix

      android/ios

      桌面系統:主要是面對大眾用戶,以美觀、易用為原則,有圖形化界面。

      服務器端:知道使用命令行進行調試的那個小黑窗口,就知道什么是服務器端。

      剛剛買回來的計算機:僅有硬件;

      硬件:主要包括CPU、內存、主板、硬盤驅動器、光盤驅動器、各種擴展卡、連接線、電源等;外部設備包括鼠標、鍵盤等。

      只有裝上了操作系統、應用軟件后,才使得電腦世界變得豐富多彩;

      僅有硬件(裸機)

      操作系統軟件:windows系統

      應用軟件:qq、微信

      操作系統的作用是什么?為什么不在硬件上面直接安裝“應用軟件”,還需要安裝一個操作系統呢?

      操作系統可以提供磁盤管理、內存管理、資源調度,避免雜亂無章。

      什么是linux?

      1)Linux操作系統屬于開源操作系統,主要應用于服務器端。

      2)基于posix和unix的多用戶、多任務、多線程和多cpu的操作系統。

      3)Linux繼承了UNIX以網絡為核心的設計思想,是一個性能穩定的多用戶的網絡操作系統。

      2、linux操作系統的產生過程

      注意:linux之所以叫做linux,這個名字是由linus和unix組合而來的。

      3、linux優點

      1)分時多用戶和多任務的操作系統;

      2)多數網絡協議支持、方便的遠程管理

      3)強大的內存管理和文件系統管理;

      4)大量可用的軟件和免費的軟件;

      5)優良的穩定性和安全性;

      6)良好的可移植性和靈活性;

      7)可供選擇的廠商多;

      4、linux體系結構

      5、linux內核及發行版本

      Linux內核:內核建立了計算機軟件與硬件之間通訊的平臺,內核提供系統服務,比如文件管理、虛擬內存、設備I/O、進程管理等。“軟件調用內核,內核操作硬件”

      內核版:是系統的心臟,用于運行程序和管理硬件的核心。內核通過系統調用來管理計算機硬件,而終端命令用來檢測系統調用是否正確,使得更加方便的調用計算機硬件。系統調用主要是方便程序間接訪問計算機硬件。

      發行版:發行版包含了Linux內核,發行版就是在Linux內核之上再搭建一套應用程序,有桌面管理程序,視頻播放程序等一套程序。因為Linux內核已經實現了跟計算機硬件進行交互,所以發行版可以通過系統內核的系統調用來跟計算機硬件進行訪問,大大縮短了開發系統的時間。

      發行版本:

      6、文件系統和目錄結構

      Windows : NTFS(FAT16 FAT32) Linux: centos5 : ext3 文件系統 centos6 : ext4 文件系統 centos7 : xfs 文件系統

      ① linux中所有的內容,都是文件。

      ② 目錄或者文件的名稱長度不超過255個字符,文件或目錄是由以下字符構成:

      大寫字母(A-Z)、小寫字母(a-z)、數字(0-9)

      下劃線(_) 、句點(.) 、逗號(,)

      注意:文件和目錄是區分大小寫的。

      ③ Linux文件系統沒有擴展名,添加擴展名僅僅是幫助我們區分,不同的文件表示的是什么,文件的真實類型(文件還是目錄)是通過【文件中的內容】決定的。

      ④ 目錄結構

      樹結構如下:

      注意:/(根目錄)底下的二級目錄不要刪除、也不要添加目錄。

      使用建議:

      7、終端和常用命令

      [root@image_boundary ~]# ls -l anaconda-ks.cfg -rw------- 1 root root 1598 Sep 17 15:57 anaconda-ks.cfg

      為大家奉上linux命令大全寶貝網站:http://man.linuxde.net/

      8、磁盤命令

      cd 相對路徑/絕對路徑。利用相對路徑或絕對路徑,切換到某個目錄之下; cd . 表示當前路徑; cd .. 返回上一層目錄; cd ~ 若為root用戶,就是切換到root用戶的家目錄【/root】; 若為普通用戶,就是切換到普通用戶的家目錄【/home/普通用戶名】; cd / 直接返回到"/"根目錄; cd - 返回上一次操作目錄;"(這個很好用)"

      操作如下:

      [root@image_boundary ~]# cd / [root@image_boundary /]# cd home [root@image_boundary home]# cd ../usr [root@image_boundary usr]# cd - /home [root@image_boundary home]# cd .. [root@image_boundary /]# pwd / [root@image_boundary ~]# su hadoop [hadoop@image_boundary root]$ cd ~ [hadoop@image_boundary ~]$ pwd /home/hadoop

      [root@image_boundary /]# pwd / [root@image_boundary /]# cd ~ [root@image_boundary ~]# pwd /root [hadoop@image_boundary ~]$ pwd /home/hadoop

      -l:展示詳細信息

      -a:查看隱藏內容。(顯示以.開頭的那些文件)

      -A:查看隱藏文件。(顯示.開頭的那些文件,與a不同的是不顯示.和…)。“注意:.表示當前文件夾 …表示上一級文件夾”

      -h:友好的方式展示(文件以K、M…結尾)

      -R:遞歸展示所有文件。

      常用組合操作:ls -l 可以簡化為ll。ll -h 顯示文件的具體信息,并以友好的方式展示。

      操作如下:

      [root@image_boundary ~]# ls -l 可以寫成ll total 108 -rw-r--r--. 1 root root 9 Sep 17 19:10 aa.txt~ -rw-------. 1 root root 1598 Sep 17 15:57 anaconda-ks.cfg [root@image_boundary ~]# ls -lh 可以寫成ll -h total 108K -rw-r--r--. 1 root root 9 Sep 17 19:10 aa.txt~ -rw-------. 1 root root 1.6K Sep 17 15:57 anaconda-ks.cfg

      -a:展示所有內容

      -h:友好方式展示

      -s:統計所有文件所占用空間總的大小

      du -h:會遞歸顯示當前文件夾及其子文件夾的占用空間大小。

      du -h a.txt:會顯示指定文件a.txt的占用空間大小。

      du -h aa:會顯示指定文件夾aa的占用空間大小。

      du -sh:會顯示當前文件夾下,所以文件的占用空間大小

      操作如下:

      [root@image_boundary Desktop]# ll total 8 drwxr-xr-x. 2 root root 4096 Oct 15 20:02 aa drwxr-xr-x. 2 root root 4096 Oct 15 20:05 bb [root@image_boundary Desktop]# du -sh 28K .

      -h:友好方式展示

      -a:顯示全部的文件系統;

      注意:“df -h用于顯示磁盤空間的使用情況,以及剩余的磁盤空間大小。”

      操作如下:

      [root@image_boundary Desktop]# df -h 文件系統 容量 已用 可用 已用% 掛載點 Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_image-lv_root 35G 3.6G 30G 11% / tmpfs 931M 296K 931M 1% /dev/shm /dev/sda1 477M 42M 411M 10% /boot /dev/sr0 3.7G 3.7G 0 100% /media/CentOS_6.9_Final

      9、文件命令

      -p:遞歸創建目錄

      操作如下:

      [root@image_boundary Desktop]# ll total 8 drwxr-xr-x. 2 root root 4096 Oct 15 20:02 aa drwxr-xr-x. 2 root root 4096 Oct 15 20:05 bb [root@image_boundary Desktop]# mkdir cc [root@image_boundary Desktop]# ll total 12 drwxr-xr-x. 2 root root 4096 Oct 15 20:02 aa drwxr-xr-x. 2 root root 4096 Oct 15 20:05 bb drwxr-xr-x. 2 root root 4096 Oct 15 20:21 cc # 不寫-p會報錯。 [root@image_boundary Desktop]# mkdir dd/ee mkdir: cannot create directory `dd/ee': No such file or directory # 參數-p表示遞歸產生一個目錄。 # 創建一個遞歸目錄dd/ee。 [root@image_boundary Desktop]# mkdir -p dd/ee [root@image_boundary Desktop]# cd dd [root@image_boundary dd]# ll total 4 drwxr-xr-x. 2 root root 4096 Oct 15 20:22 ee

      [root@image_boundary Desktop]# ll total 16 drwxr-xr-x. 2 root root 4096 Oct 15 20:02 aa drwxr-xr-x. 2 root root 4096 Oct 15 20:05 bb drwxr-xr-x. 2 root root 4096 Oct 15 20:21 cc drwxr-xr-x. 3 root root 4096 Oct 15 20:22 dd [root@image_boundary Desktop]# cd cc [root@image_boundary cc]# ll total 0 [root@image_boundary cc]# touch sum.txt [root@image_boundary cc]# ll total 4 -rw-r--r--. 1 root root 0 Oct 15 20:28 sum.txt

      -b:不顯示文件名,只顯示文件類型。

      操作如下:

      "file 文件名:可以顯示其到底是一個文件,還是一個目錄" [root@image_boundary ~]$ file aa aa: directory [root@image_boundary cc]# ll total 0 -rw-r--r--. 1 root root 0 Oct 15 20:28 sum.txt "查看當前文件夾的類型(這里指的就是cc):文件夾" [root@image_boundary cc]# file . .: directory "如果sum.txt中沒有內容,顯示empty" [root@image_boundary cc]# file sum.txt ./sum.txt: empty "如果sum.txt中有內容,顯示sum.txt的文件類型" [root@image_boundary cc]# file sum.txt ./sum.txt: ASCII text [root@image_boundary cc]# file -b sum.txt ASCII text

      -p:遞歸刪除空目錄

      操作如下:

      "注意以下兩個命令的區別" rmdir dd/ee/ff 表示刪除dd下面ee下面的這一個空目錄ff。 rmdir -p dd/ee/ff 表示同時遞歸刪除dd/ee/ff這3個目錄。

      rm 文件名

      -i:詢問。(這個是默認情況,不寫就是表示要詢問)

      -r:遞歸刪除。

      -f:強制刪除(不提示刪除)。

      “下面這條命令:慎用!!!除非真的知道你在干嘛。”

      rm -rf 目錄/文件

      操作如下:

      [root@image_boundary bb]# ll total 12 -rw-r--r--. 1 root root 149 Oct 15 20:00 a.txt -rw-r--r--. 1 root root 95 Oct 15 20:02 b.txt -rw-r--r--. 1 root root 138 Oct 15 20:02 c.txt [root@image_boundary bb]# rm a.txt rm: remove regular file `a.txt'? n [root@image_boundary bb]# ll total 12 -rw-r--r--. 1 root root 149 Oct 15 20:00 a.txt -rw-r--r--. 1 root root 95 Oct 15 20:02 b.txt -rw-r--r--. 1 root root 138 Oct 15 20:02 c.txt [root@image_boundary bb]# rm a.txt rm: remove regular file `a.txt'? y [root@image_boundary bb]# ll total 8 -rw-r--r--. 1 root root 95 Oct 15 20:02 b.txt -rw-r--r--. 1 root root 138 Oct 15 20:02 c.txt "rm -rf bb會刪除bb目錄下所有的目錄和文件,問都不問,毫不留情。一定不要輕易使用該命令" [root@image_boundary Desktop]# ll total 8 drwxr-xr-x. 2 root root 4096 Oct 15 20:53 bb drwxr-xr-x. 2 root root 4096 Oct 15 20:30 cc [root@image_boundary Desktop]# rm -rf bb [root@image_boundary Desktop]# ll total 4 drwxr-xr-x. 2 root root 4096 Oct 15 20:30 cc

      注意:某個文件或目錄被復制后,原始文件或目錄依然存在。

      cp 源文件(目錄) 目標文件(目錄)

      -i:提示。

      -r/-R參數:當【復制目錄】的時候,必須用到這個參數。

      -r/-R:遞歸復制目錄。

      -f參數:在搭建集群時,修改時區的時候用到

      -f:覆蓋已存在的目標文件,而不給出提示。

      ① 同一文件,復制到同一目錄下,需要改名;否則,會報錯。

      [root@image_boundary Desktop]# ll total 8 drwxr-xr-x. 2 root root 4096 Oct 15 21:00 aa drwxr-xr-x. 3 root root 4096 Oct 15 21:00 bb [root@image_boundary Desktop]# cd aa [root@image_boundary aa]# ll total 4 -rw-r--r--. 1 root root 21 Oct 15 21:00 sum.txt -rw-r--r--. 1 root root 0 Oct 15 20:59 sum.txt~ "把當前目錄下的sum.txt文件,復制到當前目錄下。" "假如不修改文件名,會報錯。" [root@image_boundary aa]# cp sum.txt sum.txt cp: `sum.txt' and `sum.txt' are the same file "修改文件名后,才不會報錯。" [root@image_boundary aa]# cp sum.txt sum1.txt [root@image_boundary aa]# ll total 8 -rw-r--r--. 1 root root 21 Oct 15 21:04 sum1.txt -rw-r--r--. 1 root root 21 Oct 15 21:00 sum.txt -rw-r--r--. 1 root root 0 Oct 15 20:59 sum.txt~

      ② 同一文件,復制到不同目錄下,不需要改名;

      [root@image_boundary Desktop]# ll total 8 drwxr-xr-x. 2 root root 4096 Oct 15 21:04 aa drwxr-xr-x. 3 root root 4096 Oct 15 21:00 bb "將aa目錄下的sum.txt文件,復制到bb目錄下,不需要修改名稱。" [root@image_boundary Desktop]# cp aa/sum.txt bb/ [root@image_boundary Desktop]# cd bb [root@image_boundary bb]# ll total 8 drwxr-xr-x. 2 root root 4096 Oct 15 21:01 bbb -rw-r--r--. 1 root root 21 Oct 15 21:07 sum.txt

      ③ 遞歸復制bb目錄中的東西(既包括文件,也包括目錄),到aa目錄中去。

      "由于復制目錄,因此必須使用參數【-r/-R】" [root@image_boundary Desktop]# ll total 8 drwxr-xr-x. 2 root root 4096 Oct 15 21:52 aa drwxr-xr-x. 3 root root 4096 Oct 15 21:07 bb "將bb目錄復制到aa目錄下。" "注意:復制目錄的時候,必須要使用參數-r或者-R" [root@image_boundary Desktop]# cp -r bb aa/ [root@image_boundary Desktop]# cd aa [root@image_boundary aa]# ll total 4 drwxr-xr-x. 3 root root 4096 Oct 15 21:53 bb -rw-r--r--. 1 root root 0 Oct 15 20:59 sum.txt~

      -i:提示。

      -f:強制移動。

      -u:新覆蓋舊,不存在時移動。

      ① 將同一個文件,移動到同級目錄下,必須修改文件名,效果相當于重命名。

      [root@image_boundary Desktop]# ll total 8 drwxr-xr-x. 2 root root 4096 Oct 15 21:55 aa drwxr-xr-x. 2 root root 4096 Oct 15 21:54 bb [root@image_boundary Desktop]# mv bb/sum.txt bb/sum1.txt

      ② 將同一個文件,移動到不同目錄下,如果沒有指定新文件名,效果相當于移動。

      此操作,僅相當于把sum.txt移動到aa目錄下。

      [root@image_boundary Desktop]# mv bb/sum.txt aa/

      ③ 將同一個文件,移動到不同目錄下,可以不用修改文件名。

      如果指定了新文件名,效果相當于移動+重命名。

      [root@image_boundary Desktop]# mv bb/sum.txt aa/sum.txt "把bb目錄下的sum.txt文件,移動到aa目錄下,并重命名為sum1.txt。" [root@image_boundary Desktop]# mv bb/sum.txt aa/sum1.txt

      -n :指定行數;

      head :查看文件中所有內容;

      tail :查看文件中所有內容;

      head -n:查看前n行數據;

      tail -n:查看后n行數據;

      “在計劃任務那里會用下面這個參數。”

      “在hadoop集群里面,查看log日志文件的時候,會用到。”

      tail -f:查看新追加內容;

      操作如下:

      [root@image_boundary Desktop]# ll total 8 drwxr-xr-x. 2 root root 4096 Oct 15 22:35 aa drwxr-xr-x. 2 root root 4096 Oct 15 22:30 bb [root@image_boundary Desktop]# head -3 aa/sum.txt aaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbb ccccccccccccccccc [root@image_boundary Desktop]# tail -3 aa/sum.txt mmmmmmmmmmmmmmmmm nnnnnnnnnnnnnnnnn ooooooooooooooooo

      -n:顯示文件行號。(這是cat常用的)

      cat :查看文件中所有內容,正著查看。

      tac :查看文件中所有內容,倒著查看。

      操作如下:

      Linux系列:Linux常用磁盤命令、文件命令!

      [root@image_boundary Desktop]# cat -n aa/sum.txt 1 1 2 2 3 3 4 4

      cat配合EOF命令,有一個比較厲害的操作:

      q鍵:退出more命令。

      Space鍵:顯示文本的下一屏內容。

      Enter鍵:只顯示文本的下一行內容。

      h鍵:顯示幫助屏,該屏上有相關的幫助信息。

      b鍵:顯示上一屏內容。

      q鍵:退出less命令。

      G:跳到文件末尾

      gg:跳到文件首行

      按e鍵:向上滾動一行

      按y鍵:向下滾動一行

      操作如下:

      less -N aa/sum.txt 此參數會顯示文件內容的行數

      結果如下:

      -e:處理特殊的符號。eg:寫了-e,就會把\n當成換行符,否則不會。 echo $PWD :輸出變量的絕對路徑 ">表示覆蓋源文件中的內容" echo aa > a.txt ">>表示追加到源文件末尾" echo aa >> a.txt

      操作如下:

      [root@image_boundary Desktop]# echo "aa\nbb" aa\nbb [root@image_boundary Desktop]# clear "-e參數,表示讓系統能夠識別特殊字符" [root@image_boundary Desktop]# echo -e "aa\nbb" aa bb [root@image_boundary Desktop]# echo -e "aa\tbb" aa bb ================================================== "echo $PWD表示輸出當前文件夾的絕對路經,很有用。" [root@image_boundary Desktop]# echo $PWD /root/Desktop [root@image_boundary Desktop]# cd aa [root@image_boundary aa]# echo $PWD /root/Desktop/aa [root@image_boundary aa]# cd ../bb [root@image_boundary bb]# echo $PWD /root/Desktop/bb ================================================= [root@image_boundary Desktop]# echo -e '666\n888' > ./aa/aa.txt [root@image_boundary Desktop]# echo -e '中國人' >> ./aa/aa.txt

      硬鏈接類似于【復制】;

      軟連接類似于【創建快捷方式】(常用);

      為f1 創建硬鏈接 f2 :ln f1 f2

      為f1 創建軟鏈接(也叫符號鏈接) f3 :ln -s f1 f3

      操作如下:

      [root@image_boundary Desktop]# ll total 4 drwxr-xr-x. 2 root root 4096 Oct 15 23:28 aa "創建一個文件test.txt" [root@image_boundary Desktop]# cd aa [root@image_boundary aa]# touch test.txt "創建一個硬鏈接,相當于是復制了該文件" [root@image_boundary aa]# ln test.txt test "創建一個軟連接,相當于給該文件創建了一個快捷方式" [root@image_boundary aa]# ln -s test.txt s_test [root@image_boundary aa]# echo "I am a student" >> test.txt [root@image_boundary aa]# cat s_test I am a student [root@image_boundary aa]# cat test I am a student "刪除源文件test.txt后" [root@image_boundary aa]# rm -rf test.txt "軟連接文件(快捷方式)會消失" [root@image_boundary aa]# cat s_test cat: s_test: No such file or directory "但是這個硬鏈接(復制)不會消失" [root@image_boundary aa]# cat test I am a student

      “定義別名的意義在于,可以用別名,代替某些組合命令,減少敲代碼;”

      查看別名:alias

      定義別名:alias la= ‘ll -a’

      取消別名:unalias la

      操作如下:

      [root@image_boundary Desktop]# alias alias cp='cp -i' alias l.='ls -d .* --color=auto' alias ll='ls -l --color=auto' alias ls='ls --color=auto' alias mv='mv -i' alias rm='rm -i' alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'

      10、其他常用命令

      clear 或 ctrl+l :清屏 history :顯示歷史代碼命令 su :切換用戶。$普通用戶;#管理員root用戶 hostname :顯示主機名 sudo :以root用戶權限執行一次命令(目前不太明白這個) exit :退出當前登錄狀態。當前是普通用戶切換到root用戶;當前是root用戶就切換到普通用戶。 who :顯示目前有哪些用戶登入系統 | :管道符,表示把前面命令內容的輸出,當做后面命令的輸入。

      11、案例講解

      操作如下:

      "首先,創建這3個文件夾;" [root@image_boundary Desktop]# mkdir myFile [root@image_boundary Desktop]# mkdir myPic [root@image_boundary Desktop]# mkdir backup [root@image_boundary Desktop]# ll total 16 drwxr-xr-x. 2 root root 4096 Oct 15 23:36 aa drwxr-xr-x. 2 root root 4096 Oct 15 23:57 backup drwxr-xr-x. 2 root root 4096 Oct 15 23:56 myFile drwxr-xr-x. 2 root root 4096 Oct 15 23:56 myPic "分別在myFile、backup分別創建一個a.txt;" [root@image_boundary Desktop]# cd myFile [root@image_boundary myFile]# touch a.txt [root@image_boundary myFile]# cd .. [root@image_boundary Desktop]# cd backup [root@image_boundary backup]# mkdir a.txt "刪除backup這個文件夾及其其中的內容;" [root@image_boundary Desktop]# rm -rf backup "將同一個文件夾移動到同級目錄下,相當于修改名字;" [root@image_boundary Desktop]# mv ./myFile ./File "將File目錄下的a.txt文件,移動到myPic目錄下;" [root@image_boundary Desktop]# cp ./File/a.txt ./myPic/

      Linux Unix

      版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。

      版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。

      上一篇:如何加背景(剪映如何加背景)
      下一篇:Python 面向對象三大特征之繼承
      相關文章
      国产亚洲午夜高清国产拍精品| 日韩精品亚洲人成在线观看| 亚洲成人免费在线| 国产精品亚洲AV三区| 亚洲日本成本人观看| 亚洲日本成本人观看| 一本天堂ⅴ无码亚洲道久久| 亚洲综合无码一区二区痴汉 | 久久久久亚洲AV成人网| 在线观看免费亚洲| 亚洲午夜无码久久| 亚洲日韩精品无码专区加勒比 | 亚洲熟女乱色一区二区三区| 亚洲校园春色另类激情| 亚洲国产成人91精品| 亚洲三级中文字幕| 亚洲欧洲日韩国产一区二区三区 | 国产亚洲情侣一区二区无码AV| 亚洲性在线看高清h片| 伊人久久综在合线亚洲91| 日韩精品亚洲aⅴ在线影院| 亚洲精品夜夜夜妓女网| 久久91亚洲精品中文字幕| 亚洲a在线视频视频| 亚洲五月激情综合图片区| 久久精品国产亚洲av影院| 亚洲综合激情视频| 亚洲AV无码国产精品色| 亚洲欧洲精品成人久久曰| MM1313亚洲国产精品| 亚洲精品和日本精品| 亚洲熟妇av一区二区三区| 亚洲AV天天做在线观看| 亚洲AV电影院在线观看| 亚洲福利电影在线观看| 亚洲jizzjizz在线播放久| 亚洲成在人线aⅴ免费毛片| 亚洲精品99久久久久中文字幕| 国内精品99亚洲免费高清| 亚洲av无码专区在线播放| 亚洲第一成年网站大全亚洲|