Operation and maintenance
  • 目录
  • linux 历史
    • Linux网卡配置
    • linux互相登陆
  • 文件目录管理
    • linux目录结构
    • 文件的基本信息
    • linux别名alias
    • 环境变量
    • linux终端相关快捷键
    • linux文件和目录添加删除
    • linux文件查看命令
    • linux文件目录权限
    • linux文件特殊权限
    • 链接文件
    • linux下文件查找
    • linux和window文件互传
    • linux文件压缩和打包
    • vim工具集
  • 用户和组管理
    • 用户组和用户管理
    • 修改组和用户
    • 用户切换
    • 禁止root远程登陆
  • linux磁盘管理
    • 磁盘分区
    • 格式化磁盘
    • 分区挂载
    • 手动添加swap分区
    • lvm基础
  • linux软件安装和卸载
    • rpm工具
    • yum工具
    • 源码安装包
  • 日常运维
    • 监控磁盘IO
    • 查看网络状态
    • linux抓包
    • linux网络相关
    • Linux防火墙-netfilter
    • linux任务计划
    • linux系统服务管理
    • linux同步工具rsync
    • linux系统日志和screen
  • LAMP架构
    • 安装mysql
    • 免编译安装mariadb
    • 安装apache
    • 安装php5
    • 安装php7
    • apache 配置虚拟主机
    • apache 用户认证
    • apache 域名跳转
    • apache 访问日志
    • apache 不记录文件日志
    • apache 配置静态元素过期时间
    • apache 配置防盗链
    • apache 访问控制
    • apache 禁止解析php文件
    • apache 禁止user_agent
    • php 配置文件
    • php 动态扩展模块安装
  • LNMP架构
    • 安装mariadb
    • 安装php
    • 安装nginx
    • nginx 默认虚拟主机
    • nginx 用户认证
    • nginx 域名重定向
    • nginx 访问日志
    • nginx 日志切割
    • nginx不记录指定文件类型日志
    • nginx 静态文件和过期时间
    • nginx 防盗链
    • nginx 访问控制
    • nginx 解析php
    • nginx 代理
    • nginx 负载均衡
    • nginx 支持https
  • MySQL集合
    • 更改root密码
    • mysql 常用操作
    • mysql 常用sql
    • mysql 数据备份
    • mysql 主从配置
  • linux常用服务
    • nfs 服务搭建
    • CentOS7 搭建snmp服务
    • ftp 服务搭建
    • samba 服务搭建
    • Squid 服务搭建
    • Tomcat 服务搭建
    • resin 搭建
    • dns 服务搭建
    • iscsi 服务搭建
  • linux开发语言环境
    • python 开发环境
    • golang 开发环境
  • linux集群架构
    • linux 高可用
    • linux 负载均衡
  • linux监控平台
    • zabbix 监控平台(上)
  • shell集合
  • NoSql
    • memcached (上)
    • memcached(下)
    • redis(上)
    • redis(中)
    • redis(下)
    • mongodb(上)
    • mongodb(中)
    • mongodb(下)
  • 代码管理工具
    • 代码管理工具 svn
    • 代码管理工具 git
    • 搭建git私有仓库
    • 安装配置gitlab
  • docker 入门
    • docker 安装
    • docker 镜像管理
    • docker 容器管理
    • docker 仓库管理
    • docker 共享目录
    • docker 数据备份和恢复
    • docker 网络管理
    • docker 使用dockerfile
    • docker compose
  • 自动化运维
    • saltstack 安装
    • saltstack 配置认证
    • saltstack 远程执行命令
    • saltstack grains
    • saltstack pillar
    • saltstack 实战:安装配置httpd
    • saltstack 实战:配置管理文件
    • saltstack 实战:配置管理远程命令
    • saltstack 实战:配置管理任务计划
    • saltstack salt-ssh工具
    • ansible 安装
    • ansible 远程命令
    • ansible 远程目录拷贝
    • ansible 任务计划
    • ansible 远程rpm/服务管理
    • ansible playbook 详解
    • ansible playbook 实战:安装nginx
  • linux虚拟化
    • KVM介绍
    • 安装KVM
    • 虚拟机管理
    • 克隆虚拟机
    • 快照管理
    • 磁盘扩容
    • 调整虚拟机配置
    • 迁移虚拟机
  • 错误排查
    • linux启动挂在不上sysroot问题
由 GitBook 提供支持
在本页
  • chmod 命令
  • umask 命令
  • chown 命令
  • history 命令

这有帮助吗?

  1. 文件目录管理

linux文件目录权限

[root@localhost ~]# ls -l
总用量 8
-rw-r--r--  1 root root   12 7月  31 21:38 1.txt
-rw-r--r--  1 root root    0 7月  30 22:34 22.txt
-rw-r--r--  1 root root    0 7月  30 22:31 2.txt
-rw-------. 1 root root 1430 7月  12 10:41 anaconda-ks.cfg

使用ls -l 查看目录下的文件时我们会看到文件中-rw-r--r-- 这样的文件属性。分为五段为13331

  • 第一段只有一个字符 - ,表示文件的类型

  • 第二段三个字符表示文件属主的权限:r:可读 w:可写 x:可执行,也可用数字表示为 r=4,w=2,x=1,所以像文件1.txt的权限数字表示为644,root用户对该文件有读写权限。

  • 第三段三个字符表示文件属组的权限,所以root组对该文件有读权限。

  • 第四段三个字符表示其他用户的权限,所以其他用户对该文件有读权限。

  • 第五段的 . 字符表示文件创建时是否开启selinux(linux安全系统),开启才有 . 。

而后面的root和root分别表示文件的所属主和所属组。

chmod 命令

chmod命令:

介绍:change mode 的缩写,修改文件的权限

格式:chmod [option] number file

用法:

  • chmod 666 dir|file :数字表示,修改文件权限

  • chmod u+x,g+w,o-r dir|file

    :加减表示

  • chmod u=rwx,g=rw,o=r

    :赋值表示

  • -R 令目录及其目录下的文件都继承

u为用户 g为组 o为其他人 a为所有u+g+o

r=4 w=2 x=1 rwx=7 rw-=6 r-x=5

[root@localhost ~]# ls -l 1.txt
-rwxrwxrwx 1 root root 12 7月  31 21:38 1.txt
[root@localhost ~]# chmod 600 1.txt
[root@localhost ~]# ls -l 1.txt
-rw------- 1 root root 12 7月  31 21:38 1.txt
[root@localhost ~]# chmod  a+x,u+w,g+r,o+w 1.txt 
[root@localhost ~]# ls -l 1.txt
-rwxr-x-wx 1 root root 12 7月  31 21:38 1.txt
[root@localhost ~]# chmod u=r,g=rwx,o=wx 1.txt
[root@localhost ~]# ls -l 1.txt
-r--rwx-wx 1 root root 12 7月  31 21:38 1.txt

umask 命令

umask 命令:

介绍:查看和更改默认权限 , 默认0022(一般用后3位) root 有最高权限不受此影响 ,所以目录为rwxrwxrwx - ----w--w- = rwxr-xr-x(有x权限才能进入) 文件为rw-rw-rw- - ----w-w- = rw-r--r--

格式:umask number

用法:

  • umask :直接使用查看文件默认权限

  • umask number :修改文件权限

[root@localhost ~]# touch 1.txt
[root@localhost ~]# ls -l
总用量 4
-rw-r--r--  1 root root    0 7月  31 22:25 1.txt
-rw-------. 1 root root 1430 7月  12 10:41 anaconda-ks.cfg
[root@localhost ~]# umask 0111
[root@localhost ~]# touch 2.txt
[root@localhost ~]# ls -l
总用量 4
-rw-r--r--  1 root root    0 7月  31 22:25 1.txt
-rw-rw-rw-  1 root root    0 7月  31 22:26 2.txt
-rw-------. 1 root root 1430 7月  12 10:41 anaconda-ks.cfg
[root@localhost ~]# umask 0222
[root@localhost ~]# touch 3.txt
[root@localhost ~]# ls -l
总用量 4
-rw-r--r--  1 root root    0 7月  31 22:25 1.txt
-rw-rw-rw-  1 root root    0 7月  31 22:26 2.txt
-r--r--r--  1 root root    0 7月  31 22:26 3.txt
-rw-------. 1 root root 1430 7月  12 10:41 anaconda-ks.cfg

chown 命令

chown 命令:

介绍:change owner 更改属主属组

格式:chown [user].[user] [option] file|dir

用法:

  • chown root.root dir|file 修改目录或文件为root用户root组

  • -R :令目录及其下的文件继承权限

  • chown .root 只改属组 同 chgrp root

  • chown root. 只改属主

命令 . 也可被换 : 替换。

[root@localhost ~]# ls -l
总用量 4
-rw-------. 1 ping ping 1430 7月  12 10:41 anaconda-ks.cfg
[root@localhost ~]# chown root: anaconda-ks.cfg 
[root@localhost ~]# ls -l
总用量 4
-rw-------. 1 root root 1430 7月  12 10:41 anaconda-ks.cfg
[root@localhost ~]# chown ping:root anaconda-ks.cfg 
[root@localhost ~]# ls -l
总用量 4
-rw-------. 1 ping root 1430 7月  12 10:41 anaconda-ks.cfg
[root@localhost ~]# chown :ping anaconda-ks.cfg 
[root@localhost ~]# ls -l
总用量 4
-rw-------. 1 ping ping 1430 7月  12 10:41 anaconda-ks.cfg
[root@localhost ~]# chown -R root:root ./
[root@localhost ~]# ls -l
总用量 4
-rw-------. 1 root root 1430 7月  12 10:41 anaconda-ks.cfg

history 命令

history 命令:

介绍:查看命令历史

用法:直接使用

!命令标号 : 可直接执行编号的命令 。!ch : 执行最近ch开头的命令

[root@localhost ~]# history | tail -2
  250  history 
  251  history | tail -2
[root@localhost ~]# history | tail -4
  249  ls -l
  250  history 
  251  history | tail -2
  252  history | tail -4
[root@localhost ~]# !249
ls -l
总用量 4
-rw-------. 1 root root 1430 7月  12 10:41 anaconda-ks.cfg
上一页linux文件查看命令下一页linux文件特殊权限

最后更新于4年前

这有帮助吗?