本文介绍: 重定向 > Linux 允许将命令执行结果重定向一个文件,本应显示终端上的内容保存指定文件中。如:ls >test.txt ( test.txt 如果不存在,则创建存在覆盖内容 )。;重定向>>>>这个是将输出内容追加目标文件中。如果文件不存在,就创建文件;如果文件存在,则将新的内容追加到那个文件末尾,该文件中的原有内容不受影响

目录

1、重定向命令

1.1 重定向 >

1.2 重定向 >>


章节的所有操作都在/export/data/shell目录进行,请提前创建目录

mkdir –p  /export/data/

1、重定向命令

1.1 重定向 >

Linux 允许将命令执行结果重定向到一个文件,本应显示在终端上的内容保存指定文件中。如:ls >test.txt ( test.txt 如果不存在,则创建,存在则覆盖其内容 )。

案例

将/目录下文件的详情保存test.txt文件中

ll  / > test.txt

查看文件内容:cat test.txt

总用量 28

lrwxrwxrwx.   1 root root    7 3月  31 06:05 bin -> usr/bin

dr-xrxr-x.   5 root root 4096 3月  31 06:22 boot

drwxr-xr-x.   3 root root   18 5月  12 09:15 data

drwxr-xr-x.  20 root root 3320 5月  10 15:48 dev

drwxr-xr-x. 132 root root 8192 5月  12 10:27 etc

drwxr-xr-x.   3 root root   18 5月   7 20:25 export

drwxr-xr-x.   3 root root   20 4月   9 10:16 home

drwxrxr-x.   2 root root    6 11月  5 2016 media

drwxr-xr-x.   5 root root   41 4月   7 16:23 opt

dr-xr-xr-x. 206 root root    0 5月  10 15:47 proc

dr-xr-x—.  24 root root 4096 5月  12 15:43 root

drwxr-xr-x.  38 root root 1180 5月  10 15:48 run

lrwxrwxrwx.   1 root root    8 3月  31 06:05 sbin -> usr/sbin

drwxr-xr-x.   2 root root    6 11月  5 2016 srv

dr-xr-xr-x.  13 root root    0 5月  10 15:48 sys

drwxrwxrwt.  25 root root 4096 5月  12 16:32 tmp

drwxr-xr-x.  13 root root  155 3月  31 06:05 usr

drwxr-xr-x.  20 root root  282 3月  31 06:22 var

根绝结果发现命令的执行结果已经写入test.txt文件中了。

1.2 重定向 >>

>>这个是将输出内容追加目标文件中。如果文件不存在,就创建文件;如果文件存在,则将新的内容追加到那个文件的末尾,该文件中的原有内容不受影响

案例:

 现在有个文件1.txt,内容如下,现在将整个文件的内容追加到上一个案例的test.txt文件中

Hadoop HDFS MapReduce

Zookeeper Hive HBase

实现方式:

cat 1.txt >> test.txt

查看test.txt内内容:cat test.txt

总用量 28

lrwxrwxrwx.   1 root root    7 3月  31 06:05 bin -> usr/bin

dr-xr-xr-x.   5 root root 4096 3月  31 06:22 boot

drwxr-xr-x.   3 root root   18 5月  12 09:15 data

drwxr-xr-x.  20 root root 3320 5月  10 15:48 dev

drwxr-xr-x. 132 root root 8192 5月  12 10:27 etc

drwxr-xr-x.   3 root root   18 5月   7 20:25 export

drwxr-xr-x.   3 root root   20 4月   9 10:16 home

drwxr-xr-x.   2 root root    6 11月  5 2016 media

drwxr-xr-x.   5 root root   41 4月   7 16:23 opt

dr-xr-xr-x. 206 root root    0 5月  10 15:47 proc

dr-xr-x—.  24 root root 4096 5月  12 15:43 root

drwxr-xr-x.  38 root root 1180 5月  10 15:48 run

drwxr-xr-x.   2 root root    6 11月  5 2016 srv

dr-xr-xr-x.  13 root root    0 5月  10 15:48 sys

drwxrwxrwt.  25 root root 4096 5月  12 16:32 tmp

drwxr-xr-x.  13 root root  155 3月  31 06:05 usr

drwxr-xr-x.  20 root root  282 3月  31 06:22 var

drwxr-xr-x.   3 root root   17 4月   8 16:17 xxx

doop HDFS MapReduce

Zookeeper Hive HBase

通过查看结果发现test.txt中已经有了1.txt文件的内容,实现了追加。

【下一章】

四、虚拟机网络配置

【往期回顾】

一、Linux系统概述和安装
二、Linux基础命令

原文地址:https://blog.csdn.net/zhuyangyong/article/details/134714675

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任

如若转载,请注明出处:http://www.7code.cn/show_21706.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱suwngjj01@126.com进行投诉反馈,一经查实,立即删除

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注