龙空技术网

新手们常用的linux命令(man\top\find)

读书分享和突破熵增 13

前言:

此刻各位老铁们对“linux top 线程 cpu”可能比较关心,姐妹们都需要分析一些“linux top 线程 cpu”的相关文章。那么小编在网上收集了一些关于“linux top 线程 cpu””的相关文章,希望看官们能喜欢,同学们一起来了解一下吧!

一、man命令

root@test-virtual-machine:~# man -h

用法: man [选项...] [章节] 手册页...

root@test-virtual-machine:~# man pthread_create

man pthread_create函数结果

root@test-virtual-machine:~# man ls

man ls结果

二、top命令

显示linux进程、线程等信息。运行top命令后:

按1,显示所有CPU核占用率情况按H(大写),显示所有线程按u,输入用户名称,显示输入用户的进程、线程等信息。如输入root,显示root用户的信息按h(小写),显示帮助信息按x,对排序的字段进行高亮<>,改变排序的字段shift+>,排序的字段从左往右移动,直到最右边(继续按无效果,不会循环移动);shift+<,排序的字段从右往左移动,直到最左边(继续按无效果,不会循环移动)。常常结合x键使用,对指定的字段进行排序显示。按q,退出

top命令帮助信息(按h后显示的结果)

三、find命令

search for files in a directory hierarchy。

root@test-virtual-machine:~# find --help用法: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec|time] [path...] [expression]

find 命令可以结合linux shell命令使用,产生非常强大的效果,尤其是-exec,可以对通过find命令查找出来的文件执行指定的shell命令操作。表达式说明如下:

EXPRESSION       The part of the command line after the list of starting points is the expression.  This is a kind of query specification describing how we  match  files       and what we do with the files that were matched.  An expression is composed of a sequence of things:       Tests  Tests return a true or false value, usually on the basis of some property of a file we are considering.  The -empty test for example is true only              when the current file is empty.       Actions              Actions have side effects (such as printing something on the standard output) and return either true or false, usually based on  whether  or  not              they are successful.  The -print action for example prints the name of the current file on the standard output.       Global options              Global  options  affect  the  operation  of tests and actions specified on any part of the command line.  Global options always return true.  The              -depth option for example makes find traverse the file system in a depth-first order.       Positional options              Positional optiona affect only tests or actions which follow them.  Positional options always return true.  The -regextype option for example  is              positional, specifying the regular expression dialect for regulat expressions occurring later on the command line.       Operators              Operators  join  together  the other items within the expression.  They include for example -o (meaning logical OR) and -a (meaning logical AND).              Where an operator is missing, -a is assumed.   TESTS       Some tests, for example -newerXY and -samefile, allow comparison between the file currently being examined and some reference file specified on the com‐       mand line.  When these tests are used, the interpretation of the reference file is determined by the options -H, -L and -P and any previous -follow, but       the reference file is only examined once, at the time the command line is parsed.  If the reference file cannot be examined (for  example,  the  stat(2)       system call fails for it), an error message is issued, and find exits with a nonzero status.      -type c              File is of type c:              b      block (buffered) special              c      character (unbuffered) special              d      directory              p      named pipe (FIFO)              f      regular file              l      symbolic link; this is never true if the -L option or the -follow option is in effect, unless the symbolic link is broken.  If you want to                     search for symbolic links when -L is in effect, use -xtype.              s      socket              D      door (Solaris)ACTIONS      -exec command ;              Execute command; true if 0 status is returned.  All following arguments to find are taken to be arguments to the command until an  argument  con‐              sisting of `;' is encountered.  The string `{}' is replaced by the current file name being processed everywhere it occurs in the arguments to the              command, not just in arguments where it is alone, as in some versions of find.  Both of these constructions might need to be escaped (with a `\')              or quoted to protect them from expansion by the shell.  See the EXAMPLES section for examples of the use of the -exec option.  The specified com‐              mand is run once for each matched file.  The command is executed in the starting directory.   There are unavoidable security problems surrounding              use of the -exec action; you should use the -execdir option instead.       -exec command {} +              This  variant of the -exec action runs the specified command on the selected files, but the command line is built by appending each selected file              name at the end; the total number of invocations of the command will be much less than the number of matched files.  The command line is built in              much  the same way that xargs builds its command lines.  Only one instance of `{}' is allowed within the command.  The command is executed in the              starting directory.  If find encounters an error, this can sometimes cause an immediate exit, so some pending commands may not  be  run  at  all.              This variant of -exec always returns true.
root@test-virtual-machine:~/xenial# find ./* -name "test" -exec ls -al {} \;

-exec在使用“;”时,需要在前面加转译字符“\”,因为“;”是bash的特殊字符,bash会先解释它。在前面加“\”后,可以让bash将其传递给find,由find而不是bash解释。“;”是给find做标记的,即以“;”作为待执行的command命令所有参数的结束标记。(注:find在解析命令时,需要区分指定的参数是传给自己还是传给command命令?)。

另外,{}表示find命令的查找结果。

标签: #linux top 线程 cpu