Linux学习笔记(2)

本文深入解析了Linux系统中常用的touch、cat、tac、more、less、head、tail等命令的功能、用法及实例,提供了从创建文件到浏览、搜索、筛选文件内容的全面指南。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Linux 常用命令

touch:
作用:改变目录或文件的时间,或创建一个新的文件
用法:

[jerry@localhost test]$ touch newfile1 newfile2
[jerry@localhost test]$ ll
total 0
-rw-rw-r--. 1 jerry jerry 0 Oct  1 21:53 newfile1
-rw-rw-r--. 1 jerry jerry 0 Oct  1 21:53 newfile2
  • [-r –reference]把指定的目录或文件的时间设置成和参考目录或文件的时间相同,touch -r [参考…] [指定…]
[jerry@localhost test]$ touch newfile3
[jerry@localhost test]$ ll
total 0
-rw-rw-r--. 1 jerry jerry 0 Oct  1 21:53 newfile1
-rw-rw-r--. 1 jerry jerry 0 Oct  1 21:53 newfile2
-rw-rw-r--. 1 jerry jerry 0 Oct  1 21:57 newfile3
[jerry@localhost test]$ touch -r newfile3 newfile1
[jerry@localhost test]$ ll
total 0
-rw-rw-r--. 1 jerry jerry 0 Oct  1 21:57 newfile1
-rw-rw-r--. 1 jerry jerry 0 Oct  1 21:53 newfile2
-rw-rw-r--. 1 jerry jerry 0 Oct  1 21:57 newfile3

cat:
作用:

  • 一次显示整个文件,cat filename
  • 从键盘创建一个文件,cat > filename
  • 将多个文件合并成一个文件,cat file1 file2 > newfile

用法:

[jerry@localhost test]$ cat /etc/issue
\S
Kernel \r on an \m
[jerry@localhost test]$ cat > kbfile
Hello World
Linux    
Enjoy 
^C
[jerry@localhost test]$ ls
kbfile  newfile1  newfile2  newfile3
[jerry@localhost test]$ cat kbfile 
Hello World
Linux
Enjoy

tac:
作用:与cat类似,反向列示
用法:

[jerry@localhost test]$ tac kbfile 
Enjoy
Linux
Hello World

more:
作用:功能与cat类似,cat命令是将整个文件的内容从上到下显示在屏幕上,more会一页一页的显示,方便使用者逐页阅读

  • 按空格键[space]:显示下一页
  • 按字母键b:显示上一页

用法:

more filename
  • [-n –num]每页显示n行

less:
作用:与more类似,但更具弹性,less 在查看之前不会加载整个文件
用法:

less filename

浏览文件过程中

  • 按/内容,向下搜索“内容”,按字母键n翻页
  • 按?内容,向上搜索“内容”,按字母键n翻页

head:
作用:显示文件的开头,默认显示前10行
用法:

head filename
  • [-n –lines]:指定显示文件前n行

tail:
作用:与head类似,反向显示
用法:

tail filename
  • [-n –lines]:指定显示文件末尾n行
  • [-f –follow]:动态显示文件末尾内容,可以用来监视log文件
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值