zoukankan      html  css  js  c++  java
  • 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.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和本地机器进行文件互传的命令:

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

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

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

        https://www.cnblogs.com/zhangchenliang/p/7717602.html

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

    https://www.cnblogs.com/qwj-sysu/p/4989656.html     

  • 相关阅读:
    输出控制符的详解
    printf函数的讲解
    关于字节、Ascll码、字符的存储的讲解
    1.2
    1.1
    OS模块学习笔记
    time时间模块总结
    编译py为exe
    python计算excel平均值和标准差
    Python与Excel交互--Xlwings
  • 原文地址:https://www.cnblogs.com/zichun-zeng/p/11556222.html
Copyright © 2011-2022 走看看