Linux命令学习笔记2

 

<1>ps -eaf:html

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

 分为4段node

一、ps -eaf 查看当前进程,-e 显示全部进程,a显示终端上的全部进程,包括其余用户的进程,f 全格式。linux

 

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

 

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

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

因此用grep -v grep把这条过滤掉。bash

 

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

 

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

 <2>htm

if [ $? -eq 0 ]; then

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

<3> find命令

 

Basic ExamplesPermalink

 

Command Description
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.
find . -type d -exec chmod 755 {}\ 将当前目录及其子目录下全部目录的权限改成755(find命令,配合-exec参数,能够对查询的文件进行进一步的操做)

 

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和本地机器进行文件互传的命令:

参考:http://www.javashuo.com/article/p-arzmzvtc-bk.html

如果文件夹互传,则把文件夹压缩(zip/unzip),而后看成文件互传。

 

 <7> cat命令与>,<,>>,<<:

    http://www.javashuo.com/article/p-wgngjadm-de.html

<8> bash中的<,>,<<,>>:

http://www.javashuo.com/article/p-fgeyxyxz-m.html     

相关文章
相关标签/搜索