day10-第三周-vim補(bǔ)充和文件過濾

vim補(bǔ)充和文件過濾.png

1.vim &vim的故障

1.vim執(zhí)行過程
2.故障產(chǎn)生原因

①之前的文件沒有正常保存退出導(dǎo)致的
②同時(shí)打開1個(gè)文件

3.解決

①刪除這個(gè)臨時(shí)文件(推薦)
文件地址在錯(cuò)誤提示中

②把臨時(shí)文件的內(nèi)容恢復(fù)
vim -r 回車 就恢復(fù)了

2.別名 alias 給命令起的小名

用處:
1.給危險(xiǎn)的命令加上保護(hù)
2.省事 方便
格式:

    alias  rm='命令'
    unalias rm 取消別名
    坑:/etc/profile 和/root.bashrc 要添加注釋里面的別名 rm
alias  rm='echo command bny...' 可以讓rm命令失效,更加安全

alias net='cat /etc/sysconfig/network-scripts/ifcfg-eth0' (修改網(wǎng)卡別名)

輸入net 顯示網(wǎng)卡配置文件內(nèi)容

1.臨時(shí)-重新登錄之后失效
[root@lcx01 ~]# alias net='cat /etc/sysconfig/network-scripts/ifcfg-eth0'
[root@lcx01 ~]# net
TYPE=Ethernet
BOOTPROTO=none
NAME=eth0
UUID=fa77146b-1e0c-4544-8ecb-5a98a6ebfc41
DEVICE=eth0
ONBOOT=yes
IPADDR=10.0.0.201
PREFIX=24
GATEWAY=10.0.0.254
DNS1=10.0.0.254
DNS2=223.5.5.5
2.永久 /etc/profile
[root@lcx01 ~]# tail -1 /etc/profile
alias net='cat /etc/sysconfig/network-scripts/ifcfg-eth0'

讓配置生效

[root@lcx01 ~]# source  /etc/profile
3.檢查
[root@lcx01 ~]# alias net
alias net='cat /etc/sysconfig/network-scripts/ifcfg-eth0'

3.grep 過濾 在文件中進(jìn)行查找

grep -n  顯示行號
grep -i  不區(qū)分大小寫
grep -v  取反/排除
grep -w  按照單詞進(jìn)行過濾

1. -n 顯示行號

grep 'ssh' -n /tmp/vim.log

 [root@lcx01 ~]# grep 'ssh' -n /tmp/vim.log 
46:ssh             22/tcp                          # The Secure Shell (SSH) Protocol
47:ssh             22/udp                          # The Secure Shell (SSH) Protocol
552:x11-ssh-offset  6010/tcp                        # SSH X11 forwarding offset
592:ssh             22/sctp                 # SSH
1374:sshell          614/tcp                 # SSLshell
1375:sshell          614/udp                 #       SSLshell
1628:netconf-ssh     830/tcp                 # NETCONF over SSH
1629:netconf-ssh     830/udp                 # NETCONF over SSH
7213:sdo-ssh         3897/tcp                # Simple Distributed Objects over SSH
7214:sdo-ssh         3897/udp                # Simple Distributed Obj....
.....
  centos 7下面默認(rèn)就有  centos 6之前版本需要手動配置顯示行號的顏色
  alias grep='grep --color=auto'

2. -w按照單詞進(jìn)行過濾

grep -wn '22' /tmp/vim.log

[root@lcx01 ~]#  grep -wn '22'  /tmp/vim.log 
46:ssh             22/tcp                          # The Secure Shell (SSH) Protocol
47:ssh             22/udp                          # The Secure Shell (SSH) Protocol
592:ssh             22/sctp                 # SSH
1944:c1222-acse      1153/tcp                # ANSI C12.22 Port
1945:c1222-acse      1153/udp                # ANSI C12.22 Port
11285:ssh             22/tcp                          # The Secure Shell (SSH) Protocol
11286:ssh             22/udp                          # The Secure Shell (SSH) Protocol
11831:ssh             22/sctp                 # SSH
13183:c1222-acse      1153/tcp                # ANSI C12.22 Port
13184:c1222-acse      1153/udp                # ANSI C12.22 Port

3. -i 過濾時(shí)不區(qū)分大小寫

grep -wni 'ipaddr' /tmp/vim.log

  [root@lcx01 ~]# grep -i 'ipaddr' /tmp/vim.log 
  IPADDR=10.0.0.201
  IPADDR=10.0.0.201
  IPADDR=10.0.0.201
  IPADDR=10.0.0.201

4. -v 排除/取反 不包含的

grep -v '#' /tmp/vim.log

[root@lcx01 ~]#  grep -vn '#' /tmp/vim.log 
22:
27:echo            7/tcp
28:echo            7/udp
29:discard         9/tcp           sink null
30:discard         9/udp           sink null
31:systat          11/tcp          users
32:systat          11/udp          users
33:daytime         13/tcp
34:daytime         13/udp
35:qotd            17/tcp          quote
36:qotd            17/udp          quote
39:chargen         19/tcp          ttytst source
40:chargen         19/udp          ttytst source
......

4.tr 簡單1對1的替換

< 輸入重定向:如果不輸< 會報(bào)錯(cuò)

例把o替換為0:

   [root@lcx01 ~]# tr 'o' '0' </tmp/lcx.txt 
   alex
   olcXL0cx
   alibobolcx001
   LCOx 0lcX
   LCX
'a-z' 'A-Z' 小寫替換為大寫:
   [root@lcx01 ~]# tr 'a-z' 'A-Z' </tmp/lcx.txt 
   alex
   olcXL0cx
   alibobolcx001
   LCOx 0lcX
   LCX

5.Linux文件屬性

https://www.processon.com/view/link/5caac6c5e4b06765f08823bb

[root@lcx01 ~]# ls -lhi
total 16K
33574978 -rw-------. 1 root root 1.5K Mar 26 14:05 anaconda-ks.cfg
33788998 -rw-r--r--  1 root root  686 Mar 28 19:05 bashrc
16810233 drwxr-xr-x  3 root root   18 Apr  6 19:20 data
  206197 -rw-r--r--  1 root root  712 Apr  7 22:59 day08vim
33618790 -rw-r--r--  1 root root    0 Apr  7 23:40 ett.txt
   73411 drwxr-xr-x  3 root root   77 Apr  7 23:00 lcx
33575026 -rw-r--r--  1 root root  970 Apr  4 16:13 passwd.bak
16948566 drwxr-xr-x  2 root root   19 Apr  7 23:44 tmp
   1     2    3    4 5  6    7     8  -----9------  10
1. inode號碼索引節(jié)點(diǎn)
2. 第1位 文件類型
3. 第2-10位 權(quán)限
4. 點(diǎn). SELinux相關(guān)
5. 硬鏈接的數(shù)量 1個(gè)文件不同的入口
6. 所有者 
7. 所屬用戶組
8. 文件大小
9. 文件的修改時(shí)間
10.文件名和目錄 不是文件屬性
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容