zoukankan      html  css  js  c++  java
  • 红帽学习笔记[RHCSA] 第三课[输出重定向、Vi编辑器]

    第三课

    关于Linux的输入输出

    • 输入输出
    0  stdin  		标准输入    仅读取 
    1  stdout 		标准输出    仅写入
    2  stderr 		标准错误    仅写入
    3  filename  	其他文件    读取和/或写入
    
    • 输出重定向
    # > file 或 1 > file 标准输出重定向到file并覆盖文件
    [root@localhost test]# ls > stdout
    [root@localhost test]# cat stdout 
    11.txt
    22.txt
    stdout
    # >> file 或 1 >> file 标准输出重定向到file追加到文件结尾
    [root@localhost test]# ls >> stdout
    [root@localhost test]# cat stdout 
    11.txt
    22.txt
    stdout
    11.txt
    22.txt
    stdout
    # 2 > file 将标准错误重定向到file >>用法一致
    # 将标准输出或者标准错误丢弃
    [root@localhost test]# ls > /dev/null
    # >file 2>&1 或 &>file 将标准错误重定向到标准输出
    

    本次课程涉及的命令

    find查找某个名字的文件或者文件夹

    [root@localhost test]# find / -name test
    /root/test
    /var/lib/AccountsService/users/test
    /var/db/sudo/test
    /var/spool/mail/test
    /usr/bin/test
    /usr/lib/alsa/init/test
    /usr/lib64/python2.7/test
    /usr/lib64/python2.7/site-packages/OpenSSL/test
    /usr/lib64/python2.7/unittest/test
    /usr/share/espeak-data/voices/test
    /home/test
    /test
    # / 是查找的目录  test是查找的精确字符
    # 使用 通配符 * 表示匹配任意
    

    grep在某个文件中查找字符

    [root@localhost test]# grep boy 11.txt 
    I am boy
    # 带行数  -n
    [root@localhost test]# grep bo 11.txt  -n
    1:I am boy
    # -v不匹配
    [root@localhost test]# grep bo 11.txt  -nv
    2:I am girl
    3:hahahaha
    # -B查看前面的行数-A查看后面的行,会带出查找行以及前面或后面的行
    [root@localhost test]# grep bo 11.txt  -n -A1
    1:I am boy
    2-I am girl
    

    |管道前一个标准输出作为后面的标准输入

    [root@localhost test]#  cat /etc/passwd | grep root
    root:x:0:0:root:/root:/bin/bash
    operator:x:11:0:operator
    

    tee

    将标准输入复制到标注输出中,并且还会向标准输出输出内容。用于保存中间步骤的标注输出

    [root@localhost test]#  cat /etc/passwd |tee passwd.txt| grep root
    root:x:0:0:root:/root:/bin/bash
    operator:x:11:0:operator:/root:/sbin/nologin
    [root@localhost test]# ls
    11.txt  22.txt  passwd.txt  stderr  stdout
    

    vivim

    • 四种模式

      1. 命令模式
      2. 编辑模式
      3. 末行模式
      4. 可视化模式
    • 切换模式

      1. 刚进入vi时,是命令模式
        2. insert I i A a O o都可以进入编辑模式
      I :	再本行行首进行插入  
      i:	光标前面插入      
      a:	光标后面插入
      A: 	本行得行尾进行插入   
      o:	新建一行插入     
      O:	本行得上一行进行插入
      # -------------------
      按`ESC`退出编辑模式回到命令模式
      
      1. shift+; 也是是:可以进入末行模式
      2. Ctrl+VCtrl+v进入可视化模式
    • 命令模式命令汇总

    x :			光标在哪里删除哪里
    u : 		撤销操作
    Ctrl+r : 	重做撤销
    dw :		删除一个单词
    dd :		删除一行
    dG : 		删除光标行到文件末
    dgg :		删除光标行到文件首
    yy :		复制一行
    p :			粘贴
    5yy :		复制多行
    yw :		复制一个单词
    G :			到文件末尾
    gg :		到文件首部
    
    • 末行模式常用汇总
    q  	#离开
    w  	#保存
    x 	#保存离开 wq
    q! 	#强制离开
    r /test/11.txt	# 将11.txt文件的内容,追加到当前编辑文件的尾部
    
    • Linux 自带的vimtutor教程
  • 相关阅读:
    KindEditor自动过滤首行缩进和全角空格的解决方法
    网站流量、连接数等监控
    VSFTP的使用
    CentOs 设置静态IP
    MySQL 5.7版本sql_mode=only_full_group_by问题
    使用密钥登录CentOS系统(基于密钥的认证)
    FIRMWARE BUG – THE BIOS HAS CORRUPTED HW-PMU RESOURCES
    Ubuntu上的MySQL可以远程访问
    自动生成单据编号
    SQL Server 重置SA密码语句
  • 原文地址:https://www.cnblogs.com/primadonna/p/11422383.html
Copyright © 2011-2022 走看看