新手必会的Linux常用系统工作命令

  • 1.echo命令
  • 2.date命令
  • 3.reboot命令/poweroff命令
  • 4.wget命令
  • 5.top命令
  • 6.pidof命令

1.echo命令

echo命令用于在终端输出字符串或变量提取后的值,格式为“echo [字符串 | $变量]

例如:

在终端上显示某一个字符串信息:

┌──(root💀kali)-[~/Desktop]
└─# echo hello world
hello world

显示某一个变量的信息:

┌──(root💀kali)-[~/Desktop]
└─# echo $SHELL
/usr/bin/zsh

2.date命令

date命令用于显示及设置系统的时间或日期,格式为“date [选项] [+指定的格式]

date命令中的参数以及作用:

按照默认格式查看当前系统的时间:

┌──(root💀kali)-[~/Desktop]
└─# date
Mon 03 Oct 2022 11:40:27 PM EDT

按照“年-月-日 小时:分钟:秒”的格式查看当前系统时间:

┌──(root💀kali)-[~/Desktop]
└─# date "+%Y-%m-%d %H:%M:%S"
2022-10-03 23:42:14

将系统的当前时间设置为2017年9月1日8点30分:

[root@linuxprobe ~]# date -s "20170901 8:30:00"
Fri Sep 1 08:30:00 CST 2017

date命令中的参数%j可用来查看今天是当年中的第几天:

┌──(root💀kali)-[~/Desktop]
└─# date "+%j"               
276

3.reboot命令/poweroff命令

reboot命令用于重启系统

poweroff命令用于关闭系统

默认只有root管理员才可以重启或者关闭电脑🍆


4.wget命令

wget命令用于在终端中下载网络文件,格式为“wget [参数] 下载地址

演示:下载某网站的pdf文件到当前文件夹下:

┌──(root💀kali)-[~/Desktop]
└─# wget https://www.lw/zh/people/admin/upload/SiteAttachments/Alert%202998.pdf
--2022-10-03 23:48:15--  https://www.lw/zh/people/admin/upload/SiteAttachments/Alert%202998.pdf
Resolving www.lw (www.lw)... 13.107.219.49, 13.107.227.49, 2620:1ec:49::49, ...
Connecting to www.lw (www.lw)|13.107.219.49|:443... connected.
HTTP request sent, awaiting response... 200 OK
Cookie coming from www.lw attempted to set domain to rg-www-prod-cd.azurewebsites
Cookie coming from www.lw attempted to set domain to rg-www-prod-cd.azurewebsites
Length: 452672 (442K) [application/pdf]
Saving to: ‘Alert 2998.pdf’

Alert 2998.p 100% 442.06K   839KB/s    in 0.5s    

2022-10-03 23:48:18 (839 KB/s) - ‘Alert 2998.pdf’ saved [452672/452672]

递归下载百度网的所有网页信息,该行为会在当前文件夹下面创建一个文件夹:

┌──(root💀kali)-[~/Desktop]
└─# wget -r -p https://www.baidu/
--2022-10-03 23:49:43--  https://www.baidu/
Resolving www.baidu (www.baidu)... 110.242.68.3, 110.242.68.4
Connecting to www.baidu (www.baidu)|110.242.68.3|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2443 (2.4K) [text/html]
Saving to: ‘www.baidu/index.html’

www.baidu.co 100%   2.39K  --.-KB/s    in 0s      

2022-10-03 23:49:43 (38.5 MB/s) - ‘www.baidu/index.html’ saved [2443/2443]

Loading robots.txt; please ignore errors.
--2022-10-03 23:49:43--  https://www.baidu/robots.txt
Reusing existing connection to www.baidu:443.
HTTP request sent, awaiting response... 200 OK
Length: 2814 (2.7K) [text/plain]
Saving to: ‘www.baidu/robots.txt’

...


5.top命令

top命令用于动态地监视进程活动与系统负载等信息,其格式为top

top命令执行结果的前5行为系统整体的统计信息,其所代表的含义如下:

  • 第1行:系统时间、运行时间、登录终端数、系统负载(三个数值分别为1分钟、5分钟、15分钟内的平均值,数值越小意味着负载越低)
  • 第2行:进程总数、运行中的进程数、睡眠中的进程数、停止的进程数、僵死的进程数
  • 第3行:用户占用资源百分比、系统内核占用资源百分比、改变过优先级的进程资源百分比、空闲的资源百分比等
  • 第4行:物理内存总量、内存使用量、内存空闲量、作为内核缓存的内存量
  • 第5行:虚拟内存总量、虚拟内存使用量、虚拟内存空闲量、已被提前加载的内存量

6.pidof命令

pidof命令用于查询某个指定服务进程的PID值,格式为“pidof [参数] [服务名称]

如下查询sshd的PID号:

[root@centtos7 ~]# pidof sshd
1166

更多推荐

新手必会的Linux常用系统工作命令