linux Linux常见特殊符号 重定向符号
Linux中高级I/O 重定向的符号及其用法
符号 |
意义 |
n>&m |
将FD为m的输出复制到FD为n的文件中 |
n<&m |
将FD为m的输入复制到FD为n的文件中 |
n>&- |
关闭FD为n的输出 |
n<&- |
关闭FD为n的输入 |
&>file |
将标准输入和标准错误输出到重定向到文件 |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Linux常见特殊符号
1. > 重定向输出符号。
————————————————————————————————————————————————————————————————————————————
I/O重定向是Linux的重要内容。I/O重定向就是一个过程,在这个过程中捕捉一个文件、命令、程序或脚本,甚至代码块的输出,然后把捕捉到的输出作为输入发送到另一个文件、命令、程序或脚本。
基本I/O重定向符号和意义
序号 (举例) |
符号 |
意义 |
1 |
cmd1 md2 |
管道符,将cmd1的标准输出作为cmd2的标准输入 |
2 |
> filename |
将标准输出写到文件filename中 |
3 |
< filename |
将文件filename的内容读入到标准输出中去 |
4 |
>> filename |
将标准输出写到文件filename中,若filename存在则把内容追加到filename那么后面, |
5 |
>| filename |
即使noclobber选项开启,仍然强制将标准输出写到filename中,即把filename内容覆盖掉 |
6 |
n>|filename |
即使noclobber选项开启,仍然强制将FD为n的输出写到filename中,即把filename内容覆盖掉 |
7 |
n> filename |
将FD为n的输出写到filename文件中 |
8 |
n< filename |
将文件filename中内容读入到FD n中 |
9 |
n>> filename |
将FD为n的输出文件写到filename中,,若filename存在则把内容追加到filename那么后面, |
10 |
<< delimiter |
此处文档(Here——document) |
注:FD为文件标识符(File Descriptor)
文件标识符是从0到9结束的整数,指明了与进程有关的特定数据流源。当Linux系统启动一个进程(该进程可能用于执行Shell命令)时,将自动为该进程打开三个文件:标准输入、标准输出和标准错误输出,分别有文件标识符0、1、2标识,如果进程要打开其他的输入和输出文件,则从3开始标识。另外3-9是保留的标识符,可以把这些标识符指定为标准输入、标准输出和标准错误输出的临时连接。通常这样可以解决好多复杂的重定向请求。
举例1、
- [root@localhost shell]# ls -al |wc -l
- 95
2、
- [root@localhost shell]# cat >newfile #按住Ctrl+D结束编辑
- hello this is cherishyou's blog
- you can find some my dialog
- see you [root@localhost shell]#
- [root@localhost shell]# cat newfile
- hello this is cherishyou's blog
- you can find some my dialog
- see you
3
- [root@localhost shell]# wc < newfile #将newfile中的统计输出
- 2 13 68
4、
- [root@localhost shell]# ls /home/cherish/shell/ifexample/ >>newfile #在newfile文件后面追加内容
- [root@localhost shell]# cat newfile
- hello this is cherishyou's blog
- you can find some my dialog
- see you if
- if2
- if_exam
- if_exam1
- if_file1
- ifcopy
- ifeldel
- ifelifeise
- ifelse
- ifelse1
- ifelse2
- ifelse3
5、
- [root@localhost shell]# set -o noclobber #开启noclobber(不允许覆盖任何文件)
- [root@localhost shell]# ls /home/cherish/shell/ifexample/ > newfile #出现错误
- -bash: newfile: cannot overwrite existing file
- [root@localhost shell]# ls /home/cherish/shell/ifexample/ >| newfile #正常运行 !!注意区别
- [root@localhost shell]# cat newfile
- if
- if2
- if_exam
- if_exam1
- if_file1
- ifcopy
- ifeldel
- ifelifeise
- ifelse
- ifelse1
- ifelse2
- ifelse3
6、
- [root@localhost shell]# ls z* #无法访问
- ls: cannot access z*: No such file or directory
- [root@localhost shell]# ls z* >filefile #出现错误
- ls: cannot access z*: No such file or directory
- [root@localhost shell]# cat filefile
- [root@localhost shell]# ls z* 2> filefile #保存错误信息
- [root@localhost shell]# cat filefile
- ls: cannot access z*: No such file or directory
7、
- [root@localhost shell]# cat hello.c 1> filefile #显示标准输出结果
- [root@localhost shell]# cat filefile
- #include<stdio.h>
- main()
- {
- printf("HELLP\n");
- }
8、
- [root@localhost shell]# wc -l 0< filefile
- 5
9、
- [root@localhost shell]# cat hello.c 1>> filefile #在标准输出结果后面追加内容
- [root@localhost shell]# cat filefile
- #include<stdio.h>
- main()
- {
- printf("HELLP\n");
- }
- #include<stdio.h>
- main()
- {
- printf("HELLP\n");
- }
10、
- [root@localhost shell]# cat newfile
- if
- if2
- if_exam
- if_exam1
- [root@localhost shell]# cat >> newfile << good #提示若输入good则结束输入编辑
- > this is a file
- > very good
- > good
- [root@localhost shell]# cat newfile
- if
- if2
- if_exam
- if_exam1
- this is a file
- very good
linux Linux常见特殊符号 重定向符号相关推荐
- Linux中的特殊符号-重定向符号
重定向符号: 1.">"或"1>"输出重定向:把前面输出的东西输入到后边的文件中,会清除文件原有的内容. [root@Simile /]# echo ...
- 【Linux】Linux中常见的文件管理以及常用的符号命令的总结
一.文件管理的命令以及操作 操作 命令 注意点 文件/文件夹 创建 touch filename 如果是多个文件,文件名之间用 空格 隔开(eg:touch "hello word" ...
- linux的的符号,Linux 常见特殊符号
Linux 常见特殊符号 1,> 重定向输出符号 用法:命令 >文件名 特性:覆盖(当输入文件和输出文件是同一文件,文件内容被清空:不适合连续重定向) 典型应用:合并文件(cat a b ...
- 嵌入式linux工程师 考试,嵌入式Linux工程师常见笔试题.doc
嵌入式Linux工程师常见笔试题.doc 这些年,我既参加也组织了许多这种测试,在这过程中我意识到这些测试能为带面试者和被面试者提供许多有用信息,此外,撇开面试的压力不谈,这种测试也是相当有趣的. 从 ...
- Linux 通配符和特殊符号
linux 通配符和特殊符号 一.通配符 符号 说明 * 代表『 0 个到无穷多个』任意字符 ? 代表『一定有一个』任意字符 [ ] 同样代表『一定有一个在括号内』的字符(非任意字符).例如 [abc ...
- Linux命令中特殊符号
http://blog.chinaunix.net/uid-16946891-id-5088144.html 在shell中常用的特殊符号罗列如下: # ; ;; . , / \ 'string' | ...
- linux的常见命令解析
linux的常见命令解析 1.进入目录 语法: cd 目录 示例: cd /home #进入到home目录 目录存在可以用tab健自动提示出来 cd / cd ~ # /和~区别是 /是进入到根目录, ...
- linux 压缩文件夹格式,Linux下常见文件格式的压缩、解压小结
Linux下常见文件格式的压缩.解压小结 .tar 解包: tar xvf FileName.tar 打包:tar cvf FileName.tar DirName (注:tar是打包,不是压缩!) ...
- Linux下常见的文本处理命令
众所周知,在Linux下"一切皆文件"的原则,一切配置文件都可以以文本的方式进行编辑.存储.故对文本文件的操作能力,决定着你是否能够在Linux下操纵自如.今天,就写下几个关于Li ...
最新文章
- 决策树分类Decision tree classifier
- 电子科大邹权组招聘博后、科研助理和访问学生(生物信息学方向)
- 自行制作IT资产管理软件思路
- 阿里云混合云Apsara Stack 2.0发布,加速政企数智创新
- 聊聊高并发(二十)解析java.util.concurrent各个组件(二) 12个原子变量相关类
- 蓝桥杯之最大体积(数论+完全背包)
- Mac OS X终端的常用操作命令(UNIX指令)
- Android笔记 - android studio导入源码
- Windows 10 May 2020 中 WSL 与 WSL2 的性能比较
- 总结的Server.Mappath的用法
- QT创建和使用动态链接库
- 【组合优化】旅行商问题Traveling Salesman Problem(TSP)-概述
- matlab矩阵特征值分解,矩阵特征值分解与奇异值分解含义解析及应用
- 使用python批量压缩图片文件
- 高端域名出售如何选择交易平台?
- 世界的本质是什么---辩证的唯物论
- 增长黑客:如何低成本实现爆发式增长
- iOS 开发中的 Flux 架构模式
- 解决使用人人开源,搭建前端环境问题(renren-fast-vue)
- 箱体图如何排除异常点