応用編で詳述し、Linuxのディレクトリとファイル

A、Linuxのディレクトリ構造

ツリーのディレクトリ構造を使用して、Linuxのディレクトリ構造は、ルートディレクトリとサブディレクトリが含まれています。
応用編で詳述し、Linuxのディレクトリとファイル

1、ルートディレクトリ

位置すべてのパーティション、ディレクトリ、ファイル、およびその開始点、全体のディレクトリツリー構造、別の「/」の使用。

2、サブディレクトリ

など/ルート共通のサブディレクトリ、/ binに、/ bootには、/ devは、/ etc、/家庭、の/ varは/ usr / sbinに。

3、サブディレクトリの役割

応用編で詳述し、Linuxのディレクトリとファイル

ファイルベースのコンテンツを表示するには、2つの、Linuxのコマンド

1は、ファイルの内容を表示しますcat--

一度に表示されたファイルの内容全体のための猫。次のように基本的な構文は次のとおりです。
応用編で詳述し、Linuxのディレクトリとファイル

アプリケーション例:

[root@01 ~]# 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--ファイルの内容を表示します

より多くのページングファイルの内容のためのフルスクリーンモード。次のように基本的な構文は次のとおりです。
応用編で詳述し、Linuxのディレクトリとファイル

操作のインタラクティブな方法:

  • 押して、行ずつスクロールダウンします。

  • スペースバーを押して1つの画面断ります。

  • 終了するには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コマンドと同じコマンドが、より多くの拡張子を持ちます。次のように基本的な構文は次のとおりです。
応用編で詳述し、Linuxのディレクトリとファイル

操作のインタラクティブな方法:

  • ページアップキー:ページアップ。

  • ページダウンキー:ダウン。

  • 「/」キー:キーコンテンツを探します。

  • 「N」:キー要素を探します。

  • 「N」:キー要素を探します。

その他の特徴と類似した、より基本的なコマンド。

4、頭、tail--は、ファイルの内容を表示します

次のように頭、尾の基本的なコマンドの構文は次のとおりです。
応用編で詳述し、Linuxのディレクトリとファイル

応用編で詳述し、Linuxのディレクトリとファイル

  • ヘッド:ファイルの先頭の表示部分(デフォルトは10行です)。

  • 尾:ファイルの内容の端部を参照してください(デフォルトは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--統計ファイルの内容

文書内の単語の数、(ワード数)、行数、バイト数のトイレの統計。次のように基本的な構文は次のとおりです。
応用編で詳述し、Linuxのディレクトリとファイル

次のようにトイレの一般的なオプションは次のとおりです。

  • -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-- archiveコマンド

リリースアーカイブを作成するアーカイブ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圧縮とバックアップコマンド

オプションと引数:

  • 場合:入力ファイル(オリジナルファイル)もデバイスとすることができます。

  • 出力ファイル(ファイルバックアップ)デバイスであってもよいです。

  • BS:指定されていない場合、ブロック計画(ブロック)サイズ、デフォルトは512バイト(バイト)です。

  • カウント:どのように多くのブロックの平均。

アプリケーション例:

[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のディレクトリとファイル

おすすめ

転載: www.linuxidc.com/Linux/2020-01/162123.htm