二、CentOS基础配置(2.权限与文本管理(vi))

文章目录

    • 4、权限管理
      • [1、chmod - 修改文件或目录权限](#1、chmod - 修改文件或目录权限)
        • [(1.)-R - 递归改变给定目录及其子目录中所有文件或目录的权限](#(1.)-R - 递归改变给定目录及其子目录中所有文件或目录的权限)
        • [(2.)-c - 逐一列出更改的文件权限](#(2.)-c - 逐一列出更改的文件权限)
        • [(3.)-v - 显示详细的更改信息](#(3.)-v - 显示详细的更改信息)
        • [(4.)-f - 忽略错误信息,强制执行更改](#(4.)-f - 忽略错误信息,强制执行更改)
        • (5.)使用字母来修改权限
      • [2、chown - 修改文件或目录的属主和属组](#2、chown - 修改文件或目录的属主和属组)
        • [(1.)-R - 递归更改给定目录及其子目录中所有文件或目录的所有者](#(1.)-R - 递归更改给定目录及其子目录中所有文件或目录的所有者)
        • [(2.)--reference - 设置文件或目录的所有者和组与参考文件或目录相同](#(2.)--reference - 设置文件或目录的所有者和组与参考文件或目录相同)
        • [(3.)-v - 显示修改后的详细信息](#(3.)-v - 显示修改后的详细信息)
      • [3、chgrp - 修改文件或目录的属组](#3、chgrp - 修改文件或目录的属组)
        • [(1.)-R - 递归更改给定目录及其子目录中所有文件或目录的所属组](#(1.)-R - 递归更改给定目录及其子目录中所有文件或目录的所属组)
        • [(2.)--reference - 设置文件或目录的所属组与参考文件或目录相同](#(2.)--reference - 设置文件或目录的所属组与参考文件或目录相同)
        • [(3.)-v - 显示修改后的详细信息](#(3.)-v - 显示修改后的详细信息)
      • [4、umask - 设置默认的文件和目录权限掩码](#4、umask - 设置默认的文件和目录权限掩码)
        • [(1.)-S - 以字母形式显示当前的umask值](#(1.)-S - 以字母形式显示当前的umask值)
        • [(2.)-p - 以octal数字形式显示当前的umask值](#(2.)-p - 以octal数字形式显示当前的umask值)
        • (3.)设置参数
    • 5、文本管理(vi)

4、权限管理

1、chmod - 修改文件或目录权限

(1.)-R - 递归改变给定目录及其子目录中所有文件或目录的权限
bash 复制代码
[root@centos /]# chmod -R 777 /test/1.txt 
[root@centos /]# ll /test/1.txt 
-rwxrwxrwx 1 root root 46 Mar 25 23:28 /test/1.txt
(2.)-c - 逐一列出更改的文件权限
bash 复制代码
[root@centos /]# chmod -c 644 /test/1.txt 
mode of '/test/1.txt' changed from 0777 (rwxrwxrwx) to 0644 (rw-r--r--)
[root@centos /]# ll /test/1.txt 
-rw-r--r-- 1 root root 46 Mar 25 23:28 /test/1.txt
(3.)-v - 显示详细的更改信息
bash 复制代码
[root@centos /]# chmod -v 554 /test/home/2.txt/
mode of '/test/home/2.txt/' changed from 0644 (rw-r--r--) to 0554 (r-xr-xr--)
(4.)-f - 忽略错误信息,强制执行更改
bash 复制代码
[root@centos /]# chmod -f 554 /test/home/2.txt/
[root@centos /]# ll /test/home/2.txt/
total 0
(5.)使用字母来修改权限
bash 复制代码
[root@centos /]# chmod u+rwx,g+rwx,o+rwx /test/home/2.txt/
[root@centos /]# ll /test/home/2.txt/
total 0
[root@centos /]# cd /test/home/
[root@centos home]# ls
2.txt  3.txt  kali
[root@centos home]# ls -l 
total 12
drwxrwxrwx 2 root root 4096 Apr  2 18:08 2.txt
drwxr-xr-x 2 root root 4096 Apr  2 18:08 3.txt
drwx------ 2 kali root 4096 Mar 27 09:20 kali

2、chown - 修改文件或目录的属主和属组

(1.)-R - 递归更改给定目录及其子目录中所有文件或目录的所有者
bash 复制代码
[root@centos ~]# chown -R test:test /test/home
[root@centos ~]# ls -l /test
total 24
-rwxr-xr-x 1 root root   46 Mar 25 23:28 1.txt
drw-r--r-- 2 root root 4096 Apr  2 18:07 2.txt
drw-r--r-- 2 root root 4096 Apr  2 18:07 3.txt
drwxr-xr-x 5 test test 4096 Apr  2 18:08 home
drwxr-xr-x 3 root root 4096 Mar 25 22:51 kong
drwxr-xr-x 2 root root 4096 Mar 25 22:55 nan
(2.)--reference - 设置文件或目录的所有者和组与参考文件或目录相同
bash 复制代码
[root@centos ~]# chown --reference=/test/home /test/kong
[root@centos ~]# ls -l /test/
total 24
-rwxr-xr-x 1 root root   46 Mar 25 23:28 1.txt
drw-r--r-- 2 root root 4096 Apr  2 18:07 2.txt
drw-r--r-- 2 root root 4096 Apr  2 18:07 3.txt
drwxr-xr-x 5 test test 4096 Apr  2 18:08 home
drwxr-xr-x 3 test test 4096 Mar 25 22:51 kong
drwxr-xr-x 2 root root 4096 Mar 25 22:55 nan
(3.)-v - 显示修改后的详细信息
bash 复制代码
[root@centos ~]# chown -v root:root /test/home
changed ownership of '/test/home' from test:test to root:root
[root@centos ~]# ls -l /test/
total 24
-rwxr-xr-x 1 root root   46 Mar 25 23:28 1.txt
drw-r--r-- 2 root root 4096 Apr  2 18:07 2.txt
drw-r--r-- 2 root root 4096 Apr  2 18:07 3.txt
drwxr-xr-x 5 root root 4096 Apr  2 18:08 home
drwxr-xr-x 3 test test 4096 Mar 25 22:51 kong
drwxr-xr-x 2 root root 4096 Mar 25 22:55 nan

3、chgrp - 修改文件或目录的属组

(1.)-R - 递归更改给定目录及其子目录中所有文件或目录的所属组
bash 复制代码
[root@centos ~]# chgrp -R test /test/home/
[root@centos ~]# ls -l /test/
total 24
-rwxr-xr-x 1 root root   46 Mar 25 23:28 1.txt
drw-r--r-- 2 root root 4096 Apr  2 18:07 2.txt
drw-r--r-- 2 root root 4096 Apr  2 18:07 3.txt
drwxr-xr-x 5 root test 4096 Apr  2 18:08 home
drwxr-xr-x 3 test test 4096 Mar 25 22:51 kong
drwxr-xr-x 2 root root 4096 Mar 25 22:55 nan
(2.)--reference - 设置文件或目录的所属组与参考文件或目录相同
bash 复制代码
[root@centos ~]# chgrp --reference=/test/nan/ /test/home/
[root@centos ~]# ls -l /test/
total 24
-rwxr-xr-x 1 root root   46 Mar 25 23:28 1.txt
drw-r--r-- 2 root root 4096 Apr  2 18:07 2.txt
drw-r--r-- 2 root root 4096 Apr  2 18:07 3.txt
drwxr-xr-x 5 root root 4096 Apr  2 18:08 home
drwxr-xr-x 3 test test 4096 Mar 25 22:51 kong
drwxr-xr-x 2 root root 4096 Mar 25 22:55 nan
(3.)-v - 显示修改后的详细信息
bash 复制代码
[root@centos ~]# chgrp -v test /test/1.txt
changed group of '/test/1.txt' from root to test
[root@centos ~]# ls -l /test/
total 24
-rwxr-xr-x 1 root test   46 Mar 25 23:28 1.txt
drw-r--r-- 2 root root 4096 Apr  2 18:07 2.txt
drw-r--r-- 2 root root 4096 Apr  2 18:07 3.txt
drwxr-xr-x 5 root root 4096 Apr  2 18:08 home
drwxr-xr-x 3 test test 4096 Mar 25 22:51 kong
drwxr-xr-x 2 root root 4096 Mar 25 22:55 nan

4、umask - 设置默认的文件和目录权限掩码

(1.)-S - 以字母形式显示当前的umask值
bash 复制代码
[root@centos ~]# umask -S
u=rwx,g=rx,o=rx
(2.)-p - 以octal数字形式显示当前的umask值
bash 复制代码
[root@centos ~]# umask -p
umask 0022
(3.)设置参数
bash 复制代码
[root@centos ~]# umask 000
[root@centos ~]# umask -p
umask 0000
bash 复制代码
[root@centos ~]# umask 022
[root@centos ~]# umask -S
u=rwx,g=rx,o=rx

5、文本管理(vi)

Vi是一种文本编辑器,常用于UNIX和类UNIX操作系统上。它是一个命令行界面的编辑器,具有许多强大的编辑和操作功能,可以用于编辑和编写各种类型的文本文件。Vi通常由vim编辑器实现,并提供了许多扩展功能和定制选项

vi编辑器有三个模式:普通模式、编辑模式、命令模式;当进入到vi编辑器中的时候,当前模式就是普通模式,按下i后为编辑模式,按下ESC后就是命令模式

1、vi编辑器的特点

命令行界面:vi是一个基于命令行的文本编辑器,可以通过键盘输入命令来进行文本编辑和操作。
高效的编辑功能:vi具有丰富的编辑功能,包括文本插入、删除、剪切、复制、查找替换等功能,通过快捷键和命令实现。
跨平台性:vi可以在多个操作系统上运行,包括UNIX、Linux、Mac OS等。
可定制性:vi可以通过配置文件进行定制,用户可以根据自己的需求进行个性化设置。
强大的扩展功能:vi的改进版本vim具有丰富的插件和扩展功能,可以满足各种复杂的编辑需求。
高效的搜索和替换功能:vi提供了高效的搜索和替换功能,可以快速定位和修改文本内容。

2、vi使用操作

(1.)新建一个文件,打开并编辑
bash 复制代码
# 可以使用touch命令创建文本,也可以直接使用vi先编辑在保存创建这个文本
[root@centos test]# touch vi.txt
[root@centos test]# ls
1.txt  2.txt  3.txt  home  kong  nan  vi.txt
# 进入到文本模式中
[root@centos test]# vi vi.txt
bash 复制代码
# 下面就是进入到文本中的样子(新建的文件夹)

~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
"vi.txt" is a directory
bash 复制代码
# 插入(Insert)模式: 进入插入模式,允许编辑文本内容
# 操作方式:按下"i"键
vi.txt
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
-- INSERT --
bash 复制代码
# 编辑内容,并保存(按键盘右上角ESC,然后再按英文冒号,输入wq,即可退出保存)
vi.txt
vi.txt

vi.txt
vi.txt


vi.txt
vi.txt



vi.txt
vi.txt
vi.txt




vi.txt
vi.txt

~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
:wq
(2.)光标移动快捷键
操作 快捷键
向下移动光标 小键盘下箭头按键
英文字母j按键
空格
向上移动光标 小键盘上箭头按键
英文字母k按键
backspace按键
向左移动光标 小键盘左箭头按键
英文字母h按键
向右移动光标 小键盘右箭头按键
英文字母l按键
移动到下一行行首 回车键
+按键
移动到上一行行首 -按键
移动到最后一行行首 大写英文字母G按键
(3.)文本操作快捷键
操作 快捷键
右插入 a
左插入 i
行尾追加 A
行首插入 I
插入新行 O或o
覆盖文本 R
合并行 J
(4.)文本复制和粘贴快捷键
操作 快捷键
复制行 yy
复制多行 nyy
复制单词 yw
复制多个单词 nyw
复制光标所在到行首 y^
复制光标所在到行尾 y$
粘贴到光标后面位置 p
粘贴到光标前面为止 P
(5.)删除文本快捷键
操作 快捷键
删除当前字符 x
删除多个字符 nx
删除当前行 dd
删除多个行 ndd
撤销上一步操作 u
撤销多个操作 U
(6.)常用vi命令
操作 快捷键
保存文件 :w
退出编辑器 :q
直接退出编辑器 :q!
退出并保存 :wq
光标跳到指定行 :n、:n+、n-
显示、隐藏行号 :set nu、set nonu
快速查找自定字符 /字符

3、常用文本查看命令

(1.)cat
bash 复制代码
# 默认模式下查看所有内容
[root@centos sysconfig]# cat sshd 
# Configuration file for the sshd service.

# The server keys are automatically generated if they are missing.
# To change the automatic creation uncomment and change the appropriate
# line. Accepted key types are: DSA RSA ECDSA ED25519.
# The default is "RSA ECDSA ED25519"

# AUTOCREATE_SERVER_KEYS=""
# AUTOCREATE_SERVER_KEYS="RSA ECDSA ED25519"

# Do not change this option unless you have hardware random
# generator and you REALLY know what you are doing

SSH_USE_STRONG_RNG=0
# SSH_USE_STRONG_RNG=1
bash 复制代码
# 显示非空白行行号的情况下查看内容
[root@centos sysconfig]# cat -b sshd 
     1  # Configuration file for the sshd service.

     2  # The server keys are automatically generated if they are missing.
     3  # To change the automatic creation uncomment and change the appropriate
     4  # line. Accepted key types are: DSA RSA ECDSA ED25519.
     5  # The default is "RSA ECDSA ED25519"

     6  # AUTOCREATE_SERVER_KEYS=""
     7  # AUTOCREATE_SERVER_KEYS="RSA ECDSA ED25519"

     8  # Do not change this option unless you have hardware random
     9  # generator and you REALLY know what you are doing

    10  SSH_USE_STRONG_RNG=0
    11  # SSH_USE_STRONG_RNG=1
(2.)less

此命令查看完后按q会直接退出查看模式,less -N同样可以显示行号查看

(3.)more
bash 复制代码
# 默认查看
[root@centos sysconfig]# more sshd 
# Configuration file for the sshd service.

# The server keys are automatically generated if they are missing.
# To change the automatic creation uncomment and change the appropriate
# line. Accepted key types are: DSA RSA ECDSA ED25519.
# The default is "RSA ECDSA ED25519"

# AUTOCREATE_SERVER_KEYS=""
# AUTOCREATE_SERVER_KEYS="RSA ECDSA ED25519"

# Do not change this option unless you have hardware random
# generator and you REALLY know what you are doing

SSH_USE_STRONG_RNG=0
# SSH_USE_STRONG_RNG=1
(4.)head
bash 复制代码
# 指定查看整个文本的前几行
[root@centos sysconfig]# head -n 5 sshd 
# Configuration file for the sshd service.

# The server keys are automatically generated if they are missing.
# To change the automatic creation uncomment and change the appropriate
# line. Accepted key types are: DSA RSA ECDSA ED25519.
(5.)tail
bash 复制代码
# 指定查看整个文本的后几行
[root@centos sysconfig]# tail -n 5 sshd 
# Do not change this option unless you have hardware random
# generator and you REALLY know what you are doing

SSH_USE_STRONG_RNG=0
# SSH_USE_STRONG_RNG=1
bash 复制代码
# 实时跟踪文件变化查看
[root@centos sysconfig]# tail -f sshd 
# The default is "RSA ECDSA ED25519"

# AUTOCREATE_SERVER_KEYS=""
# AUTOCREATE_SERVER_KEYS="RSA ECDSA ED25519"

# Do not change this option unless you have hardware random
# generator and you REALLY know what you are doing

SSH_USE_STRONG_RNG=0
# SSH_USE_STRONG_RNG=1
相关推荐
数据智能老司机10 分钟前
Linux内核编程——字符设备驱动程序
linux·架构·操作系统
lyx 弈心37 分钟前
I/O 进程 7.2
linux·算法·io
舒克起飞了1 小时前
linux系统编程——Makefile、GDB调试
linux·运维·服务器
背影疾风1 小时前
C++之路:类基础、构造析构、拷贝构造函数
linux·开发语言·c++
deming_su1 小时前
轻松上手:使用Nginx实现高效负载均衡
运维·nginx·负载均衡
m0_694845572 小时前
服务器如何配置防火墙规则开放/关闭端口?
linux·服务器·安全·云计算
降世神童2 小时前
华为云Flexus+DeepSeek征文| 使用华为云CCE容器部署Dify-LLM高可用方案的验证与测试
运维·华为云·aigc
降世神童2 小时前
华为云Flexus+DeepSeek征文| 基于华为云Dify-LLM高可用平台开发运维故障处理智能体
运维·华为云·aigc
阿巴~阿巴~3 小时前
Linux基本命令篇 —— alias命令
linux·服务器·bash
好名字更能让你们记住我4 小时前
Linux多线程(十二)之【生产者消费者模型】
linux·运维·服务器·jvm·windows·centos