zoukankan      html  css  js  c++  java
  • linux Shell重定向


    Linux文件描述符:默认打开三个文件描述符:标准输入standard input 0,正确输出standard output 1,错误输出:error output 2

    输出重定向


    command-line1 [1-n] > file或文件操作符或设备


    首先是判断>右边的文件是否存在,存在的话就首先删除然后再创建,无论左边命令执行是否成功,右边文件都会变为空。使用>>为文件的追加方式。

    [Unix@17:18:57 ~]$ls > a.txt
    [Unix@
    17:19:11 ~]$cat a.txt
    a.txt
    cpp
    ctest
    Makefile
    network
    shell
    socket
    test
    thread


    输入重定向


    command-line [n] <file或文件描述符&设备

    [Unix@17:20:59 ~]$cat>a<a.txt
    [Unix
    @17:21:36 ~]$cat a
    a.txt
    cpp
    ctest
    Makefile
    network
    shell
    socket
    test
    thread


    exec绑定重定向


    exec 文件描述符[n] <或> file或文件描述符或设备


    在上面讲的输入,输出重定向 将输入,输出绑定文件或设备后,只对当前那条指令是有效的。如果需要在绑定之后,接下来的所有命令都支持的话,就需要用exec命令。

    [Unix@17:26:02 ~]$exec 1>a.txt
    [Unix
    @17:26:11 ~]$ls -al
    [Unix
    @17:26:16 ~]$exec 1>/dev/tty #恢复标准输出
    [Unix@17:26:25 ~]$ls
    a.txt cpp ctest Makefile network shell socket test thread

  • 相关阅读:
    ureport2 数据源配置
    ureport2 + spring boot 搭建
    alibaba
    Maven Helper
    在Idea中连接数据库并生成实体类
    Intellij jrebel 热部署 安装
    IDEA使用说明
    JPA 常用注解 (hibernate)
    vue + canvas 图片加水印
    vue——批量下载图片
  • 原文地址:https://www.cnblogs.com/feisky/p/1991672.html
Copyright © 2011-2022 走看看