day10-Linux运维-vim补充和文件过滤

在这里插入图片描述

1.vim &vim的故障

1.vim执行过程
2.故障产生原因
①之前的文件没有正常保存退出导致的
②同时打开1个文件

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

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

image.png

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@oldboyedu59 ~]# alias net='cat /etc/sysconfig/network-scripts/ifcfg-eth0'
[root@oldboyedu59 ~]# 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@oldboyedu59 ~]# tail -1 /etc/profile
alias net='cat /etc/sysconfig/network-scripts/ifcfg-eth0'

让配置生效

[root@oldboyedu59 ~]# source  /etc/profile

3.检查

[root@oldboyedu59 ~]# 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@oldboy59 ~]# 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@oldboy59 ~]#  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@oldboy59 ~]# 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@oldboy59 ~]#  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@oldboy59 ~]# tr 'o' '0' </tmp/oldboy.txt 
   0ldb0y
   alex
   0ldb0y0ldb0y
   alex0ldb0y
   Oldb0y 0Ldb0y
   OLDBOY

’a-z’ ‘A-Z’ 小写替换为大写:

   [root@oldboy59 ~]# tr 'a-z' 'A-Z' </tmp/oldboy.txt 
   OLDBOY
   ALEX
   OLDBOYOLDBOY
   ALEXOLDBOY
   OLDBOY OLDBOY
   OLDBOY

5.Linux文件属性

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

[root@oldboy59 ~]# 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.文件名和目录 不是文件属性

image.png

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值