day10-第三周-vim补充和文件过滤

vim补充和文件过滤.png

1.vim &vim的故障

1.vim执行过程
2.故障产生原因

①之前的文件没有正常保存退出导致的
②同时打开1个文件

3.解决

①删除这个临时文件(推荐)
文件地址在错误提示中

②把临时文件的内容恢复
vim -r 回车 就恢复了

2.别名 alias 给命令起的小名

用处:
1.给危险的命令加上保护
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' (修改网卡别名)

输入net 显示网卡配置文件内容

1.临时-重新登录之后失效
[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 过滤 在文件中进行查找

grep -n  显示行号
grep -i  不区分大小写
grep -v  取反/排除
grep -w  按照单词进行过滤

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下面默认就有  centos 6之前版本需要手动配置显示行号的颜色
  alias grep='grep --color=auto'

2. -w按照单词进行过滤

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 过滤时不区分大小写

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的替换

< 输入重定向:如果不输< 会报错

例把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号码索引节点
2. 第1位 文件类型
3. 第2-10位 权限
4. 点. SELinux相关
5. 硬链接的数量 1个文件不同的入口
6. 所有者 
7. 所属用户组
8. 文件大小
9. 文件的修改时间
10.文件名和目录 不是文件属性
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容