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
  • 16
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

十一的学习笔记

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值