Linux基本命令之文件及目录命令02

在这里插入图片描述

接上一个博客

文件及目录01:https://blog.csdn.net/qq_40520912/article/details/119224154

2.9、 rm:删除目录或文件

语法:

rm [参数] [文件或目录]

选项与参数:

  • -f :强制删除,不会出现提示警告信息
  • -i :互动模式,会出现提示警告信息
  • -r :递归删除,删除目录,这是个非常危险的选项,最好别用!!!

案例

1.将/home/itbestboy/test02 目录下的文件test.java文件删除。

#强制删除 f
[root@root test02]# rm -f test.java 
[root@root test02]# ls
test01
[root@root test02]# touch test.java
[root@root test02]# ls
test01  test.java
#提示删除 i
[root@root test02]# rm -i test.java 
rm: remove regular empty file ‘test.java’? y
[root@root test02]# ls
test01

2.将/home/itbestboy/test02 目录下的test01目录删除。

[root@root test02]# rm -f test01
rm: cannot remove ‘test01’: Is a directory
#建议不要使用,最好忘记这个参数,太恐怖了!!!!!
[root@root test02]# rm -rf test01
[root@root test02]# ls
[root@root test02]# 

2.10、cat:显示文件内容

cat 查看文件内容从第一行开始查看,以只读的方式打开,比较适合看内容较少的文件

语法

cat [参数] [文件名]

选项与参数:

**-n **:由 1 开始对所有输出的行数编号(包括空行)。

-b:所有输出的行数编号(不包括空行)。

**-s **:当遇到有连续两行以上的空白行,就代换为一行的空白行。

案例

查看/home/itbestboy/test01 目录下的hello.java文件。

root@root test01]# cat hello.java 
hello everyone!!!!!
HELLOW   JAVA    PYTHON


HELLO

GOOGL
#加参数 n
[root@root test01]# cat -n hello.java 
     1	hello everyone!!!!!
     2	HELLOW   JAVA    PYTHON
     3	
     4	
     5	HELLO
     6	
     7	GOOGL
     8	
 
#加参数 b
[root@root test01]# cat -b hello.java 
     1	hello everyone!!!!!
     2	HELLOW   JAVA    PYTHON


     3	HELLO

     4	GOOGL


#加参数 s
[root@root test01]# cat -s hello.java 
hello everyone!!!!!
HELLOW   JAVA    PYTHON

HELLO

GOOGL
#加参数 ns
[root@root test01]# cat -ns hello.java 
     1	hello everyone!!!!!
     2	HELLOW   JAVA    PYTHON
     3	
     4	HELLO
     5	
     6	GOOGL
     7	
[root@root test01]# 

2.11、tac:反向显示文件内容

tac查看文件内容从最后一行开始查看,以只读的方式打开,比较适合看内容较少的文件

语法

tac [参数] [文件名]

案例

查看/home/itbestboy/test01 目录下的hello.java文件。

[root@root /]# tac /home/itbestboy/test01/hello.java 

GOOGL

HELLO


HELLOW   JAVA    PYTHON
hello everyone!!!!!

2.12、more:分页显示文件内容

more与cat命令类似,都是用来查看文件的内容,但是more适合查看大文件的内容,是一个基于 VI 编辑器的文本过滤器,它以全屏幕的方式按页显示文本文件的内容!!

语法

more [参数] [文件]

参数

  • -num:每次显示的行数
  • -f 计算行数时,以实际上的行数,而非自动换行过后的行数
  • -p 不以卷动的方式显示每一页,而是先清除萤幕后再显示内容
  • -s 当遇到有连续两行以上的空白行,就代换为一行的空白行
  • +num 从第 num 行开始显示

案例

1.查看/home/itbestboy/test01 目录下的hello.java文件。

[root@root /]# more /home/itbestboy/test01/hello.java 
hello everyone!!!!!
HELLOW   JAVA    PYTHON


HELLO

GOOGL
There is no denying the fact that it is a hotly debated topic 
today how college graduates should choose their careers.
 Some time ago, it was reported that some college graduates chose to work as village officials.
 To this people's attitudes differ sharply. Some hold the positive view while others are against it.
 As far as I am concerned, I believe that it is a wise choice.



On the one hand, college graduates can contribute a lot to the development of the countryside. 
First, they can apply their professional knowledge there.
 Secondly, they can introduce new concepts to the countryside and speed the development of rural culture
. As a result, the gap between the city and the countryside can well be bridged.

On the other hand, these graduates can benefit a lot from working as village officials
. While too many college graduates are fighting for the handful of positions in big cities,
--More--(87%)

2.查看/home/itbestboy/test01 目录下的hello.java文件,每次显示10行。

[root@root /]# more -5 /home/itbestboy/test01/hello.java 
hello everyone!!!!!
HELLOW   JAVA    PYTHON


HELLO

GOOGL
There is no denying the fact that it is a hotly debated topic 
today how college graduates should choose their careers.
--More--(14%)

3.查看/home/itbestboy/test01 目录下的hello.java文件,从第10行开始。

[root@root /]# more +10 /home/itbestboy/test01/hello.java 
 Some time ago, it was reported that some college graduates chose to work as village officials.
 To this people's attitudes differ sharply. Some hold the positive view while others are against it.
 As far as I am concerned, I believe that it is a wise choice.



On the one hand, college graduates can contribute a lot to the development of the countryside. 
First, they can apply their professional knowledge there.
 Secondly, they can introduce new concepts to the countryside and speed the development of rural culture
. As a result, the gap between the city and the countryside can well be bridged.

On the other hand, these graduates can benefit a lot from working as village officials
. While too many college graduates are fighting for the handful of positions in big cities,
 these graduates can find themselves a wider stage of development and realize their value.



Therefore, college graduates working as village officials is a win-win choice and more graduates should be encouraged to work in the countryside.
[root@root /]# 

**注:**常用翻页操作

操作功能
空格键向下翻一页
Enter向下翻一行
q退出more,不在显示内容
Ctrl+b返回上一屏
Ctrl+F向下滚动一屏
/字符查找这个字符

2.13、less:分页显示文件内容

less与more命令类似,都是用来查看文件的内容,但是比 more 指令更加强大,支持各种显示终端。less 指令在显示文件内容时,并不是一次将整个文件加载之后才显示,而是根据显示需要加载内容,以分屏幕的方式显示文本文件的内容对于显示大型文件具有较高的效率。

语法

less [参数] [文件]

参数说明

  • -b <缓冲区大小> 设置缓冲区的大小
  • -f 强迫打开特殊文件,例如外围设备代号、目录和二进制文件
  • -g 只标志最后搜索的关键词
  • -i 忽略搜索时的大小写
  • -m 显示类似more命令的百分比
  • -N 显示每行的行号

案例

1.查看/home/itbestboy/test01 目录下的hello.java文件。

[root@root /]# less /home/itbestboy/test01/hello.java 

**注:**常用操作

操作功能
Ctrl+D向前滚动半屏
Ctrl+U向后滚动半屏
q退出more,不在显示内容
Ctrl+B向后移动一屏
Ctrl+F向前滚动一屏
/字符查找这个字符

2.14、head:显示文件头部内容

head 命令可用于查看文件的开头部分的内容,默认显示 10 行的内容。

语法

head [参数] [文件]

参数:

  • -n<行数> 显示的行数(常用)。
  • -c<数目> 显示的字节数
  • -q 隐藏文件名
  • -v 显示文件名

案例

1.查看/home/itbestboy/test01 目录下的hello.java文件的前10行。

[root@root /]# head /home/itbestboy/test01/hello.java 
hello everyone!!!!!
HELLOW   JAVA    PYTHON


HELLO

GOOGL
There is no denying the fact that it is a hotly debated topic 
today how college graduates should choose their careers.
 Some time ago, it was reported that some college graduates chose to work as village officials.

2.查看/home/itbestboy/test01 目录下的hello.java文件的前10个字符。

[root@root /]# head -c 10 /home/itbestboy/test01/hello.java 
hello ever

2.15、tail:显示文件尾部内容

tail 用于输出文件中尾部的内容,默认情况下 tail 指令显示文件的后 10 行内容。一般这个命令还可以用来做追踪,比如日志更新等

语法

tail [参数] [文件]

参数:

  • -f 实时追踪文档的所有更新
  • -c<数目> 显示的字节数
  • -n<行数> 显示文件的尾部 n 行内容
  • +n<行数> 显示从文件第n行到尾部的内容
  • -q 隐藏处理信息
  • -v 显示处理信息
  • –pid=PID 与-f合用,表示在进程ID,PID死掉之后结束
  • -q, --quiet, --silent 从不输出给出文件名的首部
  • -s, --sleep-interval=S 与-f合用,表示在每次反复的间隔休眠S秒

案例

1.查看/home/itbestboy/test01 目录下的hello.java文件的后20行。

[root@root /]# tail -n 20 /home/itbestboy/test01/hello.java 
There is no denying the fact that it is a hotly debated topic 
today how college graduates should choose their careers.
 Some time ago, it was reported that some college graduates chose to work as village officials.
 To this people's attitudes differ sharply. Some hold the positive view while others are against it.
 As far as I am concerned, I believe that it is a wise choice.



On the one hand, college graduates can contribute a lot to the development of the countryside. 
First, they can apply their professional knowledge there.
 Secondly, they can introduce new concepts to the countryside and speed the development of rural culture
. As a result, the gap between the city and the countryside can well be bridged.

On the other hand, these graduates can benefit a lot from working as village officials
. While too many college graduates are fighting for the handful of positions in big cities,
 these graduates can find themselves a wider stage of development and realize their value.



Therefore, college graduates working as village officials is a win-win choice and more graduates should be encouraged to work in the countryside.
[root@root /]# 

2.查看/home/itbestboy/test01 目录下的hello.java文件的后20个字符。

[root@root /]# tail -c 20 /home/itbestboy/test01/hello.java 
in the countryside.

3.追踪/home/itbestboy/test01 目录下hello.java文件的增长情况。

[root@root /]# tail -f /home/itbestboy/test01/hello.java 

2.16、nl:显示行号

语法

nl [参数] [文件]

选项与参数:

  • -b :指定行号指定的方式,主要有两种:
    -b a :表示不论是否为空行,也同样列出行号(类似 cat -n);
    -b t :如果有空行,空的那一行不要列出行号(默认值);
  • -n :列出行号表示的方法,主要有三种:
    -n ln :行号在荧幕的最左方显示;
    -n rn :行号在自己栏位的最右方显示,且不加 0 ;
    -n rz :行号在自己栏位的最右方显示,且加 0 ;
  • -w :行号栏位的占用的位数。

案例

查看/home/itbestboy/test01 目录下的hello.java文件。

[root@root /]# nl  /home/itbestboy/test01/hello.java
     1	hello everyone!!!!!
     2	HELLOW   JAVA    PYTHON
       
       
     3	HELLO
       
     4	GOOGL
     5	There is no denying the fact that it is a hotly debated topic 
     6	today how college graduates should choose their careers.
     7	 Some time ago, it was reported that some college graduates chose to work as village officials.
     8	 To this people's attitudes differ sharply. Some hold the positive view while others are against it.
     9	 As far as I am concerned, I believe that it is a wise choice.
       
       
       
    10	On the one hand, college graduates can contribute a lot to the development of the countryside. 
    11	First, they can apply their professional knowledge there.
    12	 Secondly, they can introduce new concepts to the countryside and speed the development of rural culture
    13	. As a result, the gap between the city and the countryside can well be bridged.
       
    14	On the other hand, these graduates can benefit a lot from working as village officials
    15	. While too many college graduates are fighting for the handful of positions in big cities,
    16	 these graduates can find themselves a wider stage of development and realize their value.
       
       
       
    17	Therefore, college graduat

Linux基本命令之文件及目录命令01:---------------------------------------------------------《加载完成》---------------------------------------------------------------
欢迎交流在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值