#第V章:Linuxのコマンドは、ファイルの種類と実践を見つけるために

1、ファイルの属性

  • ファイルの属性はを参照します。

    • ファイルサイズ、作成日時、種類、アクセス権、およびその他のグループ。
    [root@oldboyedu ~]# ls -lih
    total 4.0K
    33574978 -rw-------. 1 root root 1.7K Apr  4 18:09 anaconda-ks.cfg
    [root@oldboyedu ~]# ls -lih /etc/
    total 1.1M
    51000206 drwxr-xr-x.  3 root root  101 Apr  4 18:06 abrt
    16881475 -rw-r--r--.  1 root root   16 Apr  4 18:08 adjtime
    16777784 -rw-r--r--.  1 root root 1.5K Jun  7  2013 aliases
    16777285 -rw-r--r--.  1 root root  12K Apr  4 18:17 aliases.db
    50334171 drwxr-xr-x.  2 root root  261 Apr  4 18:22 alternatives
    16881620 -rw-------.  1 root root  541 Aug  9  2019 anacrontab
    17167203 -rw-r--r--.  1 root root   55 Aug  8  2019 asound.conf
    51150791 drwxr-x---.  3 root root   43 Apr  4 18:06 audisp
    17528264 drwxr-x---.  3 root root   83 Apr  4 18:17 audit
    50331775 drwxr-xr-x.  2 root root   79 Apr  4 18:23 bash_completion.d
    16777785 -rw-r--r--.  1 root root 2.8K Oct 31  2018 bashrc
    34060666 drwxr-xr-x.  2 root root    6 Mar 18 07:46 binfmt.d
    16777318 -rw-r--r--.  1 root root   37 Sep  5  2019 centos-release
    16777319 -rw-r--r--.  1 root root   51 Sep  5  2019 centos-release-upstream
       35647 drwxr-xr-x.  2 root root    6 Aug  4  2017 chkconfig.d
      539069 drwxr-xr-x.  2 root root   36 Apr  4 18:20 cron.d
    17167190 drwxr-xr-x.  2 root root   42 Apr  4 18:06 cron.daily
    16881621 -rw-------.  1 root root    0 Aug  9  2019 cron.deny
    
    
  • 10のプロパティファイルの合計

    16881621 -rw-------.  1 root root    0 Aug  9  2019 cron.deny
       1          2       3  4    5      6  7   8   9      10    
    
    • 最初の列

      • 伝票番号はまた、iノード(ノード)として知られているユニークな識別子であります
    • 第二のカラム

      • 最初の文字

        • これは、ファイルタイプを参照します

          • - ファイルタイプを代表するが通常ファイルである(Fで示します)

          • Dは、代表的なファイルタイプである(Dで示す)ディレクトリであります

            [root@oldboyedu ~]# ls -ld /etc/
            drwxr-xr-x. 79 root root 8192 Apr  9 17:51 /etc/
            [root@oldboyedu ~]# ls -lp /etc/
            total 1076
            drwxr-xr-x.  3 root root    101 Apr  4 18:06 abrt/ #以斜线结尾的都是目录
            -rw-r--r--.  1 root root     16 Apr  4 18:08 adjtime
            -rw-r--r--.  1 root root   1518 Jun  7  2013 aliases
            -rw-r--r--.  1 root root  12288 Apr  4 18:17 aliases.db
            drwxr-xr-x.  2 root root    261 Apr  4 18:22 alternatives/
            -rw-------.  1 root root    541 Aug  9  2019 anacrontab
            -rw-r--r--.  1 root root     55 Aug  8  2019 asound.conf
            drwxr-x---.  3 root root     43 Apr  4 18:06 audisp/
            [root@oldboyedu ~]# ls -F /etc/
            abrt/                    gnupg/                    motd               sasl2/
            adjtime                  GREP_COLORS               mtab@              securetty
            aliases                  groff/                    my.cnf             security/
            #@指的是连接文件
            
          • Lは(Lで示される)の代表的なファイルタイプのファイルであります

            [root@oldboyedu ~]# ls -l /etc/rc.local 
            lrwxrwxrwx. 1 root root 13 Apr  4 18:22 /etc/rc.local -> rc.d/rc.local
            
            
          • Cは、ファイルタイプが(Cで示す)文字装置であって表します

            [root@oldboyedu ~]# ls -l /dev/ttyS2
            crw-rw----. 1 root dialout 4, 66 Apr  9 17:51 /dev/ttyS2
            
          • (b)は(Bによって表される)代表的なファイルタイプのファイルであります

            [root@oldboyedu ~]# ls -l /dev/ | grep "^d"
            drwxr-xr-x. 2 root root         140 Apr  9 17:51 block
            drwxr-xr-x. 2 root root          80 Apr  9 17:51 bsg
            drwxr-xr-x. 3 root root          60 Apr  9 17:51 bus
            drwxr-xr-x. 2 root root        2980 Apr  9 17:51 char
            drwxr-xr-x. 3 root root          60 Apr  9 17:51 cpu
            drwxr-xr-x. 5 root root         100 Apr  9 17:51 disk
            drwxr-xr-x. 2 root root          80 Apr  9 17:51 dri
            drwxr-xr-x. 2 root root           0 Apr  9 17:51 hugepages
            drwxr-xr-x. 4 root root         300 Apr  9 17:51 input
            drwxr-xr-x. 2 root root          60 Apr  9 17:51 mapper
            drwxrwxrwt. 2 root root          40 Apr  9 17:51 mqueue
            drwxr-xr-x. 2 root root          60 Apr  9 17:51 net
            drwxr-xr-x. 2 root root           0 Apr  9 17:51 pts
            drwxr-xr-x. 2 root root          60 Apr  9 17:51 raw
            drwxrwxrwt. 2 root root          40 Apr  9 17:51 shm
            drwxr-xr-x. 3 root root         200 Apr  9 17:51 snd
            drwxr-xr-x. 2 root root          60 Apr  9 17:51 vfio
            
            
          • Sは(Sで示す)の代表的なファイルタイプのファイルであります

            • .sockファイルには、以下のような多くの場合、ネットワーク、データ接続の間で使用されるような文書の特別なクラスです:私たちは、クライアントがソケットを介してデータを通信することができるクライアント要求をリッスンするプログラムを起動することができます。
            • プロセス間のファイルの通信
            [root@oldboyedu ~]# ls -l /dev/ | grep "^s"
            srw-rw-rw-. 1 root root           0 Apr  9 17:51 log
            

2、パスチェックコマンド

  • これ

    [root@oldboyedu ~]# which ls
    alias ls='ls --color=auto'
    	/usr/bin/ls
    [root@oldboyedu ~]# which cp
    alias cp='cp -i'
    	/usr/bin/cp
    [root@oldboyedu ~]# which ip
    /usr/sbin/ip
    [root@oldboyedu ~]# which cd
    /usr/bin/cd
    

3、システム変数(検索コマンドポジションシステム)

  • $ PATHスーパー焦点
[root@oldboyedu ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
#系统默认从上面路径查找,以:分割,每分割一次为一个路径
#示例一
[root@oldboyedu ~]# cat /usr/bin/cc
echo $1
[root@oldboyedu ~]# chmod +x /usr/bin/cc
[root@oldboyedu ~]# cc sun
sun
[root@oldboyedu ~]# which cc
/usr/bin/cc

図4は、ファイルおよびそれに関連するコマンドのフルパスを表示します

  • whereisは

    [root@oldboyedu ~]# whereis ls
    ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz
    [root@oldboyedu ~]# whereis cp
    cp: /usr/bin/cp /usr/share/man/man1/cp.1.gz
    
    • -bコマンドは、バイナリファイルのパス

      [root@oldboyedu ~]# whereis -b cp
      cp: /usr/bin/cp
      

5、すぐにファイルのパスを探します

  • 見つけます

    • データベースクエリから、ファイルパスを探します
    [root@oldboyedu ~]# yum provides locate  #查看命令所需要的rpm包
    [root@oldboyedu ~]# yum install mlocate -y
    [root@oldboyedu ~]# updatedb #更新库
    [root@oldboyedu ~]# locate ls
    

6、ディレクトリ内のファイル検索

  • 見つけます

    • 原則検索:遅いディスクを横断
    [root@oldboyedu ~]# touch oldboy.txt
    [root@oldboyedu ~]# find ~ -name "oldboy.txt"
    /root/oldboy.txt
    
    
    • あいまい参照
    [root@oldboyedu ~]# find ~ -name "oldboy*"
    /root/oldboy.txt
    [root@oldboyedu ~]# find /etc/sysconfig/ -name "ifcfg*"
    /etc/sysconfig/network-scripts/ifcfg-lo
    /etc/sysconfig/network-scripts/ifcfg-eth0
    
    
    • ファイルタイプによる検索を-type
    [root@oldboyedu ~]# find /etc/sysconfig/ -type f -name "ifcfg-eth0"   #f文件
    /etc/sysconfig/network-scripts/ifcfg-eth0
    
    [root@oldboyedu ~]# find /etc/ -type d  -name "sysconfig"	#目录
    /etc/sysconfig
    [root@oldboyedu ~]# find /etc/ -type d  -name "sys*"
    /etc/selinux/targeted/active/modules/100/sysadm
    /etc/selinux/targeted/active/modules/100/sysadm_secadm
    /etc/selinux/targeted/active/modules/100/sysnetwork
    /etc/selinux/targeted/active/modules/100/sysstat
    /etc/selinux/targeted/active/modules/100/systemd
    /etc/systemd
    /etc/systemd/system
    /etc/systemd/system/system-update.target.wants
    /etc/systemd/system/sysinit.target.wants
    /etc/dbus-1/system.d
    /etc/sysctl.d
    /etc/sysconfig
    /etc/xdg/systemd
    /etc/NetworkManager/system-connections
    /etc/latrace.d/headers/sysdeps
    
    • 否定

      [root@oldboyedu ~]# find /etc/sysconfig/network-scripts/ -type f ! -name "ifcfg-eth0"
      /etc/sysconfig/network-scripts/ifcfg-lo
      /etc/sysconfig/network-scripts/ifdown-bnep
      /etc/sysconfig/network-scripts/ifdown-eth
      /etc/sysconfig/network-scripts/ifdown-ippp
      /etc/sysconfig/network-scripts/ifdown-ipv6
      /etc/sysconfig/network-scripts/ifdown-post
      /etc/sysconfig/network-scripts/ifdown-ppp
      /etc/sysconfig/network-scripts/ifdown-routes
      /etc/sysconfig/network-scripts/ifdown-sit
      /etc/sysconfig/network-scripts/ifdown-tunnel
      /etc/sysconfig/network-scripts/ifup-aliases
      /etc/sysconfig/network-scripts/ifup-bnep
      /etc/sysconfig/network-scripts/ifup-eth
      /etc/sysconfig/network-scripts/ifup-ippp
      /etc/sysconfig/network-scripts/ifup-ipv6
      /etc/sysconfig/network-scripts/ifup-plip
      /etc/sysconfig/network-scripts/ifup-plusb
      /etc/sysconfig/network-scripts/ifup-post
      /etc/sysconfig/network-scripts/ifup-ppp
      /etc/sysconfig/network-scripts/ifup-routes
      /etc/sysconfig/network-scripts/ifup-sit
      /etc/sysconfig/network-scripts/ifup-tunnel
      /etc/sysconfig/network-scripts/ifup-wireless
      /etc/sysconfig/network-scripts/init.ipv6-global
      /etc/sysconfig/network-scripts/network-functions
      /etc/sysconfig/network-scripts/network-functions-ipv6
      /etc/sysconfig/network-scripts/ifdown-Team
      /etc/sysconfig/network-scripts/ifdown-TeamPort
      /etc/sysconfig/network-scripts/ifup-Team
      /etc/sysconfig/network-scripts/ifup-TeamPort
      
      
    • 行動の過程で-exec検索

      • ここに置くために見つける{}以前の結果
      • このコマンドが使用されることに注意してください{};中間スペースマスト
      • \ここでは、エスケープを表している。本来の意味を変換します
      [root@oldboyedu ~]# find ~ -type f -name "oldboy*"
      /root/oldboy.txt
      [root@oldboyedu ~]# find ~ -type f -name "oldboy*" -exec rm -f {} \;
      [root@oldboyedu ~]# ls
      anaconda-ks.cfg
      
      
    • 修正時刻によって検索-mtime

      • + nは数日前
      • n日
      • 数日後に-n
      [root@oldboyedu ~]# find ~ -type f -mtime +3  #三天之前
      /root/.bash_logout
      /root/.bash_profile
      /root/.bashrc
      /root/.cshrc
      /root/.tcshrc
      /root/anaconda-ks.cfg
      /root/.bash_history
      [root@oldboyedu ~]# find ~ -type f -mtime +1  #一天之前
      /root/.bash_logout
      /root/.bash_profile
      /root/.bashrc
      /root/.cshrc
      /root/.tcshrc
      /root/anaconda-ks.cfg
      /root/.bash_history
      [root@oldboyedu ~]# find ~ -type f -mtime 3  #第三天
      [root@oldboyedu ~]# find ~ -type f -mtime -3 #三天之后
      /root/.viminfo
      
      

7、グループ化(デフォルトは空白)

  • xargsの

    • グループとして、いくつかを指定する-n
    [root@oldboyedu ~]# echo {1..10} > text.txt
    [root@oldboyedu ~]# xargs -n 3 < text.txt 
    1 2 3
    4 5 6
    7 8 9
    10
    [root@oldboyedu ~]# xargs -n 5 < text.txt 
    1 2 3 4 5
    6 7 8 9 10
    [root@oldboyedu ~]# xargs -n 1 < text.txt 
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    [root@oldboyedu ~]# xargs  < text.txt 
    1 2 3 4 5 6 7 8 9 10
    
    • 指定された区切り文字を-d
    [root@oldboyedu ~]# xargs -n 1 < text.txt > text1.txt
    [root@oldboyedu ~]# cat text.txt 
    1 2 3 4 5 6 7 8 9 10
    [root@oldboyedu ~]# xargs -d "\n" < text1.txt 
    1 2 3 4 5 6 7 8 9 10
    [root@oldboyedu ~]# xargs -d "\n" -n 1 < text1.txt 
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    [root@oldboyedu ~]# xargs -d "\n" -n 3 < text1.txt 
    1 2 3
    4 5 6
    7 8 9
    10
    
    [root@oldboyedu ~]# xargs < text1.txt 
    1|2|3|4|5|6|7|8|9|10
    [root@oldboyedu ~]# xargs -d "|" < text1.txt 
    1 2 3 4 5 6 7 8 9 10
    
    
    • |パイプ記号
      • 結果はパイプラインの割り当てを実行する権利を残しました
    [root@oldboyedu ~]#  find /etc/sysconfig/network-scripts/ -type f  -name "ifcfg-eth0" | xargs ls -l 
    -rw-r--r--. 1 root root 362 Apr  4 18:08 /etc/sysconfig/network-scripts/ifcfg-eth0
    
    
    • 特別-i {}だけ以前の結果を見ているように

      [root@oldboyedu ~]#  find /etc/sysconfig/network-scripts/ -type f  -name "ifcfg-eth0" | xargs  cp {}  /opt/
      cp: target ‘/etc/sysconfig/network-scripts/ifcfg-eth0’ is not a directory
      [root@oldboyedu ~]#  find /etc/sysconfig/network-scripts/ -type f  -name "ifcfg-eth0" | xargs  -i cp {}  /opt/
      [root@oldboyedu ~]# ll /opt/
      total 4
      -rw-r--r--. 1 root root 362 Apr  9 19:00 ifcfg-eth0
      
      [root@oldboyedu ~]#  find /etc/sysconfig/network-scripts/ -type f  -name "ifcfg-eth0" | xargs -i  mv {}  /opt/
      [root@oldboyedu ~]# ll /opt/
      total 4
      -rw-r--r--. 1 root root 362 Apr  4 18:08 ifcfg-eth0
      
      
      

8、ディスプレイシステムの日付と時刻

  • 日付

    • システムの時刻を設定します。-s

      [root@oldboyedu ~]# date 
      Thu Apr  9 19:01:57 CST 2020
      [root@oldboyedu ~]# date -s "2020/01/01 00:00:00"
      Wed Jan  1 00:00:00 CST 2020
      [root@oldboyedu ~]# date
      Wed Jan  1 00:00:03 CST 2020
      [root@oldboyedu ~]# clock -w  #计入到主板里
      
      [root@localhost ~]# date +%F  #年月日
      2020-01-01
      [root@localhost ~]# date +%Y	#年
      2020
      [root@localhost ~]# date +%y	#年后两位
      20
      [root@localhost ~]# date +%m	#月
      01
      [root@localhost ~]# date +%d	#日
      01
      [root@localhost ~]# date +%H     #时
      00
      [root@localhost ~]# date +%M	 #分
      02
      [root@localhost ~]# date +%S	 #秒
      15
      

9、圧縮梱包

  • とり
    • -z圧縮
    • 作成-c
    • -v詳細
    • -fファイル
    • -t見ます
    • 指定された場所を抽出-C
    • -x解凍
    • -hファイル圧縮リンク
[root@oldboyedu /]# tar -zcvf data.tar.gz ./data
./data/
./data/1.txt
./data/2.txt
./data/3.txt
./data/4.txt
./data/5.txt
./data/6.txt
./data/7.txt
./data/8.txt
./data/9.txt
./data/10.txt
./data/a/
./data/b/
[root@oldboyedu /]# tar -zcvf /opt/data.tar.gz ./data
./data/
./data/1.txt
./data/2.txt
./data/3.txt
./data/4.txt
./data/5.txt
./data/6.txt
./data/7.txt
./data/8.txt
./data/9.txt
./data/10.txt
./data/a/
./data/b/
[root@oldboyedu /]# tar -tf /opt/data.tar.gz 
./data/
./data/1.txt
./data/2.txt
./data/3.txt
./data/4.txt
./data/5.txt
./data/6.txt
./data/7.txt
./data/8.txt
./data/9.txt
./data/10.txt
./data/a/
./data/b/

おすすめ

転載: www.cnblogs.com/sunyuhang1/p/12668985.html
おすすめ