一个小白学习linux的艰辛路程day15
day15学习笔记
一、linux权限管理篇补充
1.umask的理解
umask 命令用来限制新文件权限的掩码,也称之为遮罩码
[root@linux tmp]# ll -d 王中王
drwxr-xr-x. 2 root root 6 Mar 18 13:54 王中王 文件夹权限为755
[YL@linux tmp]$ ll -d 苹果
drwxrwxr-x. 2 YL YL 6 Mar 18 13:54 苹果 文件夹权限是775
linux中默认文件夹的最高权限为777
[root@linux tmp]# ll shouyue.txt
-rw-r--r--. 1 root root 0 Mar 18 13:58 shouyue.txt文件权限为644
[YL@linux tmp]$ ll xuance.log
-rw-rw-r--. 1 YL YL 0 Mar 18 13:59 xuance.log 文件权限为664
linux中默认创建文件的最高权限为666
通过两个用户创建的文件夹和文件我们可以发现 ,文件或文件夹的最高权限都一样,为什么双方创建的文件夹和文件权限却完全不同?这就是我们的umask值
防止文件、文件夹创建的时候,权限过大,当新文件被创建时,其最初的权限由文件创建掩码决定。这就是umask的作用
[root@linux tmp]# umask
0022
[YL@linux tmp]$ umask
0002
通过查找我们发现root用户的umask值为022,普通用户的值为002,用户每次注册进入系统时,umask命令都被执行,并自动设置掩码改变默认值(最高权限减去用户的umask值就是你所创建的文件或文件夹的权限)
2.umask注意事项
很明显,umask的值是可以进行修改的。
1.临时修改
[YL@linux tmp]$ umask 202
[YL@linux tmp]$ mkdir 橘子
[YL@linux tmp]$ ll -d 橘子
dr-xrwxr-x. 2 YL YL 6 Mar 18 14:09 橘子
此时我们将用户的umask值修改为202,发现新创建的文件夹的权限为575(777-202=575)。
当我们重新登录时又会发现umask值又变成了其默认值
2.永久修改
[root@linux tmp]# vim .bashrc
编辑用户环境变量文件,将修改的umask值编辑进文件,保存后重新登录,umask值就永久修改完成了
3.文件特殊属性
chattr
前期我们学习chmod命令用来修改文件的r,w,x权限,而chattr命令用来修改文件的扩展属性
a 文件锁定,向文件追加数据,但不能删除
i 文件不能被删除、改名、修改内容,文件锁定
+号增加参数
-号移除参数
=号指定参数
[root@linux tmp]# chattr +a shouyue.txt
[root@linux tmp]# echo '我是百里守约' >> shouyue.txt
[root@linux tmp]# rm -rf shouyue.txt
rm: cannot remove ‘shouyue.txt’: Operation not permitted
我们将shouyue.txt添加了一个a的扩展属性,发现只能向文件追加内容,但不能删除,哪怕是root用户也没有这个权限,这就是a参数
[root@linux tmp]# chattr -a shouyue.txt
[root@linux tmp]# chattr +i shouyue.txt
[root@linux tmp]# echo '我是百里守约' >> shouyue.txt
-bash: shouyue.txt: Permission denied
我们将a参数移除,给文件添加一个i;参数,发现这时候连追加内容都没有了权限,这就是i参数的作用
4.查看文件的特殊属性
lsattr
-R递归的列出目录以及其下内容的属性
-a列出目录的所有文件,包括隐藏文件的属性
-d列出目录本身的属性
[root@linux tmp]# ll shouyue.txt
-rw-r--r--. 1 root root 19 Mar 18 14:24 shouyue.txt
[root@linux tmp]# lsattr shouyue.txt
----i----------- shouyue.txt
使用ll命令只能看到文件的r,w,x权限,使用lsattr命令,可以看的文件的特殊属性i
查看文件的具体类型
file
file +文件名
二、服务管理篇(一)
1.服务
服务是指系统上安装的各种软件提供的服务,也就是一些特定的进程
abled
自有服务就是系统开机后就自动运行的一些进程,一旦客户发出请求,这些进程就自动为他们提供服务
2.服务管理命令
systemctl,用于控制 systemd 系统和管理服务
systemctl start 服务名称 启动指定的服务
systemctl stop 服务名称 关闭指定的服务
systemctl restart 服务名称 重启指定的服务
systemctl reload 服务名称 重新加载指定的服务
systemctl enable 服务名称 系统开机是自动启动指定的服务
systemctl disable 服务名称 开机时不自动启动指定的服务
systemctl status 服务名称 查看指定的服务当前运行状态
is-enabled 查看服务是否设置了开机自启
systemctl list-units --type service --all 列出系统中所有的服务级状态
使用该命令配合grep命令能搜索出服务的完整名称,利用完整名称才能去进行管理
[root@linux ~]# systemctl list-units --type service --all
UNIT LOAD ACTIVE SUB DESCRIPTION
abrt-ccpp.service loaded active exited Install ABRT coredump hook
abrt-oops.service loaded active running ABRT kernel log watcher
abrt-vmcore.service loaded inactive dead Harvest vmcores for ABRT
abrt-xorg.service loaded active running ABRT Xorg log watcher
abrtd.service loaded active running ABRT Automated Bug Reporting Tool
accounts-daemon.service loaded active running Accounts Service
alsa-restore.service loaded inactive dead Save/Restore Sound Card State
alsa-state.service loaded active running Manage Sound Card State (restore and store)
● apparmor.service not-found inactive dead apparmor.service
atd.service loaded active running Job spooling tools
auditd.service loaded active running Security Auditing
空格翻页、回车下一行、q退出
[root@linux ~]# systemctl list-units --type service
UNIT LOAD ACTIVE SUB DESCRIPTION
abrt-oops.service loaded active running ABRT kernel log watcher
abrt-xorg.service loaded active running ABRT Xorg log watcher
abrtd.service loaded active running ABRT Automated Bug Reporting Tool
accounts-daemon.service loaded active running Accounts Service
alsa-state.service loaded active running Manage Sound Card State (restore and store)
atd.service loaded active running Job spooling tools
auditd.service loaded active running Security Auditing Service
avahi-daemon.service loaded active running Avahi mDNS/DNS-SD Stack
blk-availability.service loaded active exited Availability of block devices
bluetooth.service loaded active running Bluetooth service
chronyd.service loaded active running NTP client/server
colord.service loaded active running Manage, Install and Generate Color Profiles
只列出积极运行中的服务
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 字符编码:从基础到乱码解决
· 提示词工程——AI应用必不可少的技术