Linux 输出的重定向

Linux 环境中支持输入输出重定向,用符号来表示。 将当前目录下的文件以长模式显示,然后写入 listfile 文件:

[root@localhost ~]# ls -l > listfile
[root@localhost ~]# cat listfile
total 12
drwxr-xr-x. 2 root root    6 Jul 19 10:52 -
-rw-------. 1 root root 2262 Sep  2  2021 anaconda-ks.cfg
drwxr-xr-x. 2 root root   22 Jul 20 13:14 Desktop
drwxr-xr-x. 2 root root    6 Jul 19 10:51 dirtest
drwxr-xr-x. 2 root root    6 Sep  2  2021 Documents
drwxr-xr-x. 2 root root    6 Sep  2  2021 Downloads
-rw-r--r--. 1 root root 2310 Sep  2  2021 initial-setup-ks.cfg
-rw-r--r--. 1 root root    0 Aug 14 13:31 listfile
drwxr-xr-x. 2 root root    6 Sep  2  2021 Music
drwxr-xr-x. 3 root root   19 Jul 19 10:53 mytest
drwxr-xr-x. 2 root root    6 Jul 19 10:52 p
drwxr-xr-x. 2 root root 4096 Jul 19 12:58 Pictures
drwxr-xr-x. 2 root root    6 Sep  2  2021 Public
drwxr-xr-x. 2 root root    6 Sep  2  2021 Templates
drwxrwxrwx. 2 root root    6 Jul 19 10:54 testmod
drwxr-xr-x. 3 root root   17 Jul 21 09:26 u02
drwxr-xr-x. 2 root root    6 Sep  2  2021 Videos
[root@localhost ~]# 

使用>进行输出重定向,文件的原内容会被覆盖,可以使用>>将输出追加入文件:

[root@localhost ~]# ll /home/oracle >> listfile
[root@localhost ~]# cat listfile
total 12
drwxr-xr-x. 2 root root    6 Jul 19 10:52 -
-rw-------. 1 root root 2262 Sep  2  2021 anaconda-ks.cfg
drwxr-xr-x. 2 root root   22 Jul 20 13:14 Desktop
drwxr-xr-x. 2 root root    6 Jul 19 10:51 dirtest
drwxr-xr-x. 2 root root    6 Sep  2  2021 Documents
drwxr-xr-x. 2 root root    6 Sep  2  2021 Downloads
-rw-r--r--. 1 root root 2310 Sep  2  2021 initial-setup-ks.cfg
-rw-r--r--. 1 root root    0 Aug 14 13:31 listfile
drwxr-xr-x. 2 root root    6 Sep  2  2021 Music
drwxr-xr-x. 3 root root   19 Jul 19 10:53 mytest
drwxr-xr-x. 2 root root    6 Jul 19 10:52 p
drwxr-xr-x. 2 root root 4096 Jul 19 12:58 Pictures
drwxr-xr-x. 2 root root    6 Sep  2  2021 Public
drwxr-xr-x. 2 root root    6 Sep  2  2021 Templates
drwxrwxrwx. 2 root root    6 Jul 19 10:54 testmod
drwxr-xr-x. 3 root root   17 Jul 21 09:26 u02
drwxr-xr-x. 2 root root    6 Sep  2  2021 Videos
total 0
[root@localhost ~]# 

备注:可以使用 cat file1 > file2 命令实现文件 file1 到 file2 的拷贝。cat file* > file 可将数个小文件合并成一个大文件。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值