大数据全系列 教程
1869个小节阅读:467.9k
目录
408考研
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
touch 已存在的文件,抹平各个时间
touch 不存在的文件,则创建文件
xxxxxxxxxx
[root@node1 ~]# ll
总用量 4
-rw-------. 1 root root 1201 8月 17 01:33 anaconda-ks.cfg
[root@node1 ~]# touch anaconda-ks.cfg
[root@node1 ~]# ll
总用量 4
-rw-------. 1 root root 1201 8月 17 17:51 anaconda-ks.cfg
[root@node1 ~]# touch names.txt
[root@node1 ~]# ll
总用量 4
-rw-------. 1 root root 1201 8月 17 17:51 anaconda-ks.cfg
-rw-r--r-- 1 root root 0 8月 17 17:51 names.txt
[root@node1 ~]# rm -f names.txt
直接查看一个文件的内容可以使用cat,tac,nl这几个指令
cat是concatenate的缩写,其功能时间一个文件的内容连续的输出。该命令适合看行数较少的文件。另外,需要查看一般DOS文件时,可以通过-A选项来显示换行符和[tab]。
xxxxxxxxxx
[root@node1 ~]# cat /etc/issue
\S
Kernel \r on an \m
tac(反向输出):
xxxxxxxxxx
[root@node1 ~]# tac /etc/issue
Kernel \r on an \m
\S
与上面的cat命令进行比较,是由最后一行先显示。
tac功能与cat类似,但是是由文件最后一行反向连续输出到屏幕上。
nl(添加行号打印):
nl可以将输出的文件内容自动的加上行号。
xxxxxxxxxx
[root@node1 ~]# nl /etc/issue
1 \S
2 Kernel \r on an \m
[root@node1 ~]# nl -b a /etc/issue
1 \S
2 Kernel \r on an \m
3
[root@node1 ~]# nl -b t /etc/issue
1 \S
2 Kernel \r on an \m
[root@node1 ~]#
格式:head [-n number] 文件
以/etc/man.config文件为例:
xxxxxxxxxx
[root@node1 ~]# head /etc/man_db.conf
#
#
# This file is used by the man-db package to configure the man and cat paths.
# It is also used to provide a manpath for those without one by examining
# their PATH environment variable. For details see the manpath(5) man page.
#
# Lines beginning with `#' are comments and are ignored. Any combination of
# tabs or spaces may be used as `whitespace' separators.
#
# There are three mappings allowed in this file:
[root@node1 ~]# head -n 5 /etc/man_db.conf
#
#
# This file is used by the man-db package to configure the man and cat paths.
# It is also used to provide a manpath for those without one by examining
# their PATH environment variable. For details see the manpath(5) man page.
[root@node1 ~]# wc -l /etc/man_db.conf
131 /etc/man_db.conf #该文件一共131行
[root@node1 ~]# head -n -128 /etc/man_db.conf
#
#
# This file is used by the man-db package to configure the man and cat paths.
[root@node1 ~]#
-128等价于 文件总行数131-128,获取前3条数据。
命令格式:tail [ -n number] 文件
选项与参数:
-n:后面接数字,代表显示几行的意思
-f:表示持续侦测后面文件内容的改变,知道按下Ctrl+c才会结束tail的侦测。
xxxxxxxxxx
#默认情况下显示最后10行:
[root@node1 ~]# tail /etc/profile
#如果先要显示最后20行,就要如下:
[root@node1 ~]# tail -n 20 profile
#检测文件变化,一般用于边测试,边查看日志
[root@node1 ~]# tail -f profile