[命令] Linux 命令 echo (显示内容)

内容一:echo 的命令选项

1) -n 输出不换行
2) -e 处理某些特殊字符
\a 蜂鸣声报警
\b 删除前面一个字符
\c 在末尾不换行
\e 输出 esc
\f 换行,同时光标停在原处
\n 换行
\r 不换行,同时光标停在原处
\t tab,水平方向
\v tab,垂直方向
\ 输出 \
\Onnn 输出八进制 ASCII 字符
\xHH 输出十六进制 ASCII 字符
3) -E 不再转义

内容二:echo 的其他显示选项

1) \033[0m 将所有显示属性关闭
2) \033[1m 高亮
3) \033[4m 下划线
4) \033[5m 闪烁
5) \033[7m 反显
6) \033[8m 消隐
7) \033[37m — \33[0m 设置字体颜色,这里以将字体颜色设置为白色为例
8) \033[40m — \33[0m 设置背景颜色,这里以将背景颜色设置为白色为例
9) \033[A 将光标向上移 n 行
10) \033[B 将光标向下移 n 行
11) \033[C 将光标向右移 n 行
12) \033[D 将光标向左移 n 行
13) \033[;H 将光标跳转到 x 和 y 位置
14) \033[2J 清屏
15) \033[K 将光标所在位置到行尾的所有位置全部清除
16) \033[s 将光标位置保存
17) \033[u 将光标位置恢复
18) \033[?25l 将光标隐藏
19) \033[?25h 将光标显示

内容三:echo 显示不同颜色字体的案例

# echo -e "\033[30m black characters \033[0m" 
# echo -e "\033[31m red characters \033[0m"
# echo -e "\033[32m green characters \033[0m" 
# echo -e "\033[33m yellow characters \033[0m"
# echo -e "\033[34m blue characters \033[0m"
# echo -e "\033[35m purple character \033[0m"
# echo -e "\033[36m sky blue character \033[0m"
# echo -e "\033[37m white character \033[0m"

内容四:echo 显示不同颜色背景的案例

# echo -e "\033[40;37m white characters on black background \033[0m"
# echo -e "\033[41;37m white characters on red background \033[0m"
# echo -e "\033[42;37m white characters on green background \033[0m"
# echo -e "\033[43;37m white characters on yellow background \033[0m"
# echo -e "\033[44;37m white characters on blue background \033[0m"
# echo -e "\033[45;37m white characters on purple background \033[0m"
# echo -e "\033[46;37m white characters on sky blue background \033[0m"
# echo -e "\033[47;30m black characters on white background \033[0m"

内容五:echo 的其他案例

5.1 案例一:不换行带 tab 输出

# for month in Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec;do echo -e "$month\t\c";done
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec

(补充:这里以不换行带 tab 输出 Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec 为例)

5.2 案例二:先清屏再不换行输出

# echo -e "\033[2J\033[10A\Eternal Center\c"

(补充:这里以先清屏再不换行输出 Eternal Center 为例)

[命令] Linux 命令 tee (将输出内容保存到文件里)

内容一:tee 命令的格式

# tee [option] [file]......

内容二:tee 命令的选项

1) -a 或者 –append 将输出内容添加到文件里内容的末尾
2) -i 或者 –ignore-interrupts 忽略中断信号
3) –help 显示帮助信息
4) –version 显示版本信息

内容三:tee 的使用案例

3.1 将输出内容添加到另一个文件里内容的末尾

# echo 'tee test' | tee -a test.txt
tee test
# tail -1 test.txt
tee test

(补充:这里以将输出内容 ‘tee test’ 添加到另一个文件 test.txt 里内容的末尾为例)

3.2 将文件内容添加到另一个文件里内容的末尾

# cat test1.txt | tee -a test2.txt
test1
# tail -1 test2.txt
test1

(补充:这里以将 test1.txt 文件里的内容添加到另一个文件 test2.txt 里内容的末尾为例)

3.3 将输出内容变成另一个文件里的所有内容

# echo 'tee test' | tee test.txt
tee test
# cat test.txt
tee test

(补充:这里以将输出内容 ‘tee test’ 变成另一个文件 test.txt 里的所有内容为例)

3.4 将文件内容变成另一个文件里的所有内容

# cat test1.txt | tee -a test2.txt
test1
# cat test2.txt
test1

(补充:这里以将 test1.txt 文件里的内容变成另一个文件 test2.txt 里的所有内容为例)

[命令] Linux 命令 rm (删除目录或文件)

案例一:删除某一个文件

# rm <file>

案例二:删除某一个目录以及目录里的所有文件

# rm -r <directory>

案例三:非交互式删除某一个目录以及目录里的所有文件

# rm -rf <directory>

案例四:非交互式删除当前目录下的所有隐藏文件

# rm -rf .#*

案例五:非交互式删除所有特定后缀名称的文件

# rm -rf *txt

(补充:这里以非交互式删除所有以 txt 作为后缀名称的文件为例)

[命令] Linux 命令 convert (转换图片文件)

内容一:convert 命令的使用格式

# convert <input options> <output file name> <output options> <output file name>

内容二:convert 命令的使用案例

2.1 案例一:直接转换某一个文件

# convert "a.png" "a.png.jpg"

(补充:这里以将 a.png 转换成 a.png.jpg 为例)

2.2 案例二:转换当前目录下的所有文件

# ls -1 *.png | xargs -n 1 bash -c 'convert "$0" "${0%.png}.jpg"'

(补充:这里以将当前目录下的所有 *.png 文件转换成 *.png.jpg 文件)