标准IO和管道实验练习

【例1】把/etc/fstab文件内容重定向到/tmp目录下文件名为fstab.out

写法:

13:54:35 root@centos ~]#cat /etc/fstab > /tmp/fstab.out
[13:55:02 root@centos ~]#cat /tmp/fstab.out #
# /etc/fstab
# Created by anaconda on Fri Sep 20 14:23:49 2019
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=b7becd8b-fb18-48cf-810b-953944dcf82e / xfs defaults 0 0
UUID=a74c9411-1dd4-44ff-929d-ba505baaec2c /boot xfs defaults 0 0
UUID=cc79eddd-a461-46e9-96ab-3489b7de0db3 /data xfs defaults 0 0
UUID=23047094-ac08-4c27-bfd9-f6cb8c34b185 swap swap defaults 0 0

【例2】把hello world追加到/tmp/fstab.out文件尾部

写法:

[13:57:46 root@centos ~]#echo hello world >> /tmp/fstab.out
[13:58:02 root@centos ~]#cat /tmp/fstab.out #
# /etc/fstab
# Created by anaconda on Fri Sep 20 14:23:49 2019
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=b7becd8b-fb18-48cf-810b-953944dcf82e / xfs defaults 0 0
UUID=a74c9411-1dd4-44ff-929d-ba505baaec2c /boot xfs defaults 0 0
UUID=cc79eddd-a461-46e9-96ab-3489b7de0db3 /data xfs defaults 0 0
UUID=23047094-ac08-4c27-bfd9-f6cb8c34b185 swap swap defaults 0 0
/hello world
hello world

【例3】禁止覆盖重定向和强制重定向

写法:

[14:00:32 root@centos ~]#set -C
[14:00:39 root@centos ~]#echo hello yang > /tmp/fstab.out
-bash: /tmp/fstab.out: cannot overwrite existing file
[14:02:12 root@centos ~]#echo hello yang >| /tmp/fstab.out
[14:02:26 root@centos ~]#cat /tmp/fstab.out
hello yang

【例4】解除禁止覆盖重定向设置

写法:

[14:03:15 root@centos ~]#set +C
[14:05:01 root@centos ~]#echo hello JIAK > /tmp/fstab.out
[14:05:43 root@centos ~]#cat /tmp/fstab.out
hello JIAK

【例5】把标准错误覆盖重定向到which.out文件

先看下只重定向标准输出的情况:

写法:

[14:11:57 root@centos ~]#hosname > /which.out
bash: hosname: command not found...
[14:13:50 root@centos ~]#hosname 2> /which.out
[14:13:36 root@centos ~]#cat /which.out
bash: hosname: command not found...

【例6】把标准错误和标准输出分别重覆盖定向到不同的文件里,即标准错误重定向到falt.txt文件,标准输出重 定向到correct.txt

写法:

[14:34:16 root@centos ~]#hosname 2> /falt.txt
[14:35:27 root@centos ~]#hostname > /correct.txt
[14:35:43 root@centos ~]#cat /falt.txt
bash: hosname: command not found...
[14:35:53 root@centos ~]#cat /correct.txt
centos.yang.com

【例7】用输入重定向的方式,把所有小写字母转换为大写

写法:

[15:02:54 root@centos ~]#cat /etc/issue
\S
Kernel \r on an \m [15:07:48 root@centos ~]#cat /etc/issue | tr "a-z" "A-Z"
\S
KERNEL \R ON AN \M

【例8】把out.txt文件里的内容,写到file.txt文件里

写法:

15:11:47 root@centos ~]#cat >/file.txt</out.txt
[15:11:57 root@centos ~]#cat /file.txt
/usr/bin/cat

【例9】屏幕随便输入几行内容,遇到END字样结尾后,屏幕内容自动保存在f1.txt里

写法:

[15:14:31 root@centos ~]#cat >f1.txt <<END
> hello jiak
> i am yang
> END
[15:17:17 root@centos ~]#cat f1.txt
hello jiak
i am yang

【例10】把echo输出的内容,传递给tr命令,实现小写字母转换为大写字母

写法:

[16:11:38 root@centos ~]#echo {a..z}
a b c d e f g h i j k l m n o p q r s t u v w x y z
[16:11:44 root@centos ~]#echo {a..z} | tr "a-z" "A-Z"
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

【例11】一页一页的查看输入

写法:

[16:12:05 root@centos ~]#ls -l /etc |less
total 1420
drwxr-xr-x. 3 root root 101 Sep 20 14:25 abrt
-rw-r--r--. 1 root root 16 Sep 20 14:30 adjtime
-rw-r--r--. 1 root root 1518 Jun 7 2013 aliases
-rw-r--r--. 1 root root 12288 Sep 20 14:32 aliases.db
drwxr-xr-x. 3 root root 65 Sep 20 14:26 alsa
drwxr-xr-x. 2 root root 4096 Sep 20 14:27 alternatives
-rw-------. 1 root root 541 Aug 9 07:07 anacrontab
-rw-r--r--. 1 root root 55 Aug 8 19:47 asound.conf
-rw-r--r--. 1 root root 1 Oct 31 2018 at.deny
drwxr-x---. 3 root root 43 Sep 20 14:25 audisp
drwxr-x---. 3 root root 83 Sep 20 14:32 audit

标准io和管道练习的更多相关文章

  1. Linux标准IO和管道

    Linux标准IO和管道 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.标准输入和输出 程序:指令+数据 读入数据:Input 输出数据:Output 打开的文件都有一个fd: ...

  2. [APUE]标准IO库(上)

    一.流和FILE对象 系统IO都是针对文件描述符,当打开一个文件时,即返回一个文件描述符,然后用该文件描述符来进行下面的操作,而对于标准IO库,它们的操作则是围绕流(stream)进行的. 当打开一个 ...

  3. (一) 一起学 Unix 环境高级编程 (APUE) 之 标准IO

    . . . . . 目录 (一) 一起学 Unix 环境高级编程 (APUE) 之 标准IO (二) 一起学 Unix 环境高级编程 (APUE) 之 文件 IO (三) 一起学 Unix 环境高级编 ...

  4. UNIX高级环境编程(6)标准IO函数库 - 流的概念和操作

    标准IO函数库隐藏了buffer大小和分配的细节,使得我们可以不用关心预分配的内存大小是否正确的问题. 虽然这使得这个函数库很容易用,但是如果我们对函数的原理不熟悉的话,也容易遇到很多问题.   1 ...

  5. 【Java TCP/IP Socket】Java NIO Socket VS 标准IO Socket

    简介 Java  NIO从JDK1.4引入,它提供了与标准IO完全不同的工作方式. NIO包(java.nio.*)引入了四个关键的抽象数据类型,它们共同解决传统的I/O类中的一些问题.    1. ...

  6. 系统调用IO和标准IO

    目录 1. 系统调用IO(无缓冲IO) 系统调用 常用系统调用IO函数 open close read write lseek ioctl 2. 标准IO(带缓冲IO) 概述 缓冲与冲洗 常用标准IO ...

  7. Java 标准 IO 流编程一览笔录( 上 )

    Java标准I/O知识体系图: 1.I/O是什么? I/O 是Input/Output(输入.输出)的简称,输入流可以理解为向内存输入,输出流是从内存输出. 2.流 流是一个连续的数据流,可以从流中读 ...

  8. 文件的概念、标准IO其一

    1.文件的概念 文件是一种存储在磁盘(掉电不丢失存储设备)上,掉电不丢失的一种存储数据的方式,文件在系统中有以下层次的结构来实现. 系统调用.文件IO.标准IO的关系如下: 2.linux系统的文件分 ...

  9. 深究标准IO的缓存

    前言 在最近看了APUE的标准IO部分之后感觉对标准IO的缓存太模糊,没有搞明白,APUE中关于缓存的部分一笔带过,没有深究缓存的实现原理,这样一本被吹上天的书为什么不讲透彻呢?今天早上爬起来赶紧找了 ...

随机推荐

  1. python 34 多进程(二)

    目录 1. 互斥锁 2. 进程之间的通信 2.1 基于文件的通信 2.2 基于队列的通信 1. 互斥锁 ​ 当多个进程抢占同一数据时,将数据加锁,使进程按串行的方式去获取数据,先到先得,保证了公平.数 ...

  2. CentOS -- Zookeeper installation and configure

    1 JDK 1.8 must installed first 2 Get Zookeeper package wget https://archive.apache.org/dist/zookeepe ...

  3. Springboot源码分析之事务拦截和管理

    摘要: 在springboot的自动装配事务里面,InfrastructureAdvisorAutoProxyCreator ,TransactionInterceptor,PlatformTrans ...

  4. Spring框架入门之基于Java注解配置bean

    Spring框架入门之基于Java注解配置bean 一.Spring bean配置常用的注解 常用的有四个注解 Controller: 用于控制器的注解 Service : 用于service的注解 ...

  5. Nginx总结(四)基于域名的虚拟主机配置

    前面讲了如何安装配置Nginx,大家可以去这里看看nginx系列文章:https://www.cnblogs.com/zhangweizhong/category/1529997.html 今天要说的 ...

  6. hdu 5898 odd-even number(数位dp)

    Problem Description For a number,if the length of continuous odd digits is even and the length of co ...

  7. 【LeetCode】55-跳跃游戏

    题目描述 给定一个非负整数数组,你最初位于数组的第一个位置. 数组中的每个元素代表你在该位置可以跳跃的最大长度. 判断你是否能够到达最后一个位置. 示例 1: 输入: [2,3,1,1,4] 输出: ...

  8. FreeSql (七)插入数据时忽略列

    var connstr = "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;" + "Initia ...

  9. 用Python分析2000款避孕套,得出这些有趣的结论

    到现在为止,我们的淘宝教程已经写到了第四篇,前三篇分别是: 第一篇:Python模拟登录淘宝,详细讲解如何使用requests库登录淘宝pc端. 第二篇:淘宝自动登录2.0,新增Cookies序列化, ...

  10. 代理损失函数(surrogate loss function)

    Surrogate loss function,中文可以译为代理损失函数.当原本的loss function不便计算的时候,我们就会考虑使用surrogate loss function. 在二元分类 ...