2024-03-14
Linux
00
请注意,本文编写于 115 天前,最后修改于 100 天前,其中某些信息可能已经过时。

目录

输入输出重定向
输出
输入
命令花名(别名)

输入输出重定向

输入输出重定向只能对文件进行操作,不能对目录操作。

输出

> 输出重定向,将命令执行结果不输出到屏幕上,输出到文件里,会清空原文件,所以输出的时候一定要注意,文件名称要看好了。

示例:

bash
head -20 services > 2.txt # 任意找个有内容的文件就行 cat 2.txt seq 100 > 1.txt echo 123 > 1.txt cat 1.txt > 1.txt # 清空文件内容

>> 输出追加重定向,不会清空原文件

示例:

bash
cat 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: 没有那个文件或目录

输出重定向我们用的很多,输入重定向用的很少,所以简单演示一下即可。

输入

< 输入重定向

示例:

bash
cat < 1.txt > 2.txt # 将 1.txt 的数据输入过来并写入 2.txt 中

<< 输入追加重定向

标准输入0,支持用户直接输入内容

示例:

bash
cat << 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 即可

查看花名:

bash
alias 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'

添加花名:

bash
alias rm='rm -i' # -i 是提示警告信息用的 alias | grep rm alias rm='rm -i' 或者 alias rm='echo 禁止使用删除操作'

取消花名:

bash
unalias ls alias | grep ls

alias 花名的优先级高于系统命令

花名一定要是可执行的,不能随便定义别名,比如 rrx='aaaaaaa',执行 rrx 会报错,没有 aaaaaaa 这个指令

alias 永久生效

bash
vi .bashrc # 空白行,增加一行 alias cip='ip addr|tail -4|head -1'
如果对你有用的话,可以打赏哦
打赏
ali pay
wechat pay

本文作者:@Rrx

本文链接:

版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!