输入输出重定向只能对文件进行操作,不能对目录操作。
>
输出重定向,将命令执行结果不输出到屏幕上,输出到文件里,会清空原文件,所以输出的时候一定要注意,文件名称要看好了。
示例:
bashhead -20 services > 2.txt # 任意找个有内容的文件就行
cat 2.txt
seq 100 > 1.txt
echo 123 > 1.txt
cat 1.txt
> 1.txt # 清空文件内容
>>
输出追加重定向,不会清空原文件
示例:
bashcat rrx.txt
hello rrx
what are you ok?
cat rrx # 错误信息默认是打印在屏幕上的,如果我们想记录错误信息,就可以用到标准错误输出
cat: rrx: 没有那个文件或目录
cat rrx.txt 1>1.txt 2>2.txt # 指令正确会将数据保存到 1.txt 中
cat 1.txt
hello rrx
what are you ok?
cat 2.txt
cat rrx 1>1.txt 2>2.txt
cat 1.txt
cat 2.txt # 记录了报错信息
cat: jade: 没有那个文件或目录
输出重定向我们用的很多,输入重定向用的很少,所以简单演示一下即可。
<
输入重定向
示例:
bashcat < 1.txt > 2.txt # 将 1.txt 的数据输入过来并写入 2.txt 中
<<
输入追加重定向
标准输入0,支持用户直接输入内容
示例:
bashcat << 0
> 1
> 2
> 222
> 0
1
2
222
cat << 0 > 2.txt
> a
> 2
> ddd
> 0
cat 2.txt
a
b
ddd
alias
比如:ls -l
直接可以写 ll
即可
查看花名:
bashalias
alias cp='cp -i'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='rm -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
添加花名:
bashalias rm='rm -i' # -i 是提示警告信息用的
alias | grep rm
alias rm='rm -i'
或者
alias rm='echo 禁止使用删除操作'
取消花名:
bashunalias ls
alias | grep ls
alias
花名的优先级高于系统命令
花名一定要是可执行的,不能随便定义别名,比如 rrx='aaaaaaa'
,执行 rrx
会报错,没有 aaaaaaa
这个指令
alias
永久生效
bashvi .bashrc
# 空白行,增加一行
alias cip='ip addr|tail -4|head -1'
本文作者:@Rrx
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!