【linux 文件管理】7-文件重定向

https://edu.aliyun.com/lesson_1733_14278?spm=5176.8764728.0.0.38291acbi9l0O6#_14278

  • 标准输入和输出
    input output
    打开的文件都有一个文件描述符file descriptor(fd),系统分配的数字
    标准输入SRDNI - 0 默认键盘输入
    标准输出STDOUT - 1 默认输出到终端窗口
    标准错误STDERR - 2 默认输出到终端窗口
    I/O重定向:改变默认位置

vim anaconda-ks.cfg
cd /proc/
ls
ps aux|grep vim
cd /proc/53170
ls
cd fd
ll

  • 重定向redirect:换个终端窗口显示
    tty
    ls > /dev/pts/1

覆盖

追加
set -C 禁止覆盖 set +C 允许覆盖

STDOUT重定向
2> STDERR重定向
&> 所有输出
| file 强制覆盖

ll /dev/null 垃圾箱
ls /boot /dir > /root/all2.log 2>&1 把错的也放到里面
ls /boot /dir 2> /root/all2.log 1>&2

(cal 08 2008;cal 08 2018) > /data/cal.txt

bc < f1.txt > bc.log
cat 把输入的输出出来

* tr命令:转换和删除字符
tr 'a-z' 'A-Z'

tr 'a-z' 'A-Z' < /etc/issue > f1.txt
cat f1.txt

tr -d 'abc'
abfecadc

tr -dc '0-9'

tr -s 'ab' 连续字符压缩
aabb

who
who > who.log
tr -s " " < who.log
tr -s " " + < who.log

tr ' ' ' ' < f2.txt

原文地址:https://www.cnblogs.com/sec875/p/13408644.html