Linux系统命令从入门到完全忘记(四)

2,923次阅读
没有评论

共计 3387 个字符,预计需要花费 9 分钟才能阅读完成。

Linux系统命令从入门到完全忘记(四)

系统安全相关命令

chmod

概要:
用于改变文件或目录的访问权限,用它控制文件或目录的访问权限。

语法格式:
chmod [-cfvR] [–help] [–version] mode file

参数:

参数 说明
-c 当发生改变时,报告处理信息
-f 错误信息不输出
-R 处理指定目录以及其子目录下的所有文件
-v 运行时显示详细处理信息

使用示例:

  • 增加文件file所有用户组可执行权限
1
2
3
4
5
[root@ansheng ~]# ll file
-rw-r--r-- 1 root root 0 Apr 25 21:02 file
[root@ansheng ~]# chmod a+x file 
[root@ansheng ~]# ll file        
-rwxr-xr-x 1 root root 0 Apr 25 21:02 file
  • 更改文件ansheng.txt拥有者和所属组拥有读写执行权限,其他用户没有任何权限
1
2
3
4
5
6
[root@ansheng ~]# ll
total 0
-rw-r--r-- 1 root root 0 Apr 25 21:03 ansheng.txt
[root@ansheng ~]# chmod 770 ansheng.txt 
[root@ansheng ~]# ll ansheng.txt 
-rwxrwx--- 1 root root 0 Apr 25 21:03 ansheng.txt

chown

概要:
通过chown改变文件的拥有者和群组。在更改文件的所有者或所属群组时,可以使用用户名称和用户识别码设置。普通用户不能将自己的文件改变成其他的拥有者。其操作权限一般为管理员。

语法格式:
chown [选项]… [所有者][:[组]] 文件…

参数:

参数 选项
-c 显示更改的部分的信息
-f 忽略错误信息
-h 修复符号链接
-R 处理指定目录以及其子目录下的所有文件

使用示例:

  • 更改文件group的拥有者和组
1
2
3
4
5
6
[root@ansheng ~]# touch abc
[root@ansheng ~]# ll abc
-rw-r--r-- 1 root root 0 Apr 25 21:06 abc
[root@ansheng ~]# chown ansheng.ansheng abc
[root@ansheng ~]# ll abc
-rw-r--r-- 1 ansheng ansheng 0 Apr 25 21:06 abc

chattr

概要:
用于改变文件属性

语法格式:
chattr [-RV][-v<版本编号>][+/-/=<属性>][文件或目录…]

参数:

参数 说明
-R 递归处理,将指定目录下的所有文件及子目录一并处理
-v<版本编号> 设置文件或目录版本
-V 显示指令执行过程
+<属性> 开启文件或目录的该项属性
-<属性> 关闭文件或目录的该项属性
=<属性> 指定文件或目录的该项属性

使用示例:

  • 用chattr命令防止系统中某个关键文件被修改:
1
2
3
[root@ansheng ~]# chattr +i /etc/resolv.conf
[root@ansheng ~]# ll /etc/resolv.conf 
-rw-r--r--. 1 root root 53 Apr  9 17:58 /etc/resolv.conf

lsattr

概要:
用chattr执行改变文件或目录的属性,可执行lsattr指令查询其属性。

语法格式:
lsattr [-adlRvV][文件或目录…]

参数:

参数 说明
-a 显示所有文件和目录,包括以”.”为名称开头字符的额外内建,现行目录”.”与上层目录”..”
-d 显示,目录名称,而非其内容
-l 此参数目前没有任何作用
-R 递归处理,将指定目录下的所有文件及子目录一并处理
-v 显示文件或目录版本

使用示例:

  • 查看文件/etc/resolv.conf状态
1
2
[root@ansheng ~]# lsattr /etc/resolv.conf
----i--------e- /etc/resolv.conf

系统相关命令

shutdown

概要:
该命令可以安全关闭或者重新启动系统。你没有看错,shutdown命令不仅可以关闭系统、也可以重启Linux系统。

语法格式:
shutdown [-t sec] [-arkhncfFHP] time [warning-message]

参数:

参数 说明
-a Use /etc/shutdown.allow.
-c 中断关机:当执行”shutdown -h 12:00”指令时,只要按+键就可以中断关机的指令
-f 重新启动时不进行磁盘检测(fsck)
-F 重新启动时进行磁盘检测(fsck)
-h 关闭电源
-k 模拟关机(不是真的关机),只是向登录者发送警告信息出去!
-n 不调用init进程进行关机,而是强行关机
-r 关闭系统然后重新启动,类似于Windows平台restart
-t 延迟关机的时间
-w 仅做测试,并不真的将系统重新开机,只会把重开机的数据写入/var/log目录下的wtmp记录文件

使用示例:

  • 马上关闭Linux系统,其中 now 相当于时间为 0 的状态
1
2
3
[root@ansheng ~]# shutdown -h now
Broadcast message from root (pts/1) (Sat Jan 10 18:51:34 2015):
The system is going down for system halt NOW!
  • 系统2分钟后重新启动,其中+m表示几分钟后关机或开机。
1
2
3
[root@ansheng ~]# shutdown -r +2
Broadcast message from root (pts/2) (Sat Jan 10 19:56:00 2015):
The system is going DOWN for reboot in 2 minutes!
  • 设置系统在那个时间点关机
1
2
3
4
[root@ansheng ~]# shutdown -h 12:30

[root@ansheng ~]# shutdown -h 12:30 &
[1] 4578
  • 向所有登录的用户发出信息
1
2
3
4
[root@ansheng ~]# shutdown -k "now"
Broadcast message from root (pts/2) (Sat Jan 10 20:09:14 2015):
The system is going down to maintenance mode NOW!
Shutdown cancelled.

reboot

概要:
立即重启系统

使用示例:

  • 系统重启
1
2
3
4
5
6
[root@ansheng ~]# reboot 

Broadcast message from root@ansheng
        (/dev/pts/0) at 21:19 ...

The system is going down for reboot NOW!

halt

概要:
立刻关机

使用示例:

  • 关机
1
2
3
4
5
6
[root@ansheng ~]# halt

Broadcast message from root@ansheng
        (/dev/pts/0) at 21:19 ...

The system is going down for halt NOW!

mii-tool

概要:
查看网卡接口的状态

使用示例:

  • 查看eth0是否启用
1
2
[root@ansheng ~]# mii-tool eth0
eth0: negotiated 100baseTx-FD, link ok

eject

概要:
用于退出抽取式设备。

语法格式:
eject [-dfhnqrstv][-a <开关>][-c <光驱编号>][设备]

参数:

参数 说明
-r 退出光盘

使用示例:

  • 弹出光驱
1
[root@ansheng ~]# eject -r /dev/cdrom

chkconfig

概要:

查看设置开机自启动服务

语法格式:

chkconfig [服务名] [–type type][name]

参数:

参数 概述
–list 查看所有服务状态
–add 添加一个服务
–del 删除一个服务
–level 启动级别
–type off/on

使用示例:

  • 关闭iptables在所有模式下的自启动
1
2
3
[root@ansheng ~]# chkconfig iptables off
[root@ansheng ~]# chkconfig --list|grep iptables
iptables        0:off   1:off   2:off   3:off   4:off   5:off   6:off
  • 开启iptables在2模式下启动
1
2
3
[root@ansheng ~]# chkconfig --level 5 iptables on
[root@ansheng ~]# chkconfig --list|grep iptables 
iptables        0:off   1:off   2:off   3:off   4:off   5:on    6:off
正文完
请博主喝杯咖啡吧!
post-qrcode
 
admin
版权声明:本站原创文章,由 admin 2016-07-12发表,共计3387字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(没有评论)
验证码