操作系统文件属性


操作系统文件属性

一文件属性——权限

(一)权限含义

权限组成说明

r=read        对应数字4,可读

w=write       对应数字2,可写

x=execute    对应数字1,可执行

(二)权限修改:  chmod 

权限信息  数据信息
属主修改权限: chmod u+/-/=  属主 user
属组修改权限: chmod g+/-/=  属组 group
其他用户修改: chmod o+/-/=  属组 other
同时三种用户都做权限修改:
chmod  nnn(n表示数字)

属主修改权限: chmod u+/-/= 

[root@centos71 ~]# ll  /etc/hosts
-rw-r--r-- 1 root root 158 Dec 16 11:42 /etc/hosts
[root@centos71 ~]# chmod u=x  /etc/hosts
[root@centos71 ~]# ll  /etc/hosts
---xr--r-- 1 root root 158 Dec 16 11:42 /etc/hosts

其他用户修改: chmod o+/-/=

[root@centos71 ~]# su  -   wang
Last login: Thu Dec 12 09:42:17 CST 2019 on pts/0
 ____________
< hahahahaha >
 ------------
                          /   //
           |\___/|      /   //  \
            /0  0  \__  /    //  |      
           /     /  /_/    //   |      
           @_^_@'/   /_   //    |       
           //_^_/     /_ //     |        
        ( //) |        ///      |          
      ( / /) _|_ /   )  //       |           _
    ( // /) '/,_ _ _/  ( ; -.    |    _ _.-~        .-~~~^-.
  (( / / )) ,-{        _      `-.|.-~-.           .~         `.
 (( // / ))  '/      /                 ~-. _ .-~      .-~^-.  
 (( /// ))      `.   {            }                   /        
  (( / ))     .----~-.        -'                 .~           `. ^-.
             ///.----..>                     _ -~             `.  ^-`  ^-_
               ///-._ _ _ _ _ _ _}^ - - - - ~                     ~-- ,.-~
                                                                  /.-~
[wang@centos71 ~]$ whoami 
wang
[wang@centos71 ~]$ cat  /etc/shadow
cat: /etc/shadow: Permission denied
[wang@centos71 ~]$ ll   /etc/shadow
---------- 1 root root 4348 Dec 12 10:30 /etc/shadow
[wang@centos71 ~]$ ll   /etc/shadow
---------- 1 root root 4348 Dec 12 10:30 /etc/shadow
[wang@centos71 ~]$ exit 
logout
[root@centos71 ~]# whoami 
root
[root@centos71 ~]# ll /etc/shadow
---------- 1 root root 4348 Dec 12 10:30 /etc/shadow
[root@centos71 ~]# chmod  o+r  /etc/shadow
[root@centos71 ~]# ll /etc/shadow
-------r-- 1 root root 4348 Dec 12 10:30 /etc/shadow
[root@centos71 ~]# su -  wang
Last login: Mon Dec 16 16:44:49 CST 2019 on pts/0
 ____________
< hahahahaha >
 ------------
     
      
       ("`-'  '-/") .___..--' ' "`-._
         ` *_ *  )    `-.   (      ) .`-.__. `)
         (_Y_.) ' ._   )   `._` ;  `` -. .-'
      _.. `--'_..-_/   /--' _ .' ,4
   ( i l ),-''  ( l i),'  ( ( ! .-'    
[wang@centos71 ~]$ ll   /etc/shadow
-------r-- 1 root root 4348 Dec 12 10:30 /etc/shadow

二文件属性——用户信息

管理员   root    uid=0       拥有所有权利用户

[root@centos71 ~]# id  root
uid=0(root) gid=0(root) groups=0(root)


虚拟用户 nobody  uid=1-999 

管理系统进程/管理数据,不能登录系统/没有家目录

[root@centos71 ~]# cat  /etc/passwd  | grep  "nobody"
nobody:x:99:99:Nobody:/:/sbin/nologin
[root@centos71 ~]# id  nobody
uid=99(nobody) gid=99(nobody) groups=99(nobody)


普通用户  uid=1000+  

登录系统/简单管理工作     

用户和用户组关系


1vs1关系:1个用户只属于1个组
1vs多关系:1个用户属于多个组
多vs 1关系:多个用户属于1个组
多vs多关系:多个用于属于多个组

三文件属性——时间信息

atime:  access time --- 访问时间

mtime:  modify time --- 修改时间
ctime:  change time --- 文件属性改变时间

注意文件属性改变才会改变改变时间

[root@centos71 ~]# touch   /test/aa.txt
[root@centos71 ~]# stat  /test/aa.txt
  File: ‘/test/aa.txt’
  Size: 0             Blocks: 0          IO Block: 4096   regular empty file
Device: 803h/2051d    Inode: 68253400    Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2019-12-16 17:14:48.359593701 +0800
Modify: 2019-12-16 17:14:48.359593701 +0800
Change: 2019-12-16 17:14:48.359593701 +0800
 Birth: -
[root@centos71 ~]# cat /test/aa.txt
[root@centos71 ~]# stat  /test/aa.txt
  File: ‘/test/aa.txt’
  Size: 0             Blocks: 0          IO Block: 4096   regular empty file
Device: 803h/2051d    Inode: 68253400    Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2019-12-16 17:15:02.039774388 +0800
Modify: 2019-12-16 17:14:48.359593701 +0800
Change: 2019-12-16 17:14:48.359593701 +0800
 Birth: -

 影响文件大小属性,修改了文件大小,使改变时间修改了

[root@centos71 ~]# echo   hahahaha  >> /test/aa.txt
[root@centos71 ~]# stat  /test/aa.txt
  File: ‘/test/aa.txt’
  Size: 9             Blocks: 8          IO Block: 4096   regular file
Device: 803h/2051d    Inode: 68253400    Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2019-12-16 17:15:02.039774388 +0800
Modify: 2019-12-16 17:16:31.226952386 +0800
Change: 2019-12-16 17:16:31.226952386 +0800
 Birth: -
[root@centos71 ~]# chmod   700  /test/aa.txt
[root@centos71 ~]# stat  /test/aa.txt
  File: ‘/test/aa.txt’
  Size: 9             Blocks: 8          IO Block: 4096   regular file
Device: 803h/2051d    Inode: 68253400    Links: 1
Access: (0700/-rwx------)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2019-12-16 17:15:02.039774388 +0800
Modify: 2019-12-16 17:16:31.226952386 +0800
Change: 2019-12-16 17:18:30.155523229 +0800
 Birth: -

%可以理解为调用参数的作用,和$调用变量类似

[root@centos71 ~]# date "+%F"
2019-12-16
[root@centos71 ~]# date "+%T"
17:23:14
[root@centos71 ~]# date "+%YY"
2019Y
[root@centos71 ~]# date "+%Y"
2019
[root@centos71 ~]# date "+%Y-%m-%d"
2019-12-16
[root@centos71 ~]# date "+%Y-%m-%d %H-%M-%S "
2019-12-16 17-24-17 
[root@centos71 ~]# date
Mon Dec 16 17:24:20 CST 2019
[root@centos71 ~]# date  --help  | grep "%F"
  %F   full date; same as %Y-%m-%d
[root@centos71 ~]# date  --help  | grep "%T"
  %T   time; same as %H:%M:%S

指定查看未来或过去时间



显示过去特定时间

[root@centos71 ~]# date   -d   "-88 day"
Fri Sep 20 17:35:50 CST 2019
[root@centos71 ~]# date   -d   "-88 days"
Fri Sep 20 17:35:55 CST 2019

显示未来特定时间

[root@centos71 ~]# date   -d   "66 days"
Fri Feb 21 17:36:40 CST 2020
[root@centos71 ~]# date   -d   "+66 days"
Fri Feb 21 17:36:44 CST 2020

四文件属性——索引信息

(一)inode

数据文件索引信息,类似目录

作用说明:存储文件数据属性信息文件数据指针信息

诞生过程:格式化时创建文件系统,创建inode

(二)block

真正存储数据区域

作用说明:存储文件真正数据内容

诞生过程:格式化时创建文件系统,创建block

文件属性信息存放于inode,文件数据存放于block

用户读取文件先查看inode,通过指针指向block

买的硬盘是无法存储数据的

[root@centos71 ~]# df -i
Filesystem       Inodes IUsed    IFree IUse% Mounted on
/dev/sda3      20971520 87649 20883871    1% /
devtmpfs         121766   388   121378    1% /dev
tmpfs            124490     1   124489    1% /dev/shm
tmpfs            124490   741   123749    1% /run
tmpfs            124490    16   124474    1% /sys/fs/cgroup
/dev/sda1        102400   326   102074    1% /boot
tmpfs            124490     1   124489    1% /run/user/0

空文件只占用inode,因为没数据

[root@centos71 ~]# df -i
Filesystem       Inodes IUsed    IFree IUse% Mounted on
/dev/sda3      20971520 87649 20883871    1% /
devtmpfs         121766   388   121378    1% /dev
tmpfs            124490     1   124489    1% /dev/shm
tmpfs            124490   741   123749    1% /run
tmpfs            124490    16   124474    1% /sys/fs/cgroup
/dev/sda1        102400   326   102074    1% /boot
tmpfs            124490     1   124489    1% /run/user/0
[root@centos71 ~]# touch   bb.txt
[root@centos71 ~]# df -i
Filesystem       Inodes IUsed    IFree IUse% Mounted on
/dev/sda3      20971520 87650 20883870    1% /
devtmpfs         121766   388   121378    1% /dev
tmpfs            124490     1   124489    1% /dev/shm
tmpfs            124490   741   123749    1% /run
tmpfs            124490    16   124474    1% /sys/fs/cgroup
/dev/sda1        102400   326   102074    1% /boot
tmpfs            124490     1   124489    1% /run/user/0

写入数据,block变化了,inode不变

[root@centos71 ~]# echo   hahahahahahaha >>   bb.txt
[root@centos71 ~]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda3       41922560 4584200  37338360  11% /
devtmpfs          487064       0    487064   0% /dev
tmpfs             497960       0    497960   0% /dev/shm
tmpfs             497960    7892    490068   2% /run
tmpfs             497960       0    497960   0% /sys/fs/cgroup
/dev/sda1         201380  107080     94300  54% /boot
tmpfs              99596       0     99596   0% /run/user/0
[root@centos71 ~]# df -i
Filesystem       Inodes IUsed    IFree IUse% Mounted on
/dev/sda3      20971520 87650 20883870    1% /
devtmpfs         121766   388   121378    1% /dev
tmpfs            124490     1   124489    1% /dev/shm
tmpfs            124490   741   123749    1% /run
tmpfs            124490    16   124474    1% /sys/fs/cgroup
/dev/sda1        102400   326   102074    1% /boot
tmpfs            124490     1   124489    1% /run/user/0

问题一:磁盘空间不够的处理思路

磁盘inode是否够用

磁盘block是否够用

问题二:block块单位是大点好还是小点好?


一个数据会占用一个inode,占用多个block

比如10K文件会占用3个block

(blcok单位默认为4k)

注意磁盘IO(input output)输入输出的次数,决定磁盘性能

10M消耗block少,IO次数少硬盘性能没有影响
10G消耗block多,IO次数多硬盘性能会有下降

如果拷贝10G时再拷贝10M文件,拷贝都很慢,说明性能下降,磁盘变卡就要看磁盘IO了

存储数据大文件数据比如视频图片/音频,block设置更大些,IO消耗可以减少。

注意视频图片/音频文件已经被压缩过了,不能再压缩

存储数据小文件数据文档代码,block更小些节省磁盘空间。

文件没有权限读取和数据读取原理(inode block)有关

创建文件系统时格式化,修改block大小

[root@centos71 ~]# stat  /etc/hosts
  File: ‘/etc/hosts’
  Size: 158           Blocks: 8          IO Block: 4096   regular file
Device: 803h/2051d    Inode: 35530425    Links: 1
Access: (0144/---xr--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2019-12-16 17:36:51.997076617 +0800
Modify: 2019-12-16 11:42:41.175934855 +0800
Change: 2019-12-16 16:33:11.122171607 +0800
 Birth: -

五文件属性——链接信息

(一)硬链接

硬链接:inode号码相同的文件数据称为硬链接

特点:硬链接源文件被删除了不会影响链接文件,不能给目录创建硬链接

应用:利用硬链接对大文件进行备份防止误删除,比cp节省空间

cp主要用于小文件,防止误删除/防止误修改dG

创建硬链接

[root@centos71 test]#  find   /etc/  -name   "m*.conf"
/etc/mailx_event.conf
/etc/mantisbt.conf
/etc/mantisbt_format.conf
/etc/mantisbt_format_analyzer_libreport.conf
/etc/mantisbt_formatdup.conf
/etc/mantisbt_formatdup_analyzer_libreport.conf
/etc/mailx.conf
/etc/mariadb-x86_64.conf
/etc/man_db.conf
/etc/mke2fs.conf
[root@centos71 test]# find   /etc/  -name   "m*.conf"  |  xargs  -i  cp  {}  /test
[root@centos71 test]# ls
mailx.conf        mantisbt_format_analyzer_libreport.conf     mariadb-x86_64.conf
mailx_event.conf  mantisbt_format.conf                        mke2fs.conf
man_db.conf       mantisbt_formatdup_analyzer_libreport.conf
mantisbt.conf     mantisbt_formatdup.conf
[root@centos71 test]# ll
total 44
-rw-r--r-- 1 root root  331 Dec 17 18:15 mailx.conf
-rw-r--r-- 1 root root  203 Dec 17 18:15 mailx_event.conf
-rw-r--r-- 1 root root 5171 Dec 17 18:15 man_db.conf
-rw-r--r-- 1 root root  221 Dec 17 18:15 mantisbt.conf
-rw-r--r-- 1 root root 2070 Dec 17 18:15 mantisbt_format_analyzer_libreport.conf
-rw-r--r-- 1 root root 2107 Dec 17 18:15 mantisbt_format.conf
-rw-r--r-- 1 root root 2058 Dec 17 18:15 mantisbt_formatdup_analyzer_libreport.conf
-rw-r--r-- 1 root root 2458 Dec 17 18:15 mantisbt_formatdup.conf
-rw-r--r-- 1 root root   17 Dec 17 18:15 mariadb-x86_64.conf
-rw-r--r-- 1 root root  936 Dec 17 18:15 mke2fs.conf
[root@centos71 test]# ln   mailx.conf   mailx.conf_hard_link
[root@centos71 test]# ll
total 48
-rw-r--r-- 2 root root  331 Dec 17 18:15 mailx.conf
-rw-r--r-- 2 root root  331 Dec 17 18:15 mailx.conf_hard_link
-rw-r--r-- 1 root root  203 Dec 17 18:15 mailx_event.conf
-rw-r--r-- 1 root root 5171 Dec 17 18:15 man_db.conf
-rw-r--r-- 1 root root  221 Dec 17 18:15 mantisbt.conf
-rw-r--r-- 1 root root 2070 Dec 17 18:15 mantisbt_format_analyzer_libreport.conf
-rw-r--r-- 1 root root 2107 Dec 17 18:15 mantisbt_format.conf
-rw-r--r-- 1 root root 2058 Dec 17 18:15 mantisbt_formatdup_analyzer_libreport.conf
-rw-r--r-- 1 root root 2458 Dec 17 18:15 mantisbt_formatdup.conf
-rw-r--r-- 1 root root   17 Dec 17 18:15 mariadb-x86_64.conf
-rw-r--r-- 1 root root  936 Dec 17 18:15 mke2fs.conf
[root@centos71 test]# ll   -i
total 48
68253419 -rw-r--r-- 2 root root  331 Dec 17 18:15 mailx.conf
68253419 -rw-r--r-- 2 root root  331 Dec 17 18:15 mailx.conf_hard_link
68253400 -rw-r--r-- 1 root root  203 Dec 17 18:15 mailx_event.conf
68253421 -rw-r--r-- 1 root root 5171 Dec 17 18:15 man_db.conf
68253411 -rw-r--r-- 1 root root  221 Dec 17 18:15 mantisbt.conf
68253413 -rw-r--r-- 1 root root 2070 Dec 17 18:15 mantisbt_format_analyzer_libreport.conf
68253412 -rw-r--r-- 1 root root 2107 Dec 17 18:15 mantisbt_format.conf
68253418 -rw-r--r-- 1 root root 2058 Dec 17 18:15 mantisbt_formatdup_analyzer_libreport.conf
68253415 -rw-r--r-- 1 root root 2458 Dec 17 18:15 mantisbt_formatdup.conf
68253420 -rw-r--r-- 1 root root   17 Dec 17 18:15 mariadb-x86_64.conf
68253422 -rw-r--r-- 1 root root  936 Dec 17 18:15 mke2fs.conf

把文件删除了,可以通过硬链接查看

[root@centos71 test]# cat  mailx.conf
# Uncomment and specify these parameters if you want to use
# reporter-mailx tool outside of libreport's GUI
# (i.e. from command line or in custom scripts)
# and you don't want to specify parameters in every tool invocation.
#
# String parameters:
# Subject=
# EmailFrom=
# EmailTo=
#
# Boolean parameter:
# SendBinaryData=yes/no
[root@centos71 test]# rm -f  mailx.conf
[root@centos71 test]# ls   mailx.conf
mailx.conf_hard_link 
[root@centos71 test]# cat  mailx.conf_hard_link 
# Uncomment and specify these parameters if you want to use
# reporter-mailx tool outside of libreport's GUI
# (i.e. from command line or in custom scripts)
# and you don't want to specify parameters in every tool invocation.
#
# String parameters:
# Subject=
# EmailFrom=
# EmailTo=
#
# Boolean parameter:
# SendBinaryData=yes/no

(二)软链接

软链接:一个源文件快捷方式

特点:软链接源文件被删除会影响链接文件,能给目录创建硬链接

作用:减少开发人员工作量

创建软链接

[root@centos71 test]# ln   -s    mailx.conf   mailx.conf_soft_link
[root@centos71 test]# ll  -i  mailx.conf*
68253419 -rw-r--r-- 2 root root 331 Dec 17 18:15 mailx.conf
68253419 -rw-r--r-- 2 root root 331 Dec 17 18:15 mailx.conf_hard_link
68253423 lrwxrwxrwx 1 root root  10 Dec 17 18:53 mailx.conf_soft_link -> mailx.conf

把文件删除了,可以通过硬链接查看

[root@centos71 test]# cat  mailx.conf
# Uncomment and specify these parameters if you want to use
# reporter-mailx tool outside of libreport's GUI
# (i.e. from command line or in custom scripts)
# and you don't want to specify parameters in every tool invocation.
#
# String parameters:
# Subject=
# EmailFrom=
# EmailTo=
#
# Boolean parameter:
# SendBinaryData=yes/no
[root@centos71 test]# rm -f  mailx.conf
[root@centos71 test]# ls   mailx.conf
mailx.conf_hard_link   mailx.conf_soft_link
[root@centos71 test]# cat  mailx.conf_hard_link 
# Uncomment and specify these parameters if you want to use
# reporter-mailx tool outside of libreport's GUI
# (i.e. from command line or in custom scripts)
# and you don't want to specify parameters in every tool invocation.
#
# String parameters:
# Subject=
# EmailFrom=
# EmailTo=
#
# Boolean parameter:
# SendBinaryData=yes/no

把源文件删除了,无法通过软链接查看源文件内容

[root@centos71 test]# ls   mailx.conf*  -l
-rw-r--r-- 1 root root 331 Dec 17 18:15 mailx.conf_hard_link
lrwxrwxrwx 1 root root  10 Dec 17 18:53 mailx.conf_soft_link -> mailx.conf
[root@centos71 test]# cat    mailx.conf_soft_link
cat: mailx.conf_soft_link: No such file or directory

通过软链接快速访问文件,和别名功能类似

[root@centos71 ~]# ln  -s  /etc/sysconfig/network-scripts/ifcfg-eth0   /ifcfg-eth0
[root@centos71 ~]# ll  /etc/sysconfig/network-scripts/ifcfg-eth0   /ifcfg-eth0
-rw-r--r--. 1 root root 356 Nov 27 10:42 /etc/sysconfig/network-scripts/ifcfg-eth0
lrwxrwxrwx  1 root root  41 Dec 17 19:02 /ifcfg-eth0 -> /etc/sysconfig/network-scripts/ifcfg-eth0
[root@centos71 ~]# cat  /ifcfg-eth0 
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=eth0
UUID=9d9e2656-f3ac-4f75-8722-3136d239985d
DEVICE=eth0
ONBOOT=yes
IPADDR=10.0.0.200
PREFIX=24
GATEWAY=10.0.0.254
IPV6_PRIVACY=no
DNS1=223.5.5.5

消磁就是把之前所有的block清除,这样就无法进行数据恢复了,可以使用微波炉

现在开发都是调用,调用库或者模块,比如Python、Java

C语言开发是针对底层硬件的,无法调用库,难度很大

对于应用程序的版本升级,很多文件可能要修改了,但是使用软链接就不需要了

因为开发修改就要编译,很麻烦的

原文地址:https://www.cnblogs.com/wang618/p/12056272.html