1、改错
[root@lidao ~]# vim /tmp/oldboy.txt
vim编写文件突然关闭Linux系统两种方法
[root@lidao ~]# vim /tmp/oldboy.txt再次打开
E325: ATTENTION
Found a swap file by the name "/tmp/.oldboy.txt.swp"
owned by: root dated: Mon Apr 8 16:26:39 2019
file name: /tmp/oldboy.txt
modified: YES
user name: root host name: lidao
process ID: 7594
While opening file "/tmp/oldboy.txt"
(1) Another program may be editing the same file. If this is the c
ase,
be careful not to end up with two different instances of the sa
me
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:
1、删除
[root@lidao ~]# rm -rf /tmp/oldboy.txt
2、启用原文件
(R)ecoverrR
123
123
123
123
123
~
~
-- REPLACE --
2、跟改alias别名
(一)暂时跟改别名
alias net='cat /etc/sysconfig/network-scripts/ifcfg-eth0'
[root@lidao ~]# net
TYPE=Ethernet #以太网
OXY_METHOD=none
▽ROWSER_ONLY=no
BOOTPROTO=none #启动协议。静态,动态
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=eth0
UUID=69f0aa6f-50b3-4aab-9089-60d4748d26bc
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
IPV6_PRIVACY=no
(二)永久修改
[root@lidao ~]# vim /etc/profile
export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL
# 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
alias net='cat /etc/sysconfig/network-scripts/ifcfg-eth0'#添加内容
"/etc/profile" 78L, 1878C written
生效source /etc/profile
[root@lidao ~]# source /etc/profile
(三)检查
最后一行
[root@lidao ~]# tail -3 /etc/profile
unset -f pathmunge
alias net='cat /etc/sysconfig/network-scripts/ifcfg-eth0'
[root@lidao ~]# alias net
alias net='cat /etc/sysconfig/network-scripts/ifcfg-eth0'
grep过滤查找
[root@lidao ~]# alias grep
alias grep='grep --color=auto' #centos 7下面 默认就有 CentOS6 5需要手动配置
grep小结:
-n 显示行号和内容
-i 不区分大小写
-v 取反或排除
-w 按照单词进行过滤
grep命令练习题:
准备环境:
cat >/tmp/oldboy.txt<<EOF
oldboy
alex
oldboyoldboy
alexoldboy
Oldboy oLdboy
OLDBOY
EOF
1.过滤出文件中包含oldboy的行及行号
2.过滤出文件中包含oldboy(不区分大小写)的行及行号
3.过滤出不包含oldboy(不区分大小写)的行
4.按单词过滤出oldboy(不区分大小写)
[root@lidao ~]# grep -n 'oldboy' /tmp/oldboy.txt
1:oldboy
3:oldboyoldboy
4:alexoldboy
[root@lidao ~]# grep -in 'oldboy' /tmp/oldboy.txt
1:oldboy
3:oldboyoldboy
4:alexoldboy
5:Oldboy oLdboy
6:OLDBOY
[root@lidao ~]# grep -iv 'oldboy' /tmp/oldboy.txt
alex
[root@lidao ~]# grep -iw 'oldboy' /tmp/oldboy.txt
oldboy
Oldboy oLdboy
OLDBOY
3、tr替换
[root@lidao ~]# tr 'o' '0' /tmp/oldboy.txt
tr: extra operand ‘/tmp/oldboy.txt’
Try 'tr --help' for more information.
[root@lidao ~]# tr 'o' '0' < /tmp/oldboy.txt #不加小于号认为是命令
0ldb0y
alex
0ldb0y0ldb0y
alex0ldb0y
Oldb0y 0Ldb0y
OLDBOY
[root@lidao ~]# tr 'a-z' 'A-Z'</tmp/oldboy.txt
OLDBOY
ALEX
OLDBOYOLDBOY
ALEXOLDBOY
OLDBOY OLDBOY
OLDBOY
4、ls -lhi
[root@lidao ~]# ls -lhi
total 16K
33575024 -rw-r--r-- 1 root root 35 Apr 4 17:11 all.txt
33574978 -rw-------. 1 root root 1.5K Mar 26 11:43 anaconda-ks.cfg
16814991 drwxr-xr-x 12 root root 106 Apr 4 16:34 oldboy
33583369 -rw-r--r-- 1 root root 1 Apr 4 16:50 oldboy.txt
16778590 drwxr-xr-x. 2 root root 6 Mar 27 20:34 oldman
33583367 -rw-r--r-- 1 root root 7 Apr 3 20:18 old.txt
33583365 -rw-r--r-- 1 root root 0 Apr 3 19:21 s.txt