设备文件不是保存数据的,它仅提供到设备的访问,因为设备文件不使用数据块。
所有文件都使用文件名和一个叫inode的记录。
所有文件系统的根目录的inode的号都是2。
bash-3.2$ pwd
/
bash-3.2$ ls -lai | sort -k1n
total 965
2 drwxr-xr-x 40 root root 1024 Dec 14 00:59 .
2 drwxr-xr-x 40 root root 1024 Dec 14 00:59 ..
3 drwx------ 2 root root 8192 Sep 7 22:31 lost+found
4 drwxr-xr-x 3 root sys 512 Sep 7 22:31 export
6 drwxr-xr-x 47 root sys 1024 Sep 10 00:20 var
31 drwxr-xr-x 40 root sys 1024 Sep 7 23:49 usr
77 drwxr-xr-x 88 root sys 4608 Dec 15 00:20 etc
128 drwxr-xr-x 5 root sys 512 Sep 7 23:34 platform
143 drwxr-xr-x 8 root sys 512 Sep 7 23:55 boot
1770 lrwxrwxrwx 1 root root 9 Sep 7 22:33 bin -> ./usr/bin
一般的,ls -lai就能告诉你文件和目录的inode是多少。
-bash-3.2# df -g /export/home
/export/home (/dev/dsk/c0t0d0s7 ): 8192 block size 1024 frag size
44585154 total blocks 44540864 free blocks 44095014 available 2684864 total files
2684846 free files 7864327 filesys id
ufs fstype 0x00000004 flag 255 filename length
total files是指总共的可用的inode,free files是指还可以使用的inode
显示各文件系统的inode的使用情况
-bash-3.2# /usr/bin/df -oi
df: operation not applicable for FSType autofs
df: operation not applicable for FSType ctfs
df: operation not applicable for FSType devfs
df: operation not applicable for FSType fd
df: operation not applicable for FSType lofs
df: operation not applicable for FSType mntfs
df: operation not applicable for FSType nfs
df: operation not applicable for FSType objfs
df: operation not applicable for FSType proc
df: operation not applicable for FSType sharefs
df: operation not applicable for FSType tmpfs
Filesystem iused ifree %iused Mounted on
/dev/dsk/c0t0d0s0 202739 775693 21% /
/dev/dsk/c0t0d0s7 18 2684846 0% /export/home
df: operation not applicable for FSType vboxfs
-bash-3.2#
-bash-3.2# df -i
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/dsk/c0t0d0s0 978432 202738 775694 21% /
swap 232726 382 232344 1% /etc/svc/volatile
/usr/lib/libc/libc_hwcap1.so.1 978432 202738 775694 21% /lib/libc.so.1
swap 232726 382 232344 1% /tmp
swap 232726 382 232344 1% /var/run
/dev/dsk/c0t0d0s7 2684864 18 2684846 1% /export/home
solaris3_bin 14886959 0 14886959 0% /mnt/sf_solaris3_bin
-bash-3.2# which df
/opt/csw/gnu/df
看下inode的内容?
可以安装stat来详细查看,它在coreutils包里,可以使用pkgutil来下载安装。
-bash-3.2# stat hello.txt
File: `hello.txt'
Size: 31 Blocks: 2 IO Block: 8192 regular file
Device: 780007h/7864327d Inode: 17 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 1000/ canjli) Gid: ( 1/ other)
Access: 2012-12-15 00:34:07.709970000 +0800
Modify: 2012-12-15 00:33:38.751086000 +0800
Change: 2012-12-15 00:33:38.751086000 +0800
Birth: -
-bash-3.2# cd ..
-bash-3.2# ls
local.cshrc local.login local.profile tmp
-bash-3.2# stat tmp
File: `tmp'
Size: 512 Blocks: 2 IO Block: 8192 directory
Device: 780007h/7864327d Inode: 16 Links: 2
Access: (0755/drwxr-xr-x) Uid: ( 1000/ canjli) Gid: ( 1/ other)
Access: 2012-12-15 01:10:03.770507000 +0800
Modify: 2012-12-15 00:33:38.750850000 +0800
Change: 2012-12-15 00:33:38.750850000 +0800
Birth: -
不过给的信息也并没有想象的那么全。
-bash-3.2# ls -la
total 3
drwxr-xr-x 3 root sys 512 Sep 8 00:17 .
drwxr-xr-x 8 root sys 512 Dec 9 19:48 ..
drwxr-xr-x 2 root sys 512 Sep 8 00:17 disk@0,0
brw-r----- 1 root sys 30, 0 Dec 15 00:20 disk@0,0:a
crw-r----- 1 root sys 30, 0 Dec 15 00:49 disk@0,0:a,raw
brw-r----- 1 root sys 30, 1 Dec 15 00:21 disk@0,0:b
crw-r----- 1 root sys 30, 1 Dec 15 00:49 disk@0,0:b,raw
输出中每一行的第一个字母的含义:
-:常规文件
d:目录
l:软链接
b:块设备文件
c:字符设备文件,也叫裸设备文件
设备文件分为字符设备和块设备。字符设备也叫裸设备,以磁盘的最小可寻址单元(sector,512 bytes)为单位进行IO的输入输出操作,而块设备则基于所定义的逻辑块的大小。
-bash-3.2# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/dsk/c0t0d0s0 8132399 4335043 3716033 54% /
swap 1398132 984 1397148 1% /etc/svc/volatile
/usr/lib/libc/libc_hwcap1.so.1 8132399 4335043 3716033 54% /lib/libc.so.1
swap 1397184 36 1397148 1% /tmp
swap 1397176 28 1397148 1% /var/run
/dev/dsk/c0t0d0s7 22292577 22145 22047507 1% /export/home
solaris3_bin 412993532 174802172 238191360 43% /mnt/sf_solaris3_bin
-bash-3.2#
查看设备的逻辑块的大小(一般是8k):
-bash-3.2# mkfs -m /dev/dsk/c0t0d0s0
mkfs -F ufs -o nsect=128,ntrack=48,bsize=8192,fragsize=1024,cgsize=16,free=1,rps=2,nbpi=8155,opt=t,apc=0,gap=0,nrpos=8,maxcontig=128,mtb=n /dev/dsk/c0t0d0s0 16514820
关于软链接和硬链接
-bash-3.2# touch dir1
-bash-3.2# ln -s dir1 dir2
-bash-3.2# ls -lai dir*
332028 -rw-r--r-- 1 root root 0 Dec 15 01:56 dir1
332041 lrwxrwxrwx 1 root root 4 Dec 15 01:56 dir2 -> dir1
-bash-3.2#
dir2是个软链接,它的inode中存放的是指向dir1的inode中指向的数据块。
删除dir2并不会删除dir1。
-bash-3.2# rm dir2
-bash-3.2# ls -lai dir*
332028 -rw-r--r-- 1 root root 0 Dec 15 01:56 dir1
-bash-3.2#
-bash-3.2# touch file1
-bash-3.2# ln file1 file2
-bash-3.2# ls -lai file*
332082 -rw-r--r-- 2 root root 0 Dec 15 02:01 file1
332082 -rw-r--r-- 2 root root 0 Dec 15 02:01 file2
硬链接的话,inode是同一个,都指向同一个数据块。删除任何一个都不会影响另一个。
注意第三列的2指的就是硬链接的个数。
删除硬链接可以使用rm, rmdir或unlink命令。
关于硬链接数
目录的硬链接数由其目录中子目录的数目决定。
目录复制
当需要把一个目录的所有内容拷贝到另一个目录时,可以使用cp -pr,但是这会把硬链接拷贝成一个新的文件。
可以使用:
find . | cpio -pdmu /tmp1
或者
tar cvf - . | (cd /tmp1; tar xvf -)
添加新评论0 条评论