IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 系统运维 -> Linux基本命令之文件及目录命令02 -> 正文阅读

[系统运维]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:---------------------------------------------------------《加载完成》---------------------------------------------------------------
欢迎交流在这里插入图片描述

  系统运维 最新文章
配置小型公司网络WLAN基本业务(AC通过三层
如何在交付运维过程中建立风险底线意识,提
快速传输大文件,怎么通过网络传大文件给对
从游戏服务端角度分析移动同步(状态同步)
MySQL使用MyCat实现分库分表
如何用DWDM射频光纤技术实现200公里外的站点
国内顺畅下载k8s.gcr.io的镜像
自动化测试appium
ctfshow ssrf
Linux操作系统学习之实用指令(Centos7/8均
上一篇文章      下一篇文章      查看所有文章
加:2021-07-31 17:01:25  更:2021-07-31 17:02:02 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年12日历 -2024/12/27 11:34:24-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码
数据统计