3

测试开发之系统篇-常用系统命令

 2 years ago
source link: https://my.oschina.net/candou/blog/5133022
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

测试开发之系统篇-常用系统命令 - 炒蚕豆吃蹦豆 - OSCHINA - 中文开源技术交流社区

以下介绍测试工作中常用的一些命令。未专门标注的,为Linux和Mac系统下的。

查看占用端口的进程

Linux

aaron@ubuntu:~$ lsof -i :8085 | grep LISTEN
___server 69080 aaron   11u  IPv6 0x5624b7cdebdb6b7b      0t0  TCP *:8085 (LISTEN)

Windows

C:>netstat -aon | findstr :80 | findstr LISTENING
  TCP    0.0.0.0:80             0.0.0.0:0              LISTENING       2588
  TCP    [::]:80                [::]:0                 LISTENING       2588

Linux

aaron@ubuntu:~$ kill -9 69080

Windows

PS C:\WINDOWS\system32> taskkill /F /PID 8152
SUCCESS: The process with PID 8152 has been terminated.

Windows下权限不足的,可右击开始按钮,用管理员模式启动PowerShell。

按名称查看进程

aaron@ubuntu:~$ ps -ef | grep nginx | grep -v grep
root     21471     1  0  2020 ?        00:00:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
www-data 21472 21471  0  2020 ?        00:07:55 nginx: worker process

使用grep -v grep过滤掉该查看进程本身。

命令行管道

aaron@ubuntu:~$ ps -ef | grep nginx | grep -v grep | awk '{print $2}' | xargs kill -9

此处使用管道,杀掉名为nginx的进程。

  • 使用|管道符,将命令的标准输出传递为下一个命令的标准输入;
  • 使用awk打印所捕获行的第2列,列按空格或Tab符号进行分割;
  • 使用xargs,将上个命令的标准输出转换成下一个命令的参数。

后台运行服务

aaron@ubuntu:~$ nohup appium -p %d --default-capabilities '{"udid":"sn"}' > appium.log 2>&1 &

后台为指定串号sn的手机运行appium服务。

查找zd.conf文件中,以“Version”开头的行,替换为“Version = 2.0”。
Linux

sed -i "s/Version.*/Version = 2.0/" zd.conf
gsed -i "s/Version.*/Version = 2.0/" zd.conf

复制目录到远程

scp -r bin/utl-server/0.8/linux/utl-server 139.224.8.129:~

实时查看文件内容

aaron@ubuntu:~$ tail -f jmeter.log
2021-04-25 15:11:51,723 INFO o.a.j.p.h.s.HTTPSamplerBase: Parser for text/xml is org.apache.jmeter.protocol.http.parser.LagartoBasedHtmlParser
2021-04-25 15:11:51,723 INFO o.a.j.p.h.s.HTTPSamplerBase: Parser for text/vnd.wap.wml is org.apache.jmeter.protocol.http.parser.RegexpHTMLParser
2021-04-25 15:11:51,723 INFO o.a.j.p.h.s.HTTPSamplerBase: Parser for text/css is org.apache.jmeter.protocol.http.parser.CssParser
2021-04-25 15:11:51,789 INFO o.a.j.s.SampleResult: Note: Sample TimeStamps are START times
2021-04-25 15:11:51,789 INFO o.a.j.s.SampleResult: sampleresult.default.encoding is set to ISO-8859-1
2021-04-25 15:11:51,789 INFO o.a.j.s.SampleResult: sampleresult.useNanoTime=true

查看正在运行的服务

aaron@ngtesting-lab:~$ systemctl | grep apparmor
  apparmor.service.     loaded active exited    LSB: AppArmor initialization

查看服务状态

aaron@ubuntu:~$ service apparmor status
● apparmor.service - LSB: AppArmor initialization
   Loaded: loaded (/etc/init.d/apparmor; bad; vendor preset: enabled)
   Active: active (exited) since Fri 2021-05-28 09:42:26 CST; 18s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 19969 ExecStop=/etc/init.d/apparmor stop (code=exited, status=0/SUCCESS)
  Process: 20185 ExecStart=/etc/init.d/apparmor start (code=exited, status=0/SUCCESS)
aaron@ubuntu:~$ sudo service apparmor restart

查看内存状况

aaron@ubuntu:~$ free -h
              total        used        free      shared  buff/cache   available
Mem:           7.8G        2.3G        931M         40M        4.6G        5.2G
Swap:            0B          0B          0B

查看磁盘状况

aaron@ubuntu:~/ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            3.9G     0  3.9G   0% /dev
tmpfs           799M  3.4M  795M   1% /run
/dev/vda1        40G   33G  4.8G  88% /
tmpfs           3.9G  8.0K  3.9G   1% /dev/shm
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           3.9G     0  3.9G   0% /sys/fs/cgroup
tmpfs           799M     0  799M   0% /run/user/1000

监控系统状况

aaron@ubuntu:~$ top
top - 09:29:37 up 378 days, 16:35,  1 user,  load average: 0.00, 0.00, 0.00
Tasks: 146 total,   1 running, 145 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.2 us,  0.1 sy,  0.0 ni, 99.8 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :  8174708 total,   953320 free,  2365784 used,  4855604 buff/cache
KiB Swap:        0 total,        0 free,        0 used.  5426472 avail Mem
  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
14459 root      10 -10  135204  17124  14024 S   0.7  0.2   2:52.83 AliYunDun
  956 root      20   0 2428132  92556  16208 S   0.3  1.1   2690:07 java
 3217 999       20   0   90232   7264   3296 S   0.3  0.1 308:04.26 redis-server

Windows系统下,右击任务栏选择任务管理器。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK