vim 故障
1.vim 执行过程
![](https://img.haomeiwen.com/i16955051/df00908074400e88.png)
2.故障产生原因
a.同时打开一个文件
b.之前的文件没有正常保存退出导致的
3.解决
方式一 删除这个临时文件 (推荐) 错误提示中有临时文件的名字
方式二 把临时文件的内容恢复(不推荐)
4.故障重现
echo oldboyedu.com >/tmp/oldboy.txt
vim /tmp/oldboy.txt
断开连接然后重新连接。
方式1 删除这个临时文件(推荐)
错误提示中 有这个文件的名字。
方法2 把临时文件的内容恢复(不推荐)
[root@oldboyedu59 ~]# vim -r /tmp/oldboy.txt
oldboyedu.com
guoav.com
guoav.com
guoav.com
guoav.com
guoav.com
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
"/tmp/oldboy.txt" 6L, 64C written
[root@oldboyedu59 ~]#
[root@oldboyedu59 ~]# cat /tmp/oldboy.txt
oldboyedu.com
guoav.com
guoav.com
guoav.com
guoav.com
guoav.com
[root@oldboyedu59 ~]# rm -f /tmp/.oldboy.txt.swp
[root@oldboyedu59 ~]# vim /tmp/oldboy.txt
oldboyedu.com
guoav.com
guoav.com
guoav.com
guoav.com
guoav.com
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
[root@oldboyedu59 ~]#
别名
给命令起个小名
1.危险命令加上保护
2.省事 方便
配置格式
alias 小名='命令'
输入net 显示网卡配置文件内容
1.临时 -重新登录之后失效
alias net='cat /etc/sysconfig/network-scripts/ifcfg-eth0'
2.永久 /etc/profile (/etc/bashrc)
[root@oldboy59 ~]# vim /etc/profile
# /etc/profile
# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc
# It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates.
pathmunge () {
case ":${PATH}:" in
*:"$1":*)
;;
*)
if [ "$2" = "after" ] ; then
PATH=$PATH:$1
else
PATH=$1:$PATH
fi
esac
}
"/etc/profile" 76L, 1819C 1,1 Top
# By default, we want umask to get set. This sets it for login shell
# Current threshold for system reserved uid/gids is 200
# You could check uidgid reservation validity in
# /usr/share/doc/setup-*/uidgid file
if [ $UID -gt 199 ] && [ "`/usr/bin/id -gn`" = "`/usr/bin/id -un`" ]; then
umask 002
else
umask 022
fi
for i in /etc/profile.d/*.sh /etc/profile.d/sh.local ; do
if [ -r "$i" ]; then
if [ "${-#*i}" != "$-" ]; then
. "$i"
else
. "$i" >/dev/null
fi
fi
done
unset i
unset -f pathmunge
"/etc/profile" 77L, 1877C written
让文件生效:[root@oldboy59 ~]# source /etc/profile
3.检查
[root@oldboy59 ~]# tail -1 /etc/profile
alias net='cat /etc/sysconfig/network-scripts/ifcfg-eth0'
三剑客老三-grep 过滤
vim 编辑文件 /oldboy
[root@oldboy59 ~]# alias grep centos7 默认就有 centos6 5 需要手动配置
alias grep='grep --color=auto'
-n 显示行号
grep 'ssh' /tmp/vim.log
grep -n 'ssh' /tmp/vim.log
按照单词过滤:
[root@oldboy59 ~]# grep -w '22' /tmp/vim.log
ssh 22/tcp # The Secure Shell (SSH) Protocol
ssh 22/udp # The Secure Shell (SSH) Protocol
ssh 22/sctp # SSH
c1222-acse 1153/tcp # ANSI C12.22 Port
c1222-acse 1153/udp # ANSI C12.22 Port
ssh 22/tcp # The Secure Shell (SSH) Protocol
ssh 22/udp # The Secure Shell (SSH) Protocol
ssh 22/sctp # SSH
c1222-acse 1153/tcp # ANSI C12.22 Port
c1222-acse 1153/udp # ANSI C12.22 Port
过滤的时候不区分大小写:-i ignore-case
[root@oldboy59 ~]# grep -i 'ipaddr' /tmp/vim.log
IPADDR=10.0.0.201
IPADDR=10.0.0.201
grep 排除/取反 -v
我想找出不包含#的行
[root@oldboy59 ~]# grep -v '#' /tmp/vim.log
tr 简单1对1替换
<输入重定向
grep命令练习题:
准备环境:
cat >/tmp/oldboy.txt<<EOF
oldboy
alex
oldboyoldboy
alexoldboy
Oldboy oLdboy
OLDBOY
EOF
把o替换成0
[root@oldboy59 ~]# tr 'o' '0' < /tmp/oldboy.txt
0ldb0y
alex
0ldb0y0ldb0y
alex0ldb0y
Oldb0y 0ldb0y
OLDBOY
把所有小写替换成大写:
[root@oldboy59 ~]# tr 'a-z' 'A-Z' < /tmp/oldboy.txt
OLDBOY
ALEX
OLDBOYOLDBOY
ALEXOLDBOY
OLDBOY OLDBOY
OLDBOY
Linux文件属性
![](https://img.haomeiwen.com/i16955051/9f3ead63be02b5dc.png)
网友评论