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