三、Linux高级命令

目录

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-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

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基础命令
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zhuyangyong

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值