linux

 

>: 输出重定向,覆盖输出。

>> :追加输出重定向。

<: 输入重定向

cat < /etc/fstab

<<:输出当前文本

cat << EOF  当以EOF结尾输出

cat >> /root/2.txt << EOF 可以脚本中生成文件

set –C:禁止对已经存在文件使用覆盖输出。

set +C:关闭上述功能。

 

2>:重定错误输出。只能重定错误输出,不能正常输出

[root@localhost ~]# ls /root 2> 1.txt
1.txt    anaconda-ks.cfg  install.log         nginx-tools
Desktop  apache_tools     install.log.syslog

2>>:追加方式重定错误输出。

 

&> :重定赂标准输出或错误输出到同一文件

===============================

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

命令1 | 命令2 | 命令3 | 。。。。。

ls | tr 'a-z' 'A-Z'  把字符全部输换成大写

[root@localhost ~]# ls | tr 'a-z' 'A-Z' 
2.TXT
DESKTOP
ANACONDA-KS.CFG
APACHE_TOOLS
INSTALL.LOG
INSTALL.LOG.SYSLOG
NGINX-TOOLS

cut -d: -f1 /etc/passwd | sort -n | tail –10 分割文件输出第一列,排序,取十行

[root@localhost ~]# cut -d: -f1 /etc/passwd | sort -n | tail -10
sabayon
shutdown
smmsp
squid
sshd
sync
uucp
vcsa
webalizer
xfs

echo “hello world “ | tee /tmp/hello  输出到屏幕又输出到文件

取出/etc/inittab文件的第6行

cat -n /etc/inittab  | head -6 | tail –1

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

tail -9 /etc/passwd | cut -d':'  -f 1,6 | tee /tmp/user