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

4、权限管理

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

(1.)-R - 递归改变给定目录及其子目录中所有文件或目录的权限
[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 - 逐一列出更改的文件权限
[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 - 显示详细的更改信息
[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 - 忽略错误信息,强制执行更改
[root@centos /]# chmod -f 554 /test/home/2.txt/
[root@centos /]# ll /test/home/2.txt/
total 0
(5.)使用字母来修改权限
[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 - 递归更改给定目录及其子目录中所有文件或目录的所有者
[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 - 设置文件或目录的所有者和组与参考文件或目录相同
[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 - 显示修改后的详细信息
[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 - 递归更改给定目录及其子目录中所有文件或目录的所属组
[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 - 设置文件或目录的所属组与参考文件或目录相同
[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 - 显示修改后的详细信息
[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值
[root@centos ~]# umask -S
u=rwx,g=rx,o=rx
(2.)-p - 以octal数字形式显示当前的umask值
[root@centos ~]# umask -p
umask 0022
(3.)设置参数
[root@centos ~]# umask 000
[root@centos ~]# umask -p
umask 0000
[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.)新建一个文件,打开并编辑
# 可以使用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
# 下面就是进入到文本中的样子(新建的文件夹)

~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
"vi.txt" is a directory
# 插入(Insert)模式: 进入插入模式,允许编辑文本内容
# 操作方式:按下"i"键
vi.txt
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
~                                                                                                                                                                                         
-- INSERT --
# 编辑内容,并保存(按键盘右上角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
# 默认模式下查看所有内容
[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
# 显示非空白行行号的情况下查看内容
[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
# 默认查看
[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
# 指定查看整个文本的前几行
[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
# 指定查看整个文本的后几行
[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
# 实时跟踪文件变化查看
[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

相关推荐

  1. CentOS基础配置2.权限文本管理vi))

    2024-04-07 12:16:02       36 阅读
  2. CentOS基础配置(1.网络管理

    2024-04-07 12:16:02       15 阅读
  3. CentOS 7 文件权限管理详解

    2024-04-07 12:16:02       13 阅读
  4. Linux基础指令()(文件权限等)

    2024-04-07 12:16:02       6 阅读
  5. Linux文件权限管理详解——以CentOS为例

    2024-04-07 12:16:02       14 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-04-07 12:16:02       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-04-07 12:16:02       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-04-07 12:16:02       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-04-07 12:16:02       20 阅读

热门阅读

  1. 4.6

    2024-04-07 12:16:02       14 阅读
  2. JVM常量池

    2024-04-07 12:16:02       18 阅读
  3. MySQL中的事务隔离级别与MVCC及两者间的关联

    2024-04-07 12:16:02       15 阅读
  4. Netty和websocket,如何部署Netty

    2024-04-07 12:16:02       13 阅读
  5. 用FPGA搞图像算法需要具备哪些基础

    2024-04-07 12:16:02       12 阅读