Linux查看文件内容命令03

01.cat
查看文件内容

cat cat /etc/chrony.conf
cat -b /etc/chrony.conf     #显示行号,空白行不显示
cat -n /etc/chrony.conf     #显示行号,包括空白行 
cat >> a.txt                #向文件写内容
cat >> a.txt << END         #向文件写内容(END结束写入)

02.less(more)
全屏式分页显示文件内容

less /etc/chrony.conf
more /etc/chrony.conf   

逐行滚动---回车键
向上翻页--- b
向下翻页--- 空格键
退 出--- q

03.head
查看文件头部内容,默认十行

head /etc/chrony.conf
head -n 1 /etc/chrony.conf     #查看前第n行
head -n -1 /etc/chrony.conf    #不查看最后n行
head -c 2k /etc/chrony.conf    #查看文件前2k内容
head -f /etc/chrony.conf       #实时动态查看文件内容

04.tail
查看文件尾部内容,默认十行

tail -n 2 /etc/chrony.conf     #查看后n行
tail -n +2 /etc/chrony.conf    #从第n行开始查看

05.wc
统计文件内容,结果为行数,词数,字节数(空白,跳格,换行),文件名

wc /etc/chrony.conf
wc -w /etc/chrony.conf        #统计字数
wc -l /etc/chrony.conf        #统计行数
wc -c /etc/chrony.conf        #统计字节数
wc -m /etc/chrony.conf        #统计字符数
#一个汉字占两个字节
wc -L /etc/chrony.conf        #最长行的长度
wc -w -l -c -L /etc/chrony.conf

06.grep
查找指定字符串的行

grep 'log' /etc/chrony.conf      #包含log的行
grep -c 'log' /etc/chrony.conf   #包含log的行数
grep -i 'log' /etc/chrony.conf    #不区分大小写
grep -v 'log' /etc/chrony.conf   #不包含log的行
grep --color 'log' /etc/chrony.conf  #对关键字显示颜色
grep '^log' /etc/chrony.conf     #以log开头的行
grep 'st$' /etc/chrony.conf      #以st结尾的行
grep "^$" /etc/chrony.conf       #查找空白行

07.echo
输出字符串

echo "hello the world"              #输出
echo -n "hello the world"           #输出后不换行
echo -e "hello\c"
echo -e "\\"                        #支持转义字符,输出\
echo -e "\a"                        #计算器响一声
echo -e "124\b33"                   #退一个,删除4
echo -e "hello\fthe\fworld"         #表单格式
echo -e "hello\n
> world"                            #换行
echo -e  "hello\tthe\tworld"        #水平Tab
echo -e  "hello\vthe\vworld"        #垂直Tab
echo -e  "\033[34mdate\033[0m"      #输出蓝色date
echo -e  "\033[31mdate\033[0m"      #输出红色date
#0m关闭颜色,30黑,31红,32绿,33黄,34蓝,35紫,36深绿,37白

你可能感兴趣的:(Linux查看文件内容命令03)