【Linxu】基础命令详解

本文详细介绍了Linux系统中的常见命令,包括文件管理(如rm、cp、mv)、目录操作(mkdir、rmdir)、文件查看(ls、cat、more、less)、文本编辑(vim)、命令历史(history)等,以及一些实用工具如tree、seq、tr等的使用方法,旨在帮助用户更好地理解和操作Linux系统。
摘要由CSDN通过智能技术生成

系统命令结构

在Linux遇到[] 大部分都是或者的含义,不是必须项
语法结构:
做什么? 条件 目标
命令 空格 [参数选项] 空格 文件名称/目录名称/带路径的文件目录

rm   -f  123.txt       # 强制删除当前目录下的123.txt  相对路径删除123.txt 
rm   -f  /opt/123.txt  # 绝对路径删除123.txt

rm -f123.txt 将-f123.txt 当成文件进行rm操作,参数与目标必须有空格隔开

在Linux系统中 # 表示不执行命令 注释 给我们自己看的

[root@AHui ~]# #pwd		 # 不执行命令
[root@AHui ~]# 

pwd

print working directory 显示当前的路径 显示当前所在的位置

[root@AHui network-scripts]# pwd
/etc/sysconfig/network-scripts

cd

change directory 改变目录 切换路径
使用相对路径到/etc/sysconfig目录下

[root@AHui ~]# cd /
[root@AHui /]# cd etc
[root@AHui etc]# pwd
/etc
[root@AHui etc]# cd sysconfig
[root@AHui sysconfig]# pwd
/etc/sysconfig
[root@AHui sysconfig]# cd

直接使用绝对路径到达目标位置

[root@AHui ~]# cd /etc/sysconfig
[root@AHui sysconfig]# pwd
/etc/sysconfig

cd的快捷方式:
cd 直接回车 直接回到家目录
cd - 回到上一次所在的目录
cd ~ 直接回到家目录
. 表示当前的含义 当前所在的位置
cd . 哪也没去
… 表示上一级目录
cd … 返回到上一级目录

ls

list 列表 显示当前或者显示目录下面所有的文件或目录(可以看到目录下的所有内容)
语法结构:
	ls [参数选项]            	# 直接回车显示当前目录下所有内容
	ls [参数选项] 123.txt  		#查看123.txt 是否存在
	ls [参数选项] /opt/    	  	# 查看/opt目录下有什么内容

ls的常用参数:
-l long 列出文件的详细信息

[root@AHui ~]# ls
anaconda-ks.cfg
[root@AHui ~]# ls anaconda-ks.cfg 
anaconda-ks.cfg
[root@AHui ~]# ls 123.txt
ls: cannot access 123.txt: No such file or directory
 
[root@AHui ~]# ls /opt/
123.txt
[root@AHui ~]# ls /opt/123.txt 
/opt/123.txt

相对路径和绝对路径:
在/etc/sysconfig/目录下 查看etc目录有哪些内容

[root@AHui sysconfig]# pwd
/etc/sysconfig
[root@AHui sysconfig]# ls ../

在/etc/sysconfig/目录下 使用绝对路径查看root目录有哪些内容

[root@AHui sysconfig]# ls /root
anaconda-ks.cfg

ls -l 显示文件的详细信息

[root@AHui ~]# ls -l /opt/
total 0
-rw-r--r--. 1 root root 0 Apr 28 15:24 123.txt
drwxr-xr-x. 2 root root 6 Apr 28 16:20 test

ls -l别名 ll 显示文件或者目录下的详细属性信息,效果相同

[root@AHui ~]# ll
total 4
-rw-------. 1 root root 1522 Apr 27 11:25 anaconda-ks.cfg
[root@AHui ~]# ll /opt/
total 0
-rw-r--r--. 1 root root 0 Apr 28 15:24 123.txt
drwxr-xr-x. 2 root root 6 Apr 28 16:20 test

touch

触碰/摸 创建普通文件(如果文件不存在则创建 如果文件存在则只会修改文件的时间属性 文件存在不影响文件内容)
语法结构:
创建单个文件
touch 文件名称
touch 路径/文件名称

#在当前的路径创建一个名称为123.txt的普通文件 
[root@AHui ~]# touch 123.txt
[root@AHui ~]# ll
-rw-r--r--. 1 root root 0 Apr 28 16:28 123.txt
[root@AHui ~]# ll
# 重新创建只修改时间 不影响文件内容
[root@AHui ~]# touch 123.txt
-rw-r--r--. 1 root root 0 Apr 28 16:29 123.txt

创建多个文件

touch 文件1 文件2 文件3
[root@AHui ~]# touch 1.txt 2.txt 3.txt
[root@AHui ~]# ll
total 0
-rw-r--r--. 1 root root 0 Apr 28 16:31 1.txt
-rw-r--r--. 1 root root 0 Apr 28 16:31 2.txt
-rw-r--r--. 1 root root 0 Apr 28 16:31 3.txt
-rw-r--r--. 1 root root 0 Apr 28 16:29 123.txt

# 删除当前路径下所有的文件 * 表示所有
[root@AHui ~]# rm -f *

创建多个文件在不同的路径,通过目录查看目录下的文件名称

[root@AHui ~]# touch 123.txt /opt/1.txt /tmp/2.txt
[root@AHui ~]# ll
total 0
-rw-r--r--. 1 root root 0 Apr 28 16:32 123.txt
[root@AHui ~]# ll /opt
total 0
-rw-r--r--. 1 root root 0 Apr 28 16:32 1.txt
-rw-r--r--. 1 root root 0 Apr 28 15:24 123.txt
drwxr-xr-x. 2 root root 6 Apr 28 16:20 test
[root@AHui ~]# ll /tmp/
total 4
-rw-r--r--. 1 root root   0 Apr 28 16:32 2.txt
-rwx------. 1 root root 836 Apr 27 11:25 ks-script-4rmS7G
drwx------. 2 root root   6 Apr 27 11:37 vmware-root_877-4022177778
-rw-------. 1 root root   0 Apr 27 11:14 yum.log

直接通过加上名称查看

#同时查看多个目录下所有的文件
[root@AHui ~]# ll /opt/ /tmp/
#查看当前的目录以及/opt和/tmp
[root@AHui ~]# ll ~
total 0
-rw-r--r--. 1 root root 0 Apr 28 16:32 123.txt
[root@AHui ~]# ll /root/
total 0
-rw-r--r--. 1 root root 0 Apr 28 16:32 123.txt
#“.”代表本目录
[root@AHui ~]# ll .
total 0
-rw-r--r--. 1 root root 0 Apr 28 16:32 123.txt
[root@AHui ~]# ll . /opt/ /tmp/
.:
total 0
-rw-r--r--. 1 root root 0 Apr 28 16:32 123.txt

/opt/:
total 0
-rw-r--r--. 1 root root 0 Apr 28 16:32 1.txt
-rw-r--r--. 1 root root 0 Apr 28 15:24 123.txt
drwxr-xr-x. 2 root root 6 Apr 28 16:20 test

/tmp/:
total 4
-rw-r--r--. 1 root root   0 Apr 28 16:32 2.txt
-rwx------. 1 root root 836 Apr 27 11:25 ks-script-4rmS7G
drwx------. 2 root root   6 Apr 27 11:37 vmware-root_877-4022177778
-rw-------. 1 root root   0 Apr 27 11:14 yum.log

使用文件名称查看:

[root@AHui ~]# ll 123.txt /opt/1.txt /tmp/2.txt 
-rw-r--r--. 1 root root 0 Apr 28 16:32 123.txt
-rw-r--r--. 1 root root 0 Apr 28 16:32 /opt/1.txt
-rw-r--r--. 1 root root 0 Apr 28 16:32 /tmp/2.txt
[root@AHui ~]# ll 123.txt /opt/1.txt /tmp/22222222.txt 
ls: cannot access /tmp/22222222.txt: No such file or directory
-rw-r--r--. 1 root root 0 Apr 28 16:32 123.txt
-rw-r--r--. 1 root root 0 Apr 28 16:32 /opt/1.txt

cp

copy 复制文件
语法结构:
cp 参数选项 源文件 目标位置/文件
参数:
-r 拷贝目录及目录下面所有的文件 递归拷贝

[root@AHui ~]# rm -rf /opt/*
[root@AHui ~]# ll /opt/
total 0

#复制一份123.txt 文件到/opt目录下 名称不变
[root@AHui ~]# cp 123.txt /opt/
[root@AHui ~]# ll /opt/
total 0
-rw-r--r--. 1 root root 0 Apr 28 16:47 123.txt

#复制当前目录123.txt 到/opt目录下 并且修改名称为test.txt
[root@AHui ~]# cp 123.txt /opt/test.txt

cp 123.txt /opt/123.txt 等于 cp 123.txt /opt/
cp 123.txt /opt/test.txt

#删除
[root@AHui ~]# rm -rf /opt/*
[root@AHui ~]# 
[root@AHui ~]# ll /opt/
total 0
[root@AHui ~]# ll
total 0
-rw-r--r--. 1 root root 0 Apr 28 16:32 123.txt

复制多个文件最后必须是目录, 复制单个文件 最后可以是文件名称

#如果最后面是文件则提示 1.txt不是一个目录 拷贝报错
[root@AHui ~]# cp 1.txt 123.txt /opt/1.txt
cp: target ‘/opt/1.txt’ is not a directory
[root@AHui ~]# ll /opt/
total 0

正确的拷贝多个文件的方式

#复制多个文件
[root@AHui ~]# cp 1.txt 123.txt  /opt/
[root@AHui ~]# ll /opt/
total 0
-rw-r--r--. 1 root root 0 Apr 28 17:49 1.txt
-rw-r--r--. 1 root root 0 Apr 28 17:49 123.txt

将/opt/1.txt 拷贝到/tmp目录
相对路径:

[root@AHui ~]# rm -rf /tmp/*
[root@AHui opt]# cp 1.txt /tmp/
[root@AHui opt]# ll /tmp/
total 0
-rw-r--r--. 1 root root 0 Apr 28 17:51 1.txt

绝对路径:

[root@AHui ~]# cp /opt/1.txt /tmp/
cp: overwrite ‘/tmp/1.txt’? y

注意: 如果文件存在会提示是否覆盖 y覆盖 n不覆盖

#拷贝/tmp目录下的1.txt 和/opt目录下的123.txt 到当前的路径
[root@AHui ~]# rm -rf *
[root@AHui ~]# ll
total 0

[root@AHui ~]# cp /tmp/1.txt /opt/123.txt .
[root@AHui ~]# ll
total 0
-rw-r--r--. 1 root root 0 Apr 28 17:54 1.txt
-rw-r--r--. 1 root root 0 Apr 28 17:54 123.txt

复制目录:
案例:
1.在当前目录创建testdir目录

[root@AHui ~]# rm -rf *
	[root@AHui ~]# mkdir testdir
	[root@AHui ~]# ll
	total 0
	drwxr-xr-x. 2 root root 6 Apr 28 18:06 testdir

2.在testdir目录下创建test.txt 文件

[root@AHui ~]# touch testdir/test.txt
[root@AHui ~]# ll testdir/
total 0
-rw-r--r--. 1 root root 0 Apr 28 18:06 test.txt

3.将testdir目录移动到/opt目录下

[root@AHui ~]# rm -rf /opt/*
	[root@AHui ~]# ll /opt/
	total 0
	[root@AHui ~]# cp -r testdir/ /opt/
	[root@AHui ~]# ll /opt/
	total 0
	drwxr-xr-x. 2 root root 22 Apr 28 18:08 testdir
	[root@AHui ~]# ll /opt/testdir/
	total 0
	-rw-r--r--. 1 root root 0 Apr 28 18:08 test.txt
隐藏参数:
	为了安全系统给命令加了默认的参数 称为别名 
	执行rm实际执行	rm -i   删除文件是否删除
	执行ll实际执行	ls -l	列出文件与其详细信息
	执行mv实际执行 	mv -i	剪切文件是否覆盖 
	执行cp实际执行 	cp -i		拷贝文件是否覆盖

取消参数不让他提示 直接执行 使用\

 [root@AHui ~]# \cp -r /etc .

mkdir

make directory创建目录 如果目录存在则给提示: 目录已存在 不会修改时间
语法结构:
mkdir [参数选项] 目录名称/路径目录名称 # 创建单个目录
mkdir dir1 dir2 dir3 # 创建多个目录
参数:
-p 递归创建目录 如果目录不存在则创建 存在则不提示
mkdir -p test/testdir1/testdir2/testdir3

[root@AHui ~]# mkdir testdir
[root@AHui ~]# ll
total 0
-rw-r--r--. 1 root root 0 Apr 28 17:54 1.txt
drwxr-xr-x. 2 root root 6 Apr 28 17:57 testdir

一次创建多个目录:

[root@AHui ~]# mkdir testdir1 testdir2 testdir3
[root@AHui ~]# ll
total 0
-rw-r--r--. 1 root root 0 Apr 28 17:54 1.txt
drwxr-xr-x. 2 root root 6 Apr 28 17:57 testdir
drwxr-xr-x. 2 root root 6 Apr 28 17:59 testdir1
drwxr-xr-x. 2 root root 6 Apr 28 17:59 testdir2
drwxr-xr-x. 2 root root 6 Apr 28 17:59 testdir3

创建带路径的多个目录

[root@AHui ~]# mkdir /opt/test1 /tmp/test2
[root@AHui ~]# ll /opt/ /tmp/
/opt/:
total 0
-rw-r--r--. 1 root root 0 Apr 28 17:49 1.txt
-rw-r--r--. 1 root root 0 Apr 28 17:49 123.txt
drwxr-xr-x. 2 root root 6 Apr 28 18:00 test1

/tmp/:
total 0
-rw-r--r--. 1 root root 0 Apr 28 17:52 1.txt
drwxr-xr-x. 2 root root 6 Apr 28 18:00 test2
[root@AHui ~]# rm testdir/
	rm: cannot remove ‘testdir/’: Is a directory

-r 删除目录及目录下所有的文件 但是会有-i参数的提示信息 是否删除
使用rm -r 递归删除目录及目录下所有的文件 和cp -r 相同的
使用rm -rf 强制删除目录及目录下所有文件并且不提示 和\rm -r 效果相同 此命令危险 企业一般使用mv代替

rm

remove 删除文件 移除
语法格式:
rm [参数选项] 文件/目录/路径
参数:
-f force 强制删除不提示
-r 删除目录及目录下所有的内容
使用rm -r 递归删除目录及目录下所有的文件 和cp -r 相同的
使用rm -rf 强制删除目录及目录下所有文件并且不提示 和\rm -r 效果相同 此命令危险 企业一般使用mv代替

删除/opt/test.txt
使用绝对路径:

[root@AHui ~]# \rm /opt/test.txt

使用相对路径

[root@AHui ~]# cd /opt/
[root@AHui opt]# ll
total 0
drwxr-xr-x. 2 root root 6 Apr 29 08:39 testdir
-rw-r--r--. 1 root root 0 Apr 29 09:02 test.txt
[root@AHui opt]# rm -f test.txt 
[root@AHui opt]# ll
total 0
drwxr-xr-x. 2 root root 6 Apr 29 08:39 testdir

一次删除多个文件

[root@AHui ~]# rm -f test123.txt /opt/test123.txt /tmp/test123.txt

删除目录

[root@AHui ~]# rm -rf testdir/
[root@AHui ~]# ll
total 0

mv

move 移动文件(WINDOWS剪切) 给文件该名
语法结构:
mv 从哪里来 到哪里去
mv 源文件 目标文件

将当前目录的test123.txt 移动到/opt目录下

[root@AHui ~]# touch test123.txt
[root@AHui ~]# ll
total 0
-rw-r--r--. 1 root root 0 Apr 29 09:09 test123.txt
[root@AHui ~]# mv test123.txt /opt/
[root@AHui ~]# ll
total 0
[root@AHui ~]# ll /opt/
total 0
drwxr-xr-x. 2 root root 6 Apr 29 08:39 testdir
-rw-r--r--. 1 root root 0 Apr 29 09:09 test123.txt

移动多个文件到/opt目录

[root@AHui ~]# mv 1.txt 2.txt 3.txt /opt/
[root@AHui ~]# ll /opt/
total 0
-rw-r--r--. 1 root root 0 Apr 29 09:10 1.txt
-rw-r--r--. 1 root root 0 Apr 29 09:10 2.txt
-rw-r--r--. 1 root root 0 Apr 29 09:10 3.txt

强制覆盖使用\ 如果目标目录下有1.txt 在移动出现是否覆盖提示

[root@AHui ~]# \mv 1.txt /opt/

在系统中三个命令被加了-i参数
rm 等于 rm -i
cp 等于 cp -i
mv 等于 mv -i
案例4: 移动目录 mv直接可以对目录进行操作不需要加参数 cp和rm都需要加r参数
注意: 在移动目录时候 使用我们自己创建的目录 /etc /tmp /opt

[root@AHui ~]# ll /opt/
total 0
-rw-r--r--. 1 root root 0 Apr 29 09:13 1.txt
-rw-r--r--. 1 root root 0 Apr 29 09:10 2.txt
-rw-r--r--. 1 root root 0 Apr 29 09:10 3.txt
drwxr-xr-x. 2 root root 6 Apr 29 08:39 testdir
-rw-r--r--. 1 root root 0 Apr 29 09:09 test123.txt
[root@AHui ~]# mv /opt/testdir .
[root@AHui ~]# ll
total 0
drwxr-xr-x. 2 root root 6 Apr 29 08:39 testdir

tree

tree树 以树形机构显示目录
安装tree命令 保障是可以上网的然后在安装

[root@AHui ~]# yum -y install tree

语法结构:
tree 直接回车 以树形结构显示当前目录
tree 目录/路径目录 以树形结构显示指定目录

树形结构显示当前目录下所有的内容

[root@AHui ~]# tree
.
├── testdir
└── test
    ├── 1.txt
    ├── 2.txt
    ├── 3.txt
    └── haideshiwoyage

3 directories, 3 files

指定目录

[root@AHui ~]# tree test
test
├── 1.txt
├── 2.txt
├── 3.txt
└── haideshiwoyage

1 directory, 3 files
[root@AHui ~]# touch test/haideshiwoyage/test.txt
[root@AHui ~]# tree test
test
├── 1.txt
├── 2.txt
├── 3.txt
└── haideshiwoyage
    └── test.txt

1 directory, 4 files

[root@AHui ~]# tree -d test
test
└── haideshiwoyage

1 directory

只显示一级目录

[root@AHui ~]# tree -L 1 test
test
├── 1.txt
├── 2.txt
├── 3.txt
└── haideshiwoyage

1 directory, 3 files
[root@AHui ~]# ll test/
total 0
-rw-r--r--. 1 root root  0 Apr 29 09:22 1.txt
-rw-r--r--. 1 root root  0 Apr 29 09:22 2.txt
-rw-r--r--. 1 root root  0 Apr 29 09:22 3.txt
drwxr-xr-x. 2 root root 22 Apr 29 09:24 haideshiwoyage

vim

文件编辑器 vi的增强版本
语法结构:
vim默认没有安装: 通过yum进行安装

[root@AHui ~]# yum -y install vim

vim 文件/路径文件

注意 如果文件不存在则vim会自动创建一个文件
注意 编辑使用绝对路径编辑带目录的文件 目录必须存在 如果目录存在文件不存在会自动创建文件

在当前目录创建test123.txt 编辑内容 www.AHui.com 保存退出

第一步:
vim test123.txt —> 进入到视图模式(只能看文件中的内容)
第二步:
输入 字母 i 或者 a 进入到编辑模式(可以写入内容到文件中)
输入www.AHui.com
第三步:
按键盘的esc键(可以快速多按几次) 退出到 视图模式
第四步:
在视图模式输入“:” 进入到底行模式
在底行模式输入“:wq” 保存并且退出 “w” write写入 “q” quit 退出

简单:
vim test123.txt -->视图模式–>输入 i a 键 -->编辑模式–>esc键返回视图模式–>输入: 底行模式->:wq 保存退出

编辑test.txt 写入www.test.com 保存并退出
vim test.txt
a
www.test.com
:wq

退出
vim编辑test123.txt
1)没有对文件进行修改 可以使用:q 直接退出
2)如果修改了文件 不保存退出:q! 强制不保存退出

cat

cat猫 查看文件中的内容 不进入到文件中查看内容 (也可以使用vim打开文件查看)
语法结构:
cat 文件/路径文件 # 查看单个文件
cat 文件1 文件2 # 一次查看多个文件

查看test123.txt文件的内容

[root@AHui ~]# cat test123.txt 
www.AHui.com
[root@AHui ~]# cat test.txt 
www.test.com

注意:无法查看目录

[root@AHui ~]# cat testdir		
cat: testdir: Is a directory

查看多个文件

[root@AHui ~]# cat test123.txt test.txt 
www.AHui.com
www.test.com

输出内容到屏幕

[root@ahui ~]# cat<<EOF
> aaa
> bbb
> ccc
> EOF
aaa
bbb
ccc

将内容输入到文件

[root@ahui ~]# cat>1.txt<<EOF	#注意:> 清空  >>追加
> aaa
> bbb
> ccc
> EOF
[root@ahui ~]# cat 1.txt 
aaa
bbb
ccc

cat合并文件
第一步: cat查看多个文件内容

[root@ahui ~]# cat 1.txt 
111
222
[root@ahui ~]# cat 2.txt 
aaaa
bbbb
[root@ahui ~]# cat 1.txt 2.txt 
111
222
aaaa
bbbb

第二步: 所有输出到屏幕上的内容都可以使用>,>>输入到文件中 不影响源文件

[root@ahui ~]# cat 1.txt 2.txt > all.txt
[root@ahui ~]# cat all.txt 
111
222
aaaa
bbbb
[root@ahui ~]# cat 1.txt 
111
222
[root@ahui ~]# cat 2.txt 
aaaa
bbbb

cat -n 显示文件内容的行号

[root@ahui ~]# cat -n 2.txt 
     1	aaaa
     2	bbbb
[root@ahui ~]# cat -n all.txt 
     1	111
     2	222
     3	aaaa
     4	bbbb

echo

将内容输出到屏幕上 输入到文件中
语法:
echo “我们自己写的内容” # 回车 将我们写的内容输出到屏幕上

将内容输出到屏幕

[root@AHui ~]# echo www.baidu.com
www.baidu.com

[root@AHui ~]# echo www.baidu.com www.sina.com www.weibo.com 192.168.11.253
www.baidu.com www.sina.com www.weibo.com 192.168.11.253

将内容输入到文件中
1)使用 > 方式 会清空文件中的内容然后把内容写入到文件中 (先清空后写入)
使用>>和> 时如果文件不存在 则自动创建文件
2)使用>> 方式 会将内容追加到文件的底部 不会清空文件中的内容(内容追加)

[root@AHui ~]# echo www.baidu.com
www.baidu.com
[root@AHui ~]# 
[root@AHui ~]# cat test123.txt 
www.AHui.com
[root@AHui ~]# echo www.baidu.com > test123.txt 
[root@AHui ~]# cat test123.txt 
www.baidu.com

如果文件不存在 则自动创建文件

[root@AHui ~]# echo www.hehe.com > 1.txt
[root@AHui ~]# ll
total 12
-rw-r--r--. 1 root root 13 Apr 29 11:15 1.txt
drwxr-xr-x. 2 root root  6 Apr 29 11:07 testdir
-rw-r--r--. 1 root root 14 Apr 29 11:13 test123.txt
-rw-r--r--. 1 root root 13 Apr 29 11:00 test.txt
[root@AHui ~]# cat 1.txt 
www.hehe.com

将www.sina.com 追加写入到test123.txt 文件中

[root@AHui ~]# cat test123.txt
www.baidu.com
[root@AHui ~]# echo www.sina.com >> test123.txt 
[root@AHui ~]# cat test123.txt 
www.baidu.com
www.sina.com

seq

输出序列
-w 规范输出 seq -w 05
-s 指定分割符 seq -s + 100

[root@ahui ~]# seq 3
1
2
3
[root@ahui ~]# seq -w 05
01
02
03
04
05

[root@ahui ~]# seq -s + 100
1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17+18+19+20+21+22+23+24+25+26+27+28+29+30+31+32+33+34+35+36+37+38+39+40+41+42+43+44+45+46+47+48+49+50+51+52+53+54+55+56+57+58+59+60+61+62+63+64+65+66+67+68+69+70+71+72+73+74+75+76+77+78+79+80+81+82+83+84+85+86+87+88+89+90+91+92+93+94+95+96+97+98+99+100

less

一页一页的查看文件内容 重点 主要查看大文件使用
参数选项:
less查看到文件的底部不会退出
-N 显示行号
空格 往下翻页
f 往下翻页
b 往上翻页
ng 快速到n行
g 快速到首行
G 快速到文件的末尾
/ 搜索内容
n 往下查找
N 往上查找
q 退出less模式
v 进入到编辑模式 按:q 退出编辑模式 然后在按q退出less模式

more

命令 一页一页的查看 了解 翻到文件底部 直接退出
f 往下翻页
b 往上翻页
/ 搜索
不支持快捷键

tr

一对一的替换 主要用于替换特殊字符 不影响源文件

[root@ahui ~]# cat 2.txt |tr ":" "-"
root-x-0-0-root-/root-/bin/bash

[root@ahui ~]# cat 2.txt |tr "/" "?"
root:x:0:0:root:?root:?bin?bash

[root@ahui ~]# cat 2.txt |tr ":" " "
root x 0 0 root /root /bin/bash

将替换后的内容输入到文件中

[root@ahui ~]# cat 2.txt |tr ":" " " > test.txt
[root@ahui ~]# cat test.txt 
root x 0 0 root /root /bin/bash

help

help 内部命令 #帮助(用于内置命令)
bash内置命令: 解释器中默认已存在的命令 不能使用man帮助查询 可以使用help

man

man 外部命令 #手册(用于外置命令)
bash外置命令: 后续安装的命令 可以使用man 也可以help命令查询

history

history #显示历史执行过的命令
-c 清空历史命令
[root@AHui ~]# !314 # 使用叹号加history显示的历史编号

注意: !cat 执行最后一次cat的动作
esc 加 . 快速调用上一次执行最后的一个参数

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值