美文网首页
Linux59期day09

Linux59期day09

作者: A宽宽 | 来源:发表于2019-04-08 20:12 被阅读0次

vim 故障

1.vim 执行过程

vim执行过程

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文件属性

image.png

相关文章

  • Linux59期day09

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

  • 自律给我自由—Day009

    【叶子姑娘的自律100天挑战 Day09】 2019.01.23 Day09/100 【早起】第十二天早起。 【阅...

  • Linux59期day12

    创建1个新目录他的硬链接数是2? 为何? 在这个目录下面创建1个新目录 /lidao/alex/ lidao目录...

  • Linux59期day05

    了解:/oldboy和/oldboy/ 区别?大部分命令是一样的./oldboy 表示oldboy目录和下面的内...

  • Linux59期day04

    Linux基础操作与命令 快捷键 Ctrl+c 取消当前操作 Ctrl+l 清屏 Ctrl+a 光标移到行首 C...

  • Linux59期day08

    1、vim编辑器的快捷键光标移动操作: l:光标向右移动h:光标向左移动j:光标向下移动k:光标向上移动gg或1G...

  • Linux59期day10

    文件类型: 扩展名:.avi .txt .log .shWindows:系统根据不同的扩展名,区分不...

  • Linux59期day03

    什么是救援模式? 解决故障 root密码忘记\服务器无法开机 linux磁盘分区方案 1.通用-数据不重要的时候...

  • Linux59期day02

    什么是操作系统? 人与硬件设备的中介/桥梁 Linux操作系统的组成? 外围应用程序 命令解释器 shell 系...

  • Linux59期day16

    正则表达式(Regular Expression RE) 什么是正则表达式: 发明一套符号,不同的符号有不同的...

网友评论

      本文标题:Linux59期day09

      本文链接:https://www.haomeiwen.com/subject/lnmyiqtx.html