CentOS7 基本命令(三)

运行环境:vps

Linux版本:CnetOS7.4


1.cat命令

查看纯文本文件(内容较少的),格式:

cat[选项]文件

使用

cat -n index.html


2.more命令

查看纯文本文件(内容较多的),格式:

more[选项]文件

使用

more index.html

空格键向下翻页。回车键向下一行。


3.head命令

查看纯文本文档的前N行,格式:

head[选项][文件]

查看文件前10行内容

head -n 10 index.html

查看文件前8个字节

head -c 8 index.html


4.tail命令

查看文档的后N行或持续刷新内容,格式:

tail[选项][文件]

查看文件后10行内容

tail -n 10 index.html

查看tomcat实时日志,持续刷新

tail -f catalina.out

Ctrl+C 退出


5.tr命令

替换文本文件中的字符,格式:

tr [原始字符] [新字符]

将内容中的英文全部替换为大写

head -n 10 index.html | tr [a-z] [A-Z]

将上面内容还原成小写

head -n 10 index.html | tr [:upper] [:lower]

具体支持格式参见:

tr --help


6.wc命令

统计指定文本的行数、字数、字节数,格式:

wc [参数] 文本

常见参数

参数作用
-l只显示行数
-w只显示单词数
-c只显示字节数

使用

wc index.html

  314  1079 29087 index.html

wc -l index.html

314 index.html

wc -w index.html

1079 index.html

wc -c index.html

29087 index.html


7.stat命令

查看文件的具体存储信息和时间等信息,格式:

stat 文件名称

使用

stat index.html

  File: ‘index.html’

  Size: 29087      Blocks: 64         IO Block: 4096   regular file

Device: fd01h/64769d Inode: 141546      Links: 1

Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)

Access: 2019-02-18 16:38:19.740217908 +0800

Modify: 2019-02-18 10:54:24.000000000 +0800

Change: 2019-02-18 10:56:26.117025479 +0800

 Birth: -


8.cut命令

按“列”提取文本字符,格式:

cut [参数] 文本

使用

head -n 2 /etc/passwd

root:x:0:0:root:/root:/bin/bash

bin:x:1:1:bin:/bin:/sbin/nologin

head -n 2 /etc/passwd | cut -d: -f1

root

bin

head -n 2 /etc/passwd | cut -d: -f3

0

1


9.diff命令

比较多个文本文件的差异,格式:

diff [参数] 文件

比较两个文件的区别

[root@google www.zwdu.com]# cat a.txt

hello world!

aaa



bbb

[root@google www.zwdu.com]# cat b.txt

hello world

bbb

aaa

判断两个文件是否相同

[root@google www.zwdu.com]# diff --brief a.txt b.txt

Files a.txt and b.txt differ

[root@google www.zwdu.com]# diff -c a.txt b.txt

*** a.txt 2019-02-18 17:16:06.419777001 +0800

--- b.txt 2019-02-18 17:16:26.283450641 +0800

***************

*** 1,4 ****

! hello world!

! aaa

  bbb

--- 1,3 ----

! hello world

  bbb

+ aaa

展开阅读全文