首页 技术 正文
技术 2022年11月15日
0 收藏 431 点赞 5,022 浏览 1241 个字

I/O:

系统设定

  默认输入设备:标准输入,STDIN,0

  默认输出设备:标准输出,STDOUT,1

  标准错误输出:STDERR,2

  属于不同的数据流

标准输入:键盘

标准输出和错误输出:显示器

I/O重定向:

输出重定向:

> :覆盖输出

>> :追加输出

2>:错误输出

2>>:追加错误输出

正常输出

ls /usr > /tmp/var.out

set

  -C:禁止对已经存在文件使用覆盖重定向;

  +C:允许覆盖输出

强制覆盖输出

ls /usr >| /tmp/var.out

错误输出

ls /varr 2> /tmp/var2.out

定向标准输出与标准错误输出

ls /varr > /tmp/var3.out 2> /tmp/err.out

&>:重定向标准输出或错误输出至同一个文件

ls /varr &> /tmp/var4.out

输入重定向

<:正常输入

<<:Here Document

cat << EOF

正常输入

tr ‘a-z’ ‘A-Z’ < /etc/fstab

输出内容到文件中

cat >> /tmp/myfile.txt << EOF

管道:前一个命令的输出,作为后一个命令的输入

命令1 | 命令2 | 命令3 …

echo “First love is only a little foolishness and a lot of curiosity.” | tr ‘a-z’ ‘A-Z’

echo “redhat” | passwd –stdin hive

cat /etc/passwd | sort

cut -d : -f 1 /etc/passwd | sort -n | tr ‘a-z’ ‘A-Z’

ls /var | tr ‘a-z’ ‘A-Z’

wc -l /etc/passwd | cut -d’ ‘ -f 1

tee :从标准输入读取,写入到标准输出,并保存到文件中

echo “First love is only a little foolishness and a lot of curiosity.” | tee  /tmp/test.out

练习:

1.统计/usr/bin目录下的文件个数;

#ls /usr/bin | wc -l

2.取出当前系统上所有用户的shell,每种shell只显示一次,且按顺序显示;

# /etc/passwd 保存shell

#cut -d : -f 7 /etc/passwd |sort -u

3.如何显示/var/log目录下每个文件的内容类型?

#file /var/log/*

4.取出/etc/inittab文件的第6行;

# head -6 /etc/inittab | tail -1

5.取出/etc/passwd文件中倒数第9个用户的用户名和shell,显示到屏幕上并将其保存至/tmp/users文件中;

# tail -9 /etc/passwd | head -1 | cut -d : -f 1,7 | tee /tmp/users

6.显示/etc目录下所有以pa开头的文件,并统计其个数;

#  ls -d /etc/pa* | wc -l

7.不使用文本编辑器,将alias cls=clear一行内容添加至当前用户的.bashrc文件中。

# echo “alias cls=clear” >> ~/.bashrc

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,496
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,909
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,743
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,496
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,134
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,298