Linux文件系统

su #切换到root用户
sudo admin #切换到admin用户
sudo password root #更改root用户的密码


fdisk -l #查看当前系统的磁盘数据

在这里插入图片描述

  • b表示broker设备及块设备
  • /dev/vda 表示第a块设备
  • /dev/vda1 表示第a块设备的第一个分区
  • Boot表示启动分区
  • Start 起始的扇区号
  • End 最终的扇区号
  • Sectors 扇区的数量
  • Size 大小
  • Id 分区类型编号(83表示linux分区)
  • System 表示系统类型
使⽤debugfs命令观察⽂件的扇区内容
[root@VM_0_13_centos /]# fdisk -l

Disk /dev/vda: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000d64b4
#设备
   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048   104857566    52427759+  83  Linux
[root@VM_0_13_centos /]# debugfs /dev/vda1  #使⽤debugfs命令观察⽂件的扇区内容
debugfs 1.42.9 (28-Dec-2013)
debugfs:  blocks test # 查看test⽂件占⽤的扇区号
2155242 
debugfs:  bd 2155242 # 将指定编号的扇区打印出来
0000  6865 6c6c 6f20 776f 7264 0a00 0000 0000  hello word......
0020  0000 0000 0000 0000 0000 0000 0000 0000  ................
*

debugfs:  q #退出debugfs
[root@VM_0_13_centos /]# cat test 
hello word
[root@VM_0_13_centos /]# rm -rf test 
#再次进⼊debugfs 查看之前的扇区内容
[root@VM_0_13_centos /]# debugfs /dev/vda1
debugfs 1.42.9 (28-Dec-2013)
debugfs:  bd 2155242 
0000  6865 6c6c 6f20 776f 7264 0a00 0000 0000  hello word......
0020  0000 0000 0000 0000 0000 0000 0000 0000  ................
*
#发现⽂件虽然删除了,但是扇区中的⽂件内容还在,可以被⽤来反删除
debugfs:  q
[root@VM_0_13_centos /]# 

du -h test
查看目录占用磁盘的空间大小
[root@VM_0_13_centos testc]# du -h A
4.0K	A			#实际占用空间大小,4K(8个扇区的大小)
[root@VM_0_13_centos testc]# ll A
-rw-r--r-- 1 root root 6 Mar 12 13:07 A #实际大小只有6个字节
[root@VM_0_13_centos testc]# 
stat A
查看文件的大小,状态,访问控制权限,访问时间,修改时间,
[root@VM_0_13_centos testc]# 
  File: ‘A’
  Size: 6         	Blocks: 8          IO Block: 4096   regular file
Device: fd01h/64769d	Inode: 655368      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2020-03-12 13:07:56.505892203 +0800
Modify: 2020-03-12 13:07:56.505892203 +0800
Change: 2020-03-12 13:07:56.512892200 +0800
 Birth: -

硬链接&软链接

硬链接:两个硬链接文件的inode号(文件控制块)一模一样。

[root@VM_0_13_centos tmp]# ln test test.link #创建硬链接文件
[root@VM_0_13_centos tmp]# ls -li #列出文件的inode号
total 20
525962 drwx------ 2 root root 4096 Jul 10 14:58 72f080512694ede4caf54fbbaf15d003
919905 drwx------ 3 root root 4096 Mar 17 15:34 systemd-private-78dba44efcdb4ff9b5c668da271f052d-ntpd.service-u7GgYA
   952 -rw-r--r-- 2 root root    6 Jul 18 19:09 test		#inode号=952
  1819 -rw-r--r-- 1 root root    6 Jul 18 19:09 test1
   952 -rw-r--r-- 2 root root    6 Jul 18 19:09 test.link  #inode号=952
[root@VM_0_13_centos tmp]# rm -rf test 
[root@VM_0_13_centos tmp]# cat test.link 
test1
[root@VM_0_13_centos tmp]# stat test.link  删除原始文件之后,文件任然存在
  File: ‘test.link’
  Size: 6         	Blocks: 8          IO Block: 4096   regular file
Device: fd01h/64769d	Inode: 952         Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2020-07-18 19:09:16.225934028 +0800
Modify: 2020-07-18 19:09:22.662916036 +0800
Change: 2020-07-18 19:17:31.965944695 +0800
 Birth: -
[root@VM_0_13_centos tmp]# 

软链接:软连接文件的inode号和原始文件不一致,软连接只是保存到原始文件的地址

ln -s test1 test1.link #创建软连接文件
[root@VM_0_13_centos tmp]# ls -li 
total 16
525962 drwx------ 2 root root 4096 Jul 10 14:58 72f080512694ede4caf54fbbaf15d003
919905 drwx------ 3 root root 4096 Mar 17 15:34 systemd-private-78dba44efcdb4ff9b5c668da271f052d-ntpd.service-u7GgYA
  1819 -rw-r--r-- 1 root root    6 Jul 18 19:09 test1  #inode号=1819 
  1821 lrwxrwxrwx 1 root root    5 Jul 18 19:20 test1.link -> test1 #inode号=1821 软连接文件与原始文件的inode号不一致
   952 -rw-r--r-- 1 root root    6 Jul 18 19:09 test.link
root@VM_0_13_centos tmp]#  rm -rf test1
[root@VM_0_13_centos tmp]# cat test1.link  #删除原始文件之后,软链接文件不存在
cat: test1.link: No such file or directory

[root@VM_0_13_centos tmp]# echo hello > test1.link  #向软链接写东西,原始文件又回来了
[root@VM_0_13_centos tmp]# ll -i
total 16
525962 drwx------ 2 root root 4096 Jul 10 14:58 72f080512694ede4caf54fbbaf15d003
919905 drwx------ 3 root root 4096 Mar 17 15:34 systemd-private-78dba44efcdb4ff9b5c668da271f052d-ntpd.service-u7GgYA
  1819 -rw-r--r-- 1 root root    6 Jul 18 19:27 test1
  1821 lrwxrwxrwx 1 root root    5 Jul 18 19:20 test1.link -> test1
   952 -rw-r--r-- 1 root root    6 Jul 18 19:09 test.link
[root@VM_0_13_centos tmp]# 


stat test

[root@VM_0_13_centos tmp]# stat test
  File: ‘test’
  Size: 6         	Blocks: 8          IO Block: 4096   regular file
Device: fd01h/64769d	Inode: 1822        Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2020-07-18 19:31:32.075859761 +0800 #访问时间 (atime)
Modify: 2020-07-18 19:31:32.075859761 +0800 #修改内容时间(mtime)
Change: 2020-07-18 19:31:32.075859761 +0800 #修改文件内容的时间或者修改文件属性的时间(ctime)
 Birth: -  #文件的创建时间(crtime)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值