Linux极客命令(进阶篇)

来源:互联网 发布:焦作公务员网络培训 编辑:程序博客网 时间:2024/06/08 07:04

1、查看当前进程:ps

2、实时监测进程:top

3、结束进程:kill

4、查看磁盘空间:df

5、远程复制档案或目录:scp

6、查看CPU信息:sudo cat /proc/cpuinfo

7、打印文件的文本行数、单词数、字节数等:WC

打印指定文件的文本行数。(l=小写L)

以下参数可组合使用。

参数:-c, --bytes[喝小酒的网摘]http://blog.hehehehehe.cn/a/17301.htm
打印字节数(print the byte counts)

参数:-m, --chars
打印字符数(print the character counts)

参数:-l, --lines
打印行数(print the newline counts)

参数:-L, --max-line-length
打印最长行的长度(print the length of the longest line)

参数:-w, --words
打印单词数(print the word counts)


参数: --help 在线帮助

参数: --version


8.输出:tee

格式:tee

只输出到标准输出,因为没有指定文件嘛。

 

格式:tee file

输出到标准输出的同时,保存到文件file中。如果文件不存在,则创建;如果已经存在,则覆盖之。(If a file being written to does not already exist, it is created. If a file being written to already exists, the data it previously
contained is overwritten unless the `-a' option is used.)

 

格式:tee -a file

输出到标准输出的同时,追加到文件file中。如果文件不存在,则创建;如果已经存在,就在末尾追加内容,而不是覆盖。

 

格式:tee -

输出到标准输出两次。(A FILE of `-' causes `tee' to send another copy of input to standard output, but this is typically not that useful as the copies are interleaved.)

 

格式:tee file1 file2 -

输出到标准输出两次,同时保存到file1和file2中。


9. tail 命令 和  head 和 sed


每天一个linux命令(15):tail 命令

tail 命令从指定点开始将文件写到标准输出.使用tail命令的-f选项可以方便的查阅正在改变的日志文件,tail -f filename会把filename里最尾部的内容显示在屏幕上,并且不但刷新,使你看到最新的文件内容. 

1.命令格式;

tail[必要参数][选择参数][文件]   

2.命令功能:

用于显示指定文件末尾内容,不指定文件时,作为输入信息进行处理。常用查看日志文件

3.命令参数:

-f 循环读取

-q 不显示处理信息

-v 显示详细的处理信息

-c<数目> 显示的字节数

-n<行数> 显示行数

--pid=PID 与-f合用,表示在进程ID,PID死掉之后结束. 

-q, --quiet, --silent 从不输出给出文件名的首部 

-s, --sleep-interval=S 与-f合用,表示在每次反复的间隔休眠S秒 

4.使用实例:

实例1:显示文件末尾内容

命令:

tail -n 5 log2014.log

输出:

[root@localhost test]# tail -n 5 log2014.log 

2014-09

2014-10

2014-11

2014-12

==============================[root@localhost test]#

说明:

显示文件最后5行内容

实例2:循环查看文件内容

命令:

tail -f test.log

输出:

[root@localhost ~]# ping 192.168.120.204 > test.log &

[1] 11891[root@localhost ~]# tail -f test.log 

PING 192.168.120.204 (192.168.120.204) 56(84) bytes of data.

64 bytes from 192.168.120.204: icmp_seq=1 ttl=64 time=0.038 ms

64 bytes from 192.168.120.204: icmp_seq=2 ttl=64 time=0.036 ms

64 bytes from 192.168.120.204: icmp_seq=3 ttl=64 time=0.033 ms

64 bytes from 192.168.120.204: icmp_seq=4 ttl=64 time=0.027 ms

64 bytes from 192.168.120.204: icmp_seq=5 ttl=64 time=0.032 ms

64 bytes from 192.168.120.204: icmp_seq=6 ttl=64 time=0.026 ms

64 bytes from 192.168.120.204: icmp_seq=7 ttl=64 time=0.030 ms

64 bytes from 192.168.120.204: icmp_seq=8 ttl=64 time=0.029 ms

64 bytes from 192.168.120.204: icmp_seq=9 ttl=64 time=0.044 ms

64 bytes from 192.168.120.204: icmp_seq=10 ttl=64 time=0.033 ms

64 bytes from 192.168.120.204: icmp_seq=11 ttl=64 time=0.027 ms

[root@localhost ~]#

说明:

ping 192.168.120.204 > test.log & //在后台ping远程主机。并输出文件到test.log;这种做法也使用于一个以上的档案监视。用Ctrl+c来终止。 

实例3:从第5行开始显示文件

命令:

tail -n +5 log2014.log

输出:

[root@localhost test]# cat log2014.log 

2014-01

2014-02

2014-03

2014-04

2014-05

2014-06

2014-07

2014-08

2014-09

2014-10

2014-11

2014-12

==============================

[root@localhost test]# tail -n +5 log2014.log

2014-05

2014-06

2014-07

2014-08

2014-09

2014-10

2014-11

2014-12

==============================



linux 如何显示一个文件的某几行(中间几行)

【一】从第3000行开始,显示1000行。即显示3000~3999行

cat filename | tail -n +3000 | head -n 1000

 

【二】显示1000行到3000行

cat filename| head -n 3000 | tail -n +1000

 

*注意两种方法的顺序

 

分解:

    tail -n 1000:显示最后1000行

    tail -n +1000:从1000行开始显示,显示1000行以后的

    head -n 1000:显示前面1000行

 

【三】用sed命令

 

 sed -n '5,10p' filename 这样你就可以只查看文件的第5行到第10行。



0 0
原创粉丝点击