[命令] Linux 命令 df (显示存储信息)

案例一:显示所有存储信息

# df -a

或者:

# df --all

案例二:以方便人类阅读的方式显示存储信息

# df -h

或者:

# df --human-readable

案例三:以 POSIX 的格式显示存储信息

# df -P

或者:

# df --portability

案例四:显示存储的 inode 信息

# df -i

或者:

# df --inodes

案例五:只显示本地的存储信息

# df -l

或者:

# df --local

案例六:显示存储的格式

# df -T

或者:

# df --print-type

[命令] Linux 命令 sort(对数字或字母进行排序)

内容一:sort 命令的选项

1) -b 排序时忽略每行前面的空格
2) -c 检查是否已排序
3) -f 排序时忽略大小写字母
4) -n 按照数值到大小进行排序
5) -o 将排序结果导入到指定文件
6) -r 以相反的顺序进行排序
7) -t 指定排序的分隔符
8) -k 以指定的列进行排序

内容二:sort 命令的案例

2.1 案例一:检查是否已经排序

# cat test.txt
3
5
4
2
1

# sort -c test.txt 
sort: test.txt:3: disorder: 4

(补充:这里以检查 test.txt 文件里的排列为例)

2.2 案例二:sort 排序 1 列数字

# cat test.txt
3
5
4
2
20
1

# sort -n test.txt 
1
2
3
4
5
20

(补充:这里以排列 test.txt 文件里的列为例)

2.3 案例三:sort 排序 1 列字母

# cat test.txt 
c
e
d
b
a

# sort test.txt 
a
b
c
d
e

(补充:这里以排列 test.txt 文件里的列为例)

2.4 案例四:sort 以相反的顺序进行排序

# cat test.txt 
c
e
d
b
a

# sort -r test.txt 
e
d
c
b
a

(补充:这里以排列 test.txt 文件里的列为例)

2.5 案例五:sort 以 2 列中的第 1 列进行排序

# cat test.txt 
3 d
5 c
4 a
2 e
1 b

# sort test.txt 
1 b
2 e
3 d
4 a
5 c

(补充:这里以排列 test.txt 文件里的列为例)

2.6 案例六:sort 以 2 列中的第 2 列进行排序

# cat test.txt 
3 d
5 c
4 a
2 e
1 b

# sort -k2 test.txt 
4 a
1 b
5 c
3 d
2 e

(补充:这里以排列 test.txt 文件里的列为例)

2.7 案例七:sort 对 IP 地址进行排序

# cat test.txt 
10.0.200.10
172.16.50.10
192.168.100.1
192.168.100.10
172.16.50.1
10.0.200.1

# sort test.txt
10.0.200.1
10.0.200.10
172.16.50.1
172.16.50.10
192.168.100.1
192.168.100.10

(补充:这里以排列 test.txt 文件里的列为例)

2.8 案例八:sort 以 IP 地址的第三组数字进行排序

# cat test.txt 
10.0.200.10
172.16.50.10
192.168.100.1
192.168.100.10
172.16.50.1
10.0.200.1

# sort -t'.' -k3n test.txt
172.16.50.1
172.16.50.10
192.168.100.1
192.168.100.10
10.0.200.1
10.0.200.10

(补充:这里以排列 test.txt 文件里的列为例)

[内容] Linux 输出信息的重定向

内容一:以清空原文的方式进行输出信息的重定向

1.1 以清空原文的方式将所有的输出信息重定向到某一个文件

<command> &> <file>

或者:

<command> >& <file>

1.2 以清空原文的方式只将正确的输出信息重定向到某一个文件

<command> 1> <file>

或者:

<command> > <file>

1.3 以清空原文的方式只将错误的输出信息重定向到某一个文件

<command> 2> <file>

内容二:以在原文后面追加的方式进行输出信息的重定向

2.1 以在原文后面追加的方式将所有的输出信息重定向到某一个文件

<command> &>> <file>

或者:

<command> >>& <file>

2.2 以在原文后面追加的方式只将正确的输出信息重定向到某一个文件

<command> 1>> <file>

或者:

<command> >> <file>

2.3 以在原文后面追加的方式只将错误的输出信息重定向到某一个文件

<command> 2>> <file>

内容三:通过重定向转换输出信息的正误

3.1 将错误的输出信息重定向成正确的输出信息

<command> 2&>1

或者:

<command> 2>&1

3.2 将正确的输出信息重定向成错误的输出信息

<command> 1&>2

或者:

<command> 1>&2

内容四:将输出信息重定向到黑洞

<command> &> /dev/null

或者:

<command> &>> /dev/null

或者:

<command> >& /dev/null

或者:

<command> >>& /dev/null

或者:

<command> 1> /dev/null 2>&1

或者:

<command> 1>> /dev/null 2>&1

或者:

<command> 1> /dev/null 2>>&1

或者:

<command> 1>> /dev/null 2>>&1

或者:

<command> 2> /dev/null 1>&2

或者:

<command> 2>> /dev/null 1>&2

或者:

<command> 2> /dev/null 1>>&2

或者:

<command> 2>> /dev/null 1>>&2

(补充:通过此种方法输出信息就既不会显示出来也不会被重定向到一个文件里)