十.SHELL脚本中的常用命令

一、设置主机名称

1.文件的方式

[root@localhost ~]# vim /etc/hostname
qass

2.通过命令更改主机名

[root@localhost ~]# hostnamectl hostanme qass

二、网络管理命令nmcli

1.查看网卡

[root@qass ~l# ip as ens160
[root@qass ~]# ifconfig ens160
[root@qass ~]# nmcli device show ens160
[root@qass ~]# nmcli device status
[root@qass ~l# nmcli connection show ens160

2.设置网卡

a.当网卡未被设置过时
[root@qass ~l# nmcli connection add con-name ens160 type ethernet ifname ens160 ipv4.method auto 
b.当网卡被设定,当前需要修改
[root@qass ~l# nmcli connection modify ens160 ipv4.addresses 192.168.30.200/24
[root@qass ~l# nmcli connection reload 
[root@qass ~l# nmcli connection up ens160

三、打印字符

1.打印数字

[root@qass Documents]# seq 1 3    #连续打印三个数字
1
2
3
[root@qass Documents]# seq 1 2 10    #设定打印步长
1
3
5
7
9
[root@qass Documents]# seq -f "%03g" 1 2 10    #指定打印格式
001
003
005
007
009
[root@qass Documents]# seq -f "%03g" 1 2 10 > test    #反向打印文件内容
[root@qass Documents]# cat test
001
003
005
007
009
[root@qass Documents]# tac test
009
007
005
003
001

30143515315453343131648.0[root@qass Documents]# printf "%.1f"    #打印浮点数"3.143515315453.1[root@qass Documents]# printf "%.2f" "3.143515315453343131351"3.14

打印字符

[root@qass ~]# echo hello world    #打印字符
hello world
[root@qass ~]# echo -n hello world    #不换行打印
hello world
[root@qass ~]# echo -e "hello"    
hello
[root@qass ~]# echo -e "hello\tworld"    #解析转义字符
hello	world
[root@qass ~]# echo -e "hello\nworld"
hello
world
[root@qass ~]# echo -e "\033[32mhello world"
hello world
[root@qass ~]# echo -e "\033[32mhello world\033[0m"
hello world
[root@qass ~]# echo -e "\033[35mhello world\033[0m"
hello world

 .lscpu

lscpu 命令是用于显示和收集有关 CPU (中央处理器)架构和相关信息的命令。它提供了关于 CPU 的详细信息,包括处理器类型、架构、核心数、线程数、缓存大小等

五、wget

作用是从指定的URL下载文件。wget命令非常稳定,一般即便网络波动也不会导致下载失败,而是不断尝试重连,直到整个文件下载完毕。wget命令支持如HTTP、HTTPS、FTP等常见协议,可以在命令行中直接下载网络文件。

1.查看wget版本

[rootqass~l# wget -V


2.下载文件

[root@qass ~l# wget https://didir1.qq.com/qqfile/qq/QQNT/Linux/QQ_3.2.7_240403_x86_64_01.rpm
[root@qass~l# wget https://didir1.qq.com/qqfile/qq/QQNT/Linux/QQ_3.2.7_240403_x86_64_01.rpm -O /mnt/qq.rpm


3.限速下载

[root@qass ~l# wget https://didir1.qq.com/qqfile/qq/QQNT/Linux/QQ_3.2.7_240403_x86_64_01.rpm -O /mnt/qq.rpm --limit-rate 1k


4.断点续传

[root@qass ~l# wget https://didir1.qq.com/qqfile/qq/QQNT/Linux/QQ_3.2.7_240403_x86_64_01.rpm -O /mnt/qq.rpm --limit-rate 1k -c


5.后台下载

[root@qass ~l# wget https://didir1.qq.com/qqfile/qq/QQNT/Linux/QQ_3.2.7_240403_x86_64_01.rpm -O /mnt/qq.rpm --limit-rate 1k -b 
[root@qass ~l# tail -f wget-log


6.下载整个站点

[root@qass ~l# wget -r -o /mnt/baidu http://www.baidu.com


7.检测站点是否存活

[root@qass ~l# wget -q -T 3 -t 2 --spider http://www.baidu.com

六、watch


linux命令watch是周期性的用来执行某命令,并把某命令执行结果输出到屏幕上。使用watch命令,可以 周期性的监测并输出某命令的执行结果到屏幕上,省得手动一遍一遍运行某命令,提高工作效率。

1.设置被监控的命令执行间隔

[root@qass ~l# watch -n 2 ls /mnt


2.点亮显示变化区域

[root@qass ~l# watch -d ls /mnt


3.屏蔽顶部时间信息

[root@qass ~l# watch -t ls /mnt

七、xargs

xargs 命令作用是将标准输入数据转换成命令行参数,能够处理管道或者标准输入并将其转换成特定命令 的命令参数

[root@qass ~l# echo /mnt/sen{1..3} | xargs touch

2.多行输入单行输出

[root@qass ~l# vim /mnt/sen
q q q q q
a a a a a
s s s s s
z z z z z
j j j j j
y y y y y
[root@qass ~l# xargs < /mnt/sen
q q q q q a a a a a s s s s s z z z z z j j j j j y y y y y

3.指定每行输出个数

[root@qass ~l# xargs -n 3 < /mnt/sen
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@qass ~l# echo "qaz:qaz:qaz" | xrags
qaz:qaz:qaz
[root@qass ~l# echo "qaz:qaz:qaz" | xarhs -d:
qaz qaz qaz

5.用字符代替接收值

[root@qass ~l# ls /mnt/* | xargs -Iword rm -rf word

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值