2019-04-08vim排错、文件属性与grep基础

4月8日笔记整理vim排错、文件属性与grep基础

Vim常见故障

1. vim执行过程

① vi打开文件oldboy.txt
② 进入编辑模式编辑文件
③ 编辑文件时,vi会自动创建一个临时文件(.oldboy.txt.swp)

[root@guanggege ~]# ls -a /tmp
.          
 .oldboy.txt.swp 
oldboy.txt

④ 编辑完成,vi会自动删除临时文件(保存退出时)
⑤ 退出,修改成功

2. 故障原因:

① 编辑文件时突然断开
② 多窗口同时编辑同一个文件

3. 解决方法

当未保存的数据不重要时,删除临时文件

① 报错信息


E325: ATTENTION
Found a swap file by the name "/tmp/.oldboy.txt.swp"
          owned by: root   dated: Mon Apr  8 09:51:18 2019
         file name: /tmp/oldboy.txt
          modified: YES
         user name: root   host name: guanggege
        process ID: 7591
While opening file "/tmp/oldboy.txt"
             dated: Mon Apr  8 11:17:14 2019
      NEWER than swap file!

(1) Another program may be editing the same file.  If this is the case,
    be careful not to end up with two different instances of the same
    file when making changes.  Quit, or continue with caution.
(2) An edit session for this file crashed.
    If this is the case, use ":recover" or "vim -r /tmp/oldboy.txt"
    to recover the changes (see ":help recovery").
    If you did this already, delete the swap file "/tmp/.oldboy.txt.swp"
    to avoid this message.

Swap file "/tmp/.oldboy.txt.swp" already exists!
[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort:

② 回车
③ q退出编辑
④ 命令行删除临时文件(rm –rf .oldboy.txt.swp)

[root@guanggege ~]# rm  -rf /tmp/.oldboy.txt.swp
[root@guanggege ~]# 
当未保存的数据重要时,从临时文件中恢复数据然后删除

① 报错信息
② 回车
③ Q退出编辑,命令行恢复数据(vim –r oldboy.txt)

[root@guanggege ~]# vim -r /tmp/oldboy.txt

④ 恢复的文件内容要保存退出(:wq)
⑤ 命令行删除临时文件(rm –rf .oldboy.txt.swp)

别名:给命令起的小名

用途:

① 危险命令加上保护
② 长命令变短,省事

修改别名:

① 临时修改,重新登录后失效

[root@guanggege ~]#  alias net=’cat /etc/sysconfigg/network-scripts/ifcfg-eth0’

② 永久修改,在/etc/profile
tail -1 /etc/profile

[root@guanggege ~]# tail -1 /etc/profile
alias net='cat /etc/syscofig/network-scripts/ifcfg-eth0'

alias net=’cat /etc/sysconfigg/network-scripts/ifcfg-eth0’
source /etc/profile生效

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

③ 检查 alias net

[root@guanggege ~]# alias net
alias net='cat /etc/syscofig/network-scripts/ifcfg-eth0'
[root@guanggege ~]# 
临时取消别名

\rm或/usr/bin/rm或unalias rm

三剑客老三-grep 过滤,在文件中查找

alias grep=’grep –color=auto’ 只在centos7下默认有,centos5,6需要手动配置

[root@guanggege ~]# alias  grep
alias grep='grep --color=auto'
grep –n 显示行号和内容
[root@guanggege ~]# grep  -n 'oldboy' /tmp/oldboy.txt
1:oldboy
3:oldboyoldboy
4:alexoldboy
[root@guanggege ~]# 
grep –w 按照单词进行过滤(相邻没有其他字符)
[root@guanggege ~]# grep  -w 'oldboy' /tmp/oldboy.txt
oldboy
[root@guanggege ~]# 
grep –I 过滤的时候忽略大小写
[root@guanggege ~]# grep  -i 'oldboy' /tmp/oldboy.txt
oldboy
oldboyoldboy
alexoldboy
Oldboy oLdboy
OLDBOY
[root@guanggege ~]# 
grep –v 排除/取反,找出不包含内容的行
[root@guanggege ~]# grep  -v 'oldboy' /tmp/oldboy.txt
alex
Oldboy oLdboy
OLDBOY
[root@guanggege ~]# 

tr 简单的1对1替换 必须加入<输入重定向

只能1对1字符替换,不能替换字符串

[root@guanggege ~]# tr 'o' '0' < /tmp/oldboy.txt
0ldb0y
alex
0ldb0y0ldb0y
alex0ldb0y
Oldb0y 0Ldb0y
OLDBOY
[root@guanggege ~]# 

序列'1-3' 'a-c'(只能1对1)

Linux文件属性

2019-04-08vim排错、文件属性与grep基础_第1张图片
文件属性简图.png

你可能感兴趣的:(2019-04-08vim排错、文件属性与grep基础)