Linux命令学习笔记2

<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.txtFind a file called testfile.txt in current and sub-directories.
find /home -name '*.jpgFind all .jpg files in the /home and sub-directories.
find . -type f -emptyFind 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/

<6> linux和本地机器进行文件互传的命令:

参考:https://www.cnblogs.com/wx170119/p/10238686.html

若是文件夹互传,则把文件夹压缩(zip/unzip),然后当作文件互传。

 

转载于:https://www.cnblogs.com/zichun-zeng/p/11556222.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值