以下介绍测试工作中罕用的一些命令。未专门标注的,为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 8152SUCCESS: The process with PID 8152 has been terminated.

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

按名称查看过程

aaron@ubuntu:~$ ps -ef | grep nginx | grep -v greproot     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

Mac

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.log2021-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.LagartoBasedHtmlParser2021-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.RegexpHTMLParser2021-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.CssParser2021-04-25 15:11:51,789 INFO o.a.j.s.SampleResult: Note: Sample TimeStamps are START times2021-04-25 15:11:51,789 INFO o.a.j.s.SampleResult: sampleresult.default.encoding is set to ISO-8859-12021-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   availableMem:           7.8G        2.3G        931M         40M        4.6G        5.2GSwap:            0B          0B          0B

查看磁盘情况

aaron@ubuntu:~/ df -hFilesystem      Size  Used Avail Use% Mounted onudev            3.9G     0  3.9G   0% /devtmpfs           799M  3.4M  795M   1% /run/dev/vda1        40G   33G  4.8G  88% /tmpfs           3.9G  8.0K  3.9G   1% /dev/shmtmpfs           5.0M  4.0K  5.0M   1% /run/locktmpfs           3.9G     0  3.9G   0% /sys/fs/cgrouptmpfs           799M     0  799M   0% /run/user/1000

监控零碎情况

aaron@ubuntu:~$ toptop - 09:29:37 up 378 days, 16:35,  1 user,  load average: 0.00, 0.00, 0.00Tasks: 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 stKiB Mem :  8174708 total,   953320 free,  2365784 used,  4855604 buff/cacheKiB Swap:        0 total,        0 free,        0 used.  5426472 avail Mem  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND14459 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零碎下,右击任务栏抉择工作管理器