站長資訊網
最全最豐富的資訊網站

Linux目錄和文件高級操作詳述

一、Linux目錄結構

Linux目錄結構采用樹形目錄結構,包含根目錄和子目錄。
Linux目錄和文件高級操作詳述

1、根目錄

所有分區、目錄、文件等的位置起點,整個樹形目錄結構中,使用獨立的一個“/”表示。

2、子目錄

常見的子目錄如/root、/bin、/boot、/dev、/etc、/home、/var、/usr、/sbin。

3、子目錄的作用

Linux目錄和文件高級操作詳述

二、Linux查看文件內容基礎命令

1、cat——查看文件內容

cat用于一次性顯示文件全部內容。基本語法格式如下:
Linux目錄和文件高級操作詳述

應用舉例:

[root@CentOS01 ~]# cat /etc/hosts 127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4  ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6  [root@centos01 ~]# cat /etc/sysconfig/network # Created by anaconda  [root@centos01 ~]# cat /etc/sysconfig/network /etc/hosts # Created by anaconda 127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4  ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

2、more——查看文件內容

more用于全屏模式分頁顯示文件內容。基本語法格式如下:
Linux目錄和文件高級操作詳述

交互操作方法:

  • 按Enter鍵向下逐行滾動;

  • 按空格鍵向下翻一屏;

  • 按q鍵退出;

應用舉例:

[root@centos01 ~]# more /etc/httpd/conf/httpd.conf   # # This is the main Apache HTTP server configuration file.  It contains the # configuration directives that give the server its instructions. # See <URL:http://httpd.apache.org/docs/2.4/> for detailed information. # In particular, see  # <URL:http://httpd.apache.org/docs/2.4/mod/directives.html> --More--(2%)

3、less——查看文件內容

less命令的作用與more命令相同,但擴展功能更多。基本語法格式如下:
Linux目錄和文件高級操作詳述

交互操作方法:

  • Page Up鍵:向上翻頁;

  • Page Down鍵:向下翻頁;

  • “/”鍵:查找關鍵內容;

  • “n”:查找下一個關鍵內容;

  • “N”:查找上一個關鍵內容;

其他功能與more命令基本類似;

4、head、tail——查看文件內容

head、tail命令的基本語法格式如下:
Linux目錄和文件高級操作詳述

Linux目錄和文件高級操作詳述

  • head:查看文件開頭的一部分內容(默認為10行);

  • tail:查看文件結尾的一部分內容(默認為10行);

應用舉例:

[root@centos01 ~]# head -2 /var/log/messages <!--顯示文件的開始2行內容-->  Jan 10 20:20:01 centos01 systemd: Started Session 9 of user root.  Jan 10 20:20:01 centos01 systemd: Starting Session 9 of user root.  [root@centos01 ~]#   [root@centos01 ~]# tail -3 /var/log/messages <!--顯示文件的最后3行內容-->  Jan 10 23:10:01 centos01 systemd: Starting Session 30 of user root.  Jan 10 23:20:01 centos01 systemd: Started Session 31 of user root.  Jan 10 23:20:01 centos01 systemd: Starting Session 31 of user root.  [root@centos01 ~]#   [root@centos01 ~]# tail -f /var/log/messages        <!--動態跟蹤文件尾部內容,便于實時監控文件內容的變化  (按Ctrl+c組合鍵終止)-->  Jan 10 23:01:01 centos01 systemd: Starting Session 29 of user root.  Jan 10 23:03:19 centos01 yum[11583]: Installed: httpd-tools-2.4.6-67.el7.centos.x86_64  Jan 10 23:03:19 centos01 yum[11583]: Installed: mailcap-2.1.41-2.el7.noarch  Jan 10 23:03:20 centos01 systemd: Reloading.  Jan 10 23:03:20 centos01 yum[11583]: Installed: httpd-2.4.6-67.el7.centos.x86_64  Jan 10 23:03:20 centos01 journal: g_dbus_interface_skeleton_unexport: assertion 'interface_->priv->connections != NULL' failed  Jan 10 23:10:01 centos01 systemd: Started Session 30 of user root.  Jan 10 23:10:01 centos01 systemd: Starting Session 30 of user root.  Jan 10 23:20:01 centos01 systemd: Started Session 31 of user root.  Jan 10 23:20:01 centos01 systemd: Starting Session 31 of user root.

5、wc——統計文件內容

wc用于統計文件中的單詞數量、(Word Count)、行數、字節數等。基本語法格式如下:
Linux目錄和文件高級操作詳述

wc常用選項如下:

  • -l:統計行數;

  • -w:統計單詞個數;

  • -c:統計字節數;

應用舉例:

[root@centos01 ~]# wc -l /etc/passwd   <!--統計文件行數-->  41 /etc/passwd  [root@centos01 ~]# wc -w /etc/passwd <!--統計文件中單詞個數-->  81 /etc/passwd  [root@centos01 ~]# wc -c /etc/passwd  <!--統計文件中字節數-->  2104 /etc/passwd  [root@centos01 ~]# wc /etc/passwd        <!--不加選項統計順序依次是43行,85個單詞,2223個字節-->    43   85 2223 /etc/passwd  [root@centos01 ~]# find /etc -name "*.conf" | wc -l         <!--統計/etc下有多少個以*.conf為后綴的文件數量-->  437 

6、grep——檢索和過濾文件內容

grep命令用于在文件中查找并顯示包含指定字符串的行。基本語法格式如下:
Linux目錄和文件高級操作詳述

grep命令常用選項如下:

  • -i:查找時忽略大小寫;

  • -v:反轉查找,輸出與條件不相符的行;

grep查找條件設置:

  • 要查找的字符串以雙引號括起來;

  • “^……”:表示查找以……開頭的字符串;

  • “……$”:表示查找以……結尾的字符串;

  • “^$”:表示查找空行;

應用舉例:

[root@centos01 ~]# grep -i "SSHD" /etc/passwd              <!--查詢sshd用戶忽略大小寫顯示出來-->  sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin  [root@centos01 ~]# grep "ftp" /etc/passwd                     <!--查詢ftp用戶顯示出來-->  ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin  [root@centos01 ~]# grep -v "^#" /etc/yum.conf | grep -v "^$"                    <!--過濾/etc/yum.conf中的注釋行和空行-->  [main]  cachedir=/var/cache/yum/$basearch/$releasever  keepcache=0  debuglevel=2  logfile=/var/log/yum.log  exactarch=1  obsoletes=1  gpgcheck=1  plugins=1  installonly_limit=5  bugtracker_url=http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum  distroverpkg=centos-release

三、壓縮和解壓縮文件

1、gzip、gunzip——壓縮和解壓縮

Linux目錄和文件高級操作詳述

應用舉例:

<!--壓縮和解壓縮方法一(“-9”選項代表高壓縮)-->  [root@centos01 ~]# ls anaconda-ks.cfg CentOS-7.4-x86_64-1708.iso initial-setup-ks.cfg [root@centos01 ~]# gzip -9 initial-setup-ks.cfg [root@centos01 ~]# ls anaconda-ks.cfg CentOS-7.4-x86_64-1708.iso initial-setup-ks.cfg.gz [root@centos01 ~]# gzip -d initial-setup-ks.cfg.gz [root@centos01 ~]# ls anaconda-ks.cfg CentOS-7.4-x86_64-1708.iso initial-setup-ks.cfg    <!--壓縮和解壓縮方法二(不加選項進行壓縮,解壓縮使用gunzip命令)-->  [root@centos01 ~]# ls anaconda-ks.cfg CentOS-7.4-x86_64-1708.iso initial-setup-ks.cfg [root@centos01 ~]# gzip initial-setup-ks.cfg [root@centos01 ~]# ls anaconda-ks.cfg CentOS-7.4-x86_64-1708.iso initial-setup-ks.cfg.gz [root@centos01 ~]# gunzip initial-setup-ks.cfg.gz [root@centos01 ~]# ls anaconda-ks.cfg CentOS-7.4-x86_64-1708.iso initial-setup-ks.cfg

2、bzip2、bunzip2——壓縮和解壓縮

Linux目錄和文件高級操作詳述

應用舉例:

<!--方法一-->  [root@centos01 ~]# ls  anaconda-ks.cfg  CentOS-7.4-x86_64-1708.iso  initial-setup-ks.cfg  [root@centos01 ~]# bzip2 -9 initial-setup-ks.cfg    <!--高速壓縮-->  [root@centos01 ~]# ls  anaconda-ks.cfg  CentOS-7.4-x86_64-1708.iso  initial-setup-ks.cfg.bz2  [root@centos01 ~]# bzip2 -d initial-setup-ks.cfg.bz2 <!--解壓縮-->  [root@centos01 ~]# ls  anaconda-ks.cfg  CentOS-7.4-x86_64-1708.iso  initial-setup-ks.cfg    <!--方法二-->  [root@centos01 ~]# ls  anaconda-ks.cfg  CentOS-7.4-x86_64-1708.iso  initial-setup-ks.cfg  [root@centos01 ~]# bzip2 initial-setup-ks.cfg  <!--壓縮-->  [root@centos01 ~]# ls  anaconda-ks.cfg  CentOS-7.4-x86_64-1708.iso  initial-setup-ks.cfg.bz2  [root@centos01 ~]# bunzip2 initial-setup-ks.cfg.bz2  <!--解壓縮-->  [root@centos01 ~]# ls  anaconda-ks.cfg  CentOS-7.4-x86_64-1708.iso  initial-setup-ks.cfg

3、tar——歸檔命令

tar命令制作歸檔文件、釋放歸檔文件。基本語法格式如下:
Linux目錄和文件高級操作詳述

tar命令常用選項如下:

  • -c:創建.tar格式的包文件;

  • -x:解開.tar格式的包文件;

  • -v:輸出詳細信息;

  • -f:表示使用歸檔文件;

  • -p:打包時保留原始文件及目錄的權限;

  • -t:列表查看包內的文件;

  • -C:解包時指定釋放的目標文件夾;

  • -z:調用gzip程序進行壓縮或解壓;

  • -j:調用bzip2程序進行壓縮或解壓;

應用舉例:

[root@centos01 ~]# tar zcvf yun.gz yun/ <!--使用tar命令調用gzip將yun歸檔為yun.gz-->  yun/  [root@centos01 ~]# ls  1.txt  anaconda-ks.cfg  initial-setup-ks.cfg  www  yun  yun.gz  [root@centos01 ~]# tar zxvf yun.gz -C /usr/src/              <!--將壓縮文件yun.gz解壓縮到/usr/src目錄中-->  yun/  [root@centos01 ~]# cd /usr/src/  [root@centos01 src]# ls  debug  kernels  yun  [root@centos01 ~]# tar jcvf yun.bz2 ./yun           <!--使用tar命令調用bzip將yun目錄數據進行壓縮-->  [root@centos01 ~]# tar jxvf yun.bz2 -C /usr/src/       <!--將yun.bz2壓縮文件解壓縮到/usr/src/目錄中-->  ./yun/  [root@centos01 ~]# cd /usr/src/  [root@centos01 src]# ls  debug  kernels  yun

4、dd命令壓縮與備份

選項和參數:

  • if:input file(原文件)也可以是設備;

  • of:output file(備份后的文件)也可以是設備;

  • bs:規劃的一個block(塊)的大小,若未指定則默認是512Bytes(字節);

  • count:多少塊的意思。

應用舉例:

[root@centos01 ~]# dd if=/dev/zero of=/usr/src/1.iso bs=30M count=10  <!--將/dev/zero文件中的信息復制到/usr/src目錄下創建一個1.iso的文件,一次30M,10次-->  記錄了10+0 的讀入  記錄了10+0 的寫出  314572800字節(315 MB)已復制,0.212995 秒,1.5 GB/秒  [root@centos01 ~]# cd /usr/src/  [root@centos01 src]# ls  1.iso  debug  kernels

四、vi文本編輯器

1、文本編輯器的作用

創建或者修改文本文件,維護Linux系統中的各種配置文件。

2、Linux中最常用的文本編輯器

  • vi:類Unix系統中默認的文本編輯器;

  • vim:vi編輯器的增強版本,習慣上也成為vi;

3、vi編輯器的工作模式

命令模式、輸入模式、末行模式。不同模式之間的切換如下:
Linux目錄和文件高級操作詳述

4、命令模式的常用操作

1)光標移動

Linux目錄和文件高級操作詳述

2)復制、粘貼、刪除

Linux目錄和文件高級操作詳述

3)文件內容查找

Linux目錄和文件高級操作詳述

4)撤銷編輯及保存退出

Linux目錄和文件高級操作詳述

5、末行模式的基本操作

1)保存文件及退出vi編輯器

Linux目錄和文件高級操作詳述

2)打開新文件或讀入其他文件內容

Linux目錄和文件高級操作詳述

3)文件內容替換

Linux目錄和文件高級操作詳述

贊(0)
分享到: 更多 (0)
網站地圖   滬ICP備18035694號-2    滬公網安備31011702889846號
久久青青草原精品影院| 国产精品不卡视频| 国产成人精品优优av| 国产精品亚洲二区在线观看 | 麻豆精品国产免费观看 | 久久国产乱子伦精品免费强| 国产精品1024视频| 亚洲乱码国产乱码精品精| 夜夜精品无码一区二区三区| 日韩精品视频免费网址| 国产大片91精品免费观看男同| WWW国产亚洲精品久久麻豆| 高清精品一区二区三区一区| 国产香蕉精品视频| 久久精品国产99国产精品导航| 99re热久久精品这里都是精品| 久久夜色精品国产嚕嚕亚洲av| 国产精品香港三级国产AV| 中文精品人人永久免费| 久久se这里只有精品| 国产偷窥熟女高潮精品视频| 国产精品亚洲玖玖玖在线观看| 国产精品香蕉在线观看| 国产区精品高清在线观看 | 99在线精品一区二区三区| 亚洲精品国产啊女成拍色拍| 2020国产精品永久在线观看| 2021最新国产成人精品视频| 精品国产鲁一鲁一区二区| 亚洲午夜久久久精品电影院| 精品国际久久久久999波多野| 国产午夜精品一本在线观看| 久久精品国产亚洲AV网站| 亚洲精品无码久久久影院相关影片| 在线涩涩免费观看国产精品 | 中文字幕一区日韩精品| 伊人久99久女女视频精品免| 国产精品无码久久四虎| 精品国产日韩一区三区| 四色在线精品免费观看| 尤物国产精品福利三区|