首页 > 系统服务 > 详细

Linux命令学习笔记2

时间:2019-09-20 13:10:57      阅读:124      评论:0      收藏:0      [点我收藏+]

<1>ps -eaf:

1 ps -eaf |grep tomcat |grep -v grep >/dev/null 2>&1

 分为4段

1、ps -eaf 查看当前进程,-e 显示所有进程,a显示终端上的所有进程,包括其他用户的进程,f 全格式。

 

2、显示的结果通过管道“|”传给第二段 grep tomcat,查找tomcat进程。

 

3、同样查找的结果传给第三段 grep -v grep,-v 不显示匹配的行,因为用grep查询tomcat的时候也算一个进程,而ps的时候该进程信息中也包含了tomcat,例如:

root      2317  0.0  0.0   5980   744 pts/4    S+   15:00   0:00 grep tomcat

所以用grep -v grep把这条过滤掉。

 

4、第四段 >/dev/null 2&>1,将显示结果(默认是正确输出,即1)重定向到/dev/null中去,2代表错误输出,也和1一样。Linux中0代表输入stdin,1代表输出stdout,2代表错误输出stderror。

 

每运行一个命令,该命令都会有一个返回值给shell,你可以在终端中试试ls,然后echo $?查看返回值,肯定是0,如果ls 一个不存在的文件,再看,肯定不是0。以此判断上一条命令是否执行成功。

 <2>

if [ $? -eq 0 ]; then

判断上一条命令的返回值是否等于(-eq) 0,即是否运行成功。

<3> find命令

 

Basic ExamplesPermalink

 

CommandDescription
find . -name testfile.txt Find a file called testfile.txt in current and sub-directories.
find /home -name ‘*.jpg Find all .jpg files in the /home and sub-directories.
find . -type f -empty Find an empty file within the current directory.
find /home -user exampleuser -mtime 7 -iname ".db" Find all .db files (ignoring text case) modified in the last 7 days by a user named exampleuser.

 

ps aux|grep "newfile3"|grep -v grep|awk ‘{print $2}‘|xargs kill -9

 

<4> 杀死newfile3中pid为awk ‘{print $2}‘的进程。使用管道打印newfile3的进程号,然后将参数用xargs传递给kill -9命令。 

 

nohup command > myout.file 2>&1 &

<5> 输出和标准错误都被重定向到myout.file中。nohup 和命令末尾的&表示账户注销后命令仍在后台运行。

 

 

参考链接:

https://linode.com/docs/tools-reference/tools/find-files-in-linux-using-the-command-line/

 

Linux命令学习笔记2

原文:https://www.cnblogs.com/zichun-zeng/p/11556222.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!