一.设置主机名称
1.文件的方式
]# vim /etc/hostname
timinglee.easylee.org



注意
修改完毕文件后在当前的shell中是不生效的
如果需要看到效果,关闭当前shell后重新开启新的shell
2.通过命令更改主机名
]# hostnamectl hostname timinglee.easylee.org


注意
即改即生效,无需重新启动she
二.网络管理命令nmcli
1.查看网卡
[root@timinglee ~]# ip a s ens160
[root@timinglee ~]# ifconfig ens160
[root@timinglee ~]# nmcli device show ens160
[root@timinglee ~]# nmcli device status
[root@timinglee ~]# nmcli connection show ens160


2.设置网卡
a)当网卡未被设置过时
设置dncp网络工作模
nmcli connection add con-name ens160 \
type ethernet ifname eth160 \
ipv4.method auto

设置静态网络工作模式
]# nmcli connection add con-name ens160 \
type ethernet ifname eth160 ipv4.method manual \
ipv4.addresses 172.25.254.100/24 \
ipv4.gateway 172.25.254.2

b)当网卡被设定,当前需要修改
]# nmcli connection modify ens160 ipv4.addresses 172.25.254.200/24
]# nmcli connection reload
]# nmcli connection up ens160
注意
当网卡未被设定时,对网卡的设定即改即生效
当网卡被设定过,我们通过命令更改后必须要刷新网卡才能生效
三.简单处理字符
1.打印连续数字
连续打印3个数字
[root@timinglee ]# seq 1 3
1
2
3

指定打印格式
[root@timinglee ]# seq -f "%03g" 1 3
001
002
003

设定打印步长
[root@timinglee ]# seq 1 2 10
1
3
5
7
9

2.反向打印文件内容
[root@timinglee ]# seq 1 9 > test
[root@timinglee ]# tac test
9
8
7
6
5
4
3
2
1

3.打印字符
a)printf
打印字符
[root@timinglee ]# printf "hello world"
hello world[root@timinglee mnt]#
![]()
打印字符指定格式
[root@timinglee ]# printf “hello world\n"
hello world
[root@timinglee ]# printf "hello\tworld\n"
hello world

打印百分号
[root@timinglee ]# printf "3%%\n"
3%

打印整数,浮点数
[root@timinglee ]# printf "%.0f" "3.1415926"
3
[root@timinglee mnt]# printf "%.1f \n" "3.1415926"
3.1

b)echo
打印字符
[root@timinglee ~]# echo "hello world"
hello world

不换行打印
[root@timinglee ~]# echo -n "hello world"
hello world[root@timinglee ~]#
![]()
解析转义字符
[root@timinglee ~]# echo -e "hello\tworld

4.sort
用于对内容进行排序,默认排序行首第一个字符
#示例:
#生成演示文件
]# vim lee
3
4
3
2
1
5
7
9
6
8
12
8
6
30
8
]# vim lee1
4:3
2:4
3:3
1:2
9:1
8:5
8:7
8:9
8:6
8:8
8:12
8:8
8:6
8:30
8:8
-n ##纯数字排序
sort -n lee
-r ##倒叙
sort -rn lee
-u ##去掉重复
sort -un lee
-o ##输出到指定文件
sort -un lee -o test
-t ##指定分隔符
-k ##指定排序的列
sort -n -t ":" -k 2 lee1


5.uniq
对于命令输出的字符冗余部分进行处理
#生成演示文件
]# vim lee
3
4
3
2
1
5
7
9
6
8
12
8
6
30
8
-c #合并重复并统计重复个数
sort -n lee | uniq -c
-d #显示重复的行
sort -n lee | uniq -d
-u #显示唯一的行
sort -n lee | uniq -u

6.cut
用户对字符的截取
-d : ##指定:为分隔符
-f ##指定显示的列 5第五列| 3,5 3和5列|3-5 3到5列|5- 第五列以后|-5 到第五列
-c ##指定截取的字符(数字用法同-f)
四.xargs
xargs 命令作用是将标准输入数据转换成命令行参数,能够处理管道或者标准输入并将其转换成特定命令
的命令参数
1.xargs作用命令
[root@timinglee ~]# echo /mnt/lee{1..3} | touch
touch: missing file operand
Try 'touch --help' for more information.
[root@timinglee ~]# echo /mnt/lee{1..3} | xargs touch

2.多行输入单行输出
[root@timinglee ~]# vim /mnt/lee
a a a a a a
b b b b b b
c c c c c c
d d d d d d
e e e e e e
f f f f f f
[root@timinglee ~]# xargs < /mnt/lee
a a a a a a b b b b b b c c c c c c d d d d d d e e e e e e f f f f f f

3.指定每行输出个数
[root@timinglee ~]# xargs -n 3 < /mnt/lee
a a a
a a a
b b b
b b b
c c c
c c c
d d d
d d d
e e e
e e e
f f f
f f f

4.指定分隔符
[root@timinglee ~]# echo "lee:lee:lee" | xargs
lee:lee:lee
[root@timinglee ~]# echo "lee:lee:lee" | xargs -d:
lee lee lee

5.用字符代替接收值
[root@timinglee ~]# ls /mnt/* | xargs -Iword rm -fr word
注意
-I:用于指定替换字符串,将输入数据中的特定字符串替换为命令行参数。
-n:用于指定每次执行命令的参数个数。
-t:用于打印执行的命令。
-p:用于提示用户确认是否执行命令。
-r:当标准输入为空时,不执行命令。

20万+




被折叠的 条评论
为什么被折叠?



