2019-04-08改错与alias别名、grep查找、tr替换、ls-lhi文件信息

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
文件属性
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 输入net 显示网卡配置文件内容 三剑客老三-grep 过滤 在文件中进行查找。 vim 编辑文件 /oldboy...
    Sunshine阳光_1db4阅读 1,820评论 0 0
  • 一、vim故障 1. vim执行过程 2. 故障产生原因 1.同时打开1个文件2.之前的文件没有正常保存退出 导致...
    七两三_e13f阅读 2,087评论 0 0
  • Linux启动过程 1.开机自检BIOS 2.MBR引导 3.GRUB菜单 4.加载内核 5.运行init进程 6...
    康乐_SH阅读 3,349评论 0 0
  • 原来并非不快乐, 只我一人未发觉。 若能忘掉渴望, 岁月长,衣裳薄。 放心吃喝。 不假设你在身旁,我也可畅游异国,...
    夜未央盼花香浓阅读 1,508评论 0 0
  • 人生,一辈子拼杀 有时高悬真理,有时践踏道德 从春到冬,从黎明到黑夜 从未停息 而今 天色已晚,还欲杀个铠甲不留 ...
    山中老鱼阅读 3,077评论 0 0