[命令] Linux 命令 uniq (文件里字符重复的管理)

案例一:uniq 命令去重

# cat test.txt 
a1
b2
c3
a1
d2
e3
a1
c3

# sort test.txt  | uniq
a1
b2
c3
d2
e3

(补充:这里以给 test.txt 文件里的字符为例)

案例二:uniq 只显示重复的行

# cat test.txt 
a1
b2
c3
a1
d2
e3
a1
c3

# sort test.txt  | uniq -d
a1
c3

(补充:这里以只显示 test.txt 文件里重复的行为例)

案例三:uniq 只显示不重复的行

# cat test.txt 
a1
b2
c3
a1
d2
e3
a1
c3

# sort test.txt  | uniq -u
b2
d2
e3

(补充:这里以只显示 test.txt 文件里不重复的行为例)

案例四:显示每个字符出现的次数

# cat test.txt 
a1
b2
c3
a1
d2
e3
a1
c3

# sort test.txt  | uniq -c
      3 a1
      1 b2
      2 c3
      1 d2
      1 e3

(补充:这里以显示 test.txt 每个字符出现的次数为例)

[步骤] Linux 加密压缩 (tar 版)

步骤一:创建测试文件

# touch test.txt

(补充:这里以创建 test.txt 文件为例)

步骤二:加密压缩文件或目录

2.1 交互式加密压缩文件或目录

# tar -zcf - test.txt | openssl des3 -salt | dd of=test1.tar.gz
enter des-ede3-cbc encryption password:
Verifying - enter des-ede3-cbc encryption password:
*** WARNING : deprecated key derivation used.
Using -iter or -pbkdf2 would be better.
0+1 records in
0+1 records out
224 bytes copied, 7.04902 s, 0.0 kB/s


补充:
1) 这里以将 test.txt 文件加密压缩成 test1.tar.gz (压缩)包为例
2) 如果要以 bzip2 的格式进行压缩,则将命令中的 -zcf 换成 -jcvf 将 test1.tar.gz 换成 test1.tar.bz2
3) 如果要以 xz 的格式进行压缩,则将命令中的 -zcf 换成 -Jcvf 将 test1.tar.gz 换成 test1.tar.xz

2.2 非交互式加密压缩文件或目录

# tar -zcf - test.txt | openssl des3 -salt -f eternalcenter | dd of=test2.tar.gz
des3: Unrecognized flag f
des3: Use -help for summary.
0+0 records in
0+0 records out
0 bytes copied, 0.00376576 s, 0.0 kB/s


补充:
1) 这里以将 test.txt 文件加密压缩成 test1.tar.gz (压缩)包并且将密码设置为 eternalcenter 为例
2) 如果要以 bzip2 的格式进行压缩,则将命令中的 -zcf 换成 -jcvf 将 test1.tar.gz 换成 test2.tar.bz2
3) 如果要以 xz 的格式进行压缩,则将命令中的 -zcf 换成 -Jcvf 将 test1.tar.gz 换成 test2.tar.xz

步骤三:解压加密文件或目录

3.1 交互式解压加密文件或目录

3.1.1 删除原测试目录和里面的文件
# rm -rf test.txt

(补充:这里以删除 test.txt 文件为例)

3.1.2 交互式解压加密文件或目录
# dd if=test2.tar.gz | openssl des3 -d | tar zxf -
0+1 records in
0+1 records out
224 bytes copied, 0.000589721 s, 380 kB/s
enter des-ede3-cbc decryption password:
*** WARNING : deprecated key derivation used.
Using -iter or -pbkdf2 would be better.


补充:
1) 这里以解压 test2.tar.gz (压缩)包为例
2) 如果是 bzip2 格式的(压缩)包,则将命令中的 -zxf 换成 -jcvf 将 test1.tar.gz 换成 test1.tar.bz2
3) 如果是 xz 格式的(压缩)包,则将命令中的 -zxf 换成 -Jcvf 将 test1.tar.gz 换成 test1.tar.xz

3.2 非交互式解压加密文件或目录

3.2.1 删除原测试目录和里面的文件
# rm -rf test.txt

(补充:这里以删除 test.txt 文件为例)

3.2.2 非交互式解压加密文件或目录
# dd if=test1.tar.gz | openssl des3 -d -k eternalcenter | tar zxf -
0+1 records in
0+1 records out
224 bytes copied, 0.000574539 s, 390 kB/s
*** WARNING : deprecated key derivation used.
Using -iter or -pbkdf2 would be better.


补充:
1) 这里以解压 test1.tar.gz (压缩)包并且解压密码为 eternalcenter 为例
2) 如果是 bzip2 格式的(压缩)包,则将命令中的 -zxf 换成 -jcvf 将 test1.tar.gz 换成 test1.tar.bz2
3) 如果是 xz 格式的(压缩)包,则将命令中的 -zxf 换成 -Jcvf 将 test1.tar.gz 换成 test1.tar.xz

[步骤] Linux 加密压缩 (zip 版)

步骤一:创建测试目录和测试文件

# mkdir test
# touch test/test.txt

(补充:这里以创建 test 目录和里面的 test.txt 文件为例)

步骤二:加密压缩文件或目录

2.1 交互式加密压缩文件或目录

# zip -re test1.zip test
Enter password: 
Verify password: 
  adding: test/ (stored 0%)
  adding: test/test.txt (stored 0%)

(补充:这里以将 test 目录和里面的 test.txt 文件加密压缩成 test1.zip (压缩)包为例)

2.2 非交互式加密解压文件或目录

# zip -rP eternalcenter test2.zip test
  adding: test/ (stored 0%)
  adding: test/test.txt (stored 0%)

(补充:这里以将 test 目录和里面的 test.txt 文件加密压缩成 test2.zip (压缩)包并且将密码设置为 eternalcenter 为例)

步骤三:解压加密文件或目录

3.1 交互式解压加密文件或目录

3.1.1 删除原测试目录和里面的文件
# rm -rf test

(补充:这里以删除 test 目录和里面的文件为例)

3.1.2 交互式解压加密文件或目录
# unzip test2.zip
Archive:  test2.zip
   creating: test/
[test2.zip] test/test.txt password: 
 extracting: test/test.txt

(补充:这里以解压 test2.zip (压缩)包为例)

3.2 非交互式解压加密文件或目录

3.2.1 删除原测试目录和里面的文件
# rm -rf test

(补充:这里以删除 test 目录和里面的文件为例)

3.2.2 非交互式解压加密文件
# unzip -P eternalcenter test1.zip 
Archive:  test1.zip
   creating: test/
 extracting: test/test.txt  

(补充:这里以解压 test2.zip (压缩)包并且解压密码为 eternalcenter 为例)

[命令] Linux 命令 ping (检测网络联通性)

内容一:ping 命令选项

1) -c 设置 ping 的次数 (默认会一直 ping)
2) -d 开启 Socket 的 SO_DEBUG 功能
3) -f 进行极限测试
4) -i 设置间隔时间,建议值为 0.4
5) -I 指定去 ping 的硬件设备或者 IP 地址
6) -m 设置标记
7) -l 设置发送不等待回复的数据包
8) -n 只显示数值
9) -q 只显示结果
10) -r 忽略路由表(可以用于检查本地网络接口是否有问题)
11) -R 记录路由的过程
12) -s 指定包的大小
13) -S 指定源 IP 地址
14) -t 设置 ping 包的生存时间 (TLL)
15) -v 输出详细信息
16) -w 设置 deadline,建议值为 0.8

内容二:ping 命令案例

2.1 案例一:让本地的某一个 IP 地址 ping 目标 IP 地址

# ping -I <IP address of this server> <target IP address>

2.2 案例二:让本地的某一个网卡 ping 目标 IP 地址


# ping -I <IP address of local server> <target IP address>

2.3 案例三:快速检测网络联通行

# ping -c 3 -i 0.4 -w 0.8 <target IP address>