文件类型包含普通文件、目录、字符设备文件、块设备文件
-type c
File is of type c:
b block (buffered) special **
c character (unbuffered) special
d directory *****
p named pipe (FIFO)
f regular file *****
l symbolic link; this is never true if the -L
option or the -follow option is in effect,
unless the symbolic link is broken. If you
want to search for symbolic links when -L is
in effect, use -xtype. ***
s socket
D door (Solaris)
查看文件类型:
[root@wuyike ~]# file /etc/profile
/etc/profile: ASCII English text
[root@wuyike ~]# file /bin/cp
/bin/cp: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped
[root@wuyike ~]# file /var/log/wtmp
/var/log/wtmp: data
[root@wuyike ~]# ll /var/log/wtmp /bin/cp /etc/profile
-rwxr-xr-x. 1 root root 122872 10月 15 2014 /bin/cp
-rw-r--r--. 1 root root 1796 10月 2 2013 /etc/profile
-rw-rw-r--. 1 root utmp 21888 4月 15 01:57 /var/log/wtmp
创建字符设备
[root@wuyike ~]# mknod wuyike c 5 1
[root@wuyike ~]# ll
总用量 16
-rw-r--r--. 1 root root 31 3月 3 08:15 awk.txt
drwxr-xr-x. 6 root root 4096 3月 3 19:35 data
-rw-r--r--. 1 root root 7 3月 4 03:00 test.txt
crw-r--r--. 1 root root 5, 1 4月 16 10:50 wuyike
-rw-r--r--. 1 root root 30 3月 4 18:51 wuyike.txt
-rw-r--r--. 1 root root 0 3月 4 18:51 吴宜珂.txt
链接:
用ln创建链接文件
ln 源文件 目标文件(创建硬链接)
ln -s 源文件 目标文件(创建软链接)
硬链接是指通过索引节点(iNode)来进行链接的。在Linux ext2、ext3、ext4文件系统中,保存在磁盘分区中的文件不管是什么类型都会分配发给他一个编号,这个编号被称为索引节点(Index INode)。
硬链接文件就相当于文件的另外一个入口。硬链接的作用之一是允许一个文件拥有多个有效路径名(多个入口),这样用户就可以建立硬链接到重要的文件,以防止“误删”源数据(很多硬件存储,如netapp存储中的快照功能就应用了这个原理,增加了一个快照就多了一个硬链接)。原因:
文件删除控制的变量:
i_link 文件的硬链接数量
i_count 引用数量(有一个程序使用i_count加1)
文件删除的条件:
i_link=0 and i_count=0(进程shut down,链接全部删除)
问题:
1、被进程占用的文件能不能删?能
2、如何查看文件是否被进程占用,或者查看i_count?
3、如何找回没有链接指向但是被进程占用的文件?
创建硬链接文件:
这两个硬链接文件inode相同:
[root@wuyike wuyike]# ls -lhi wuyikefile*
400923 -rw-r--r-- 2 root root 18 4月 18 22:03 wuyikefile
400923 -rw-r--r-- 2 root root 18 4月 18 22:03 wuyikefile_hard_link
删除其中一个硬链接文件:
[root@wuyike wuyike]# cat wuyikefile
I am wuyike linux
[root@wuyike wuyike]# cat wuyikefile_hard_link
I am wuyike linux
[root@wuyike wuyike]# rm -f wuyikefile
[root@wuyike wuyike]# cat wuyikefile_hard_link
I am wuyike linux
[root@wuyike wuyike]# cat wuyikefile
cat: wuyikefile: 没有那个文件或目录
查看存在的硬链接文件:
[root@wuyike wuyike]# ln wuyikefile_hard_link wuyikefile
[root@wuyike wuyike]# ll -lrt
总用量 8
-rw-r--r-- 2 root root 18 4月 18 22:03 wuyikefile_hard_link
-rw-r--r-- 2 root root 18 4月 18 22:03 wuyikefile
将硬链接创建到别的文件夹:
[root@wuyike wuyike]# ln wuyikefile /tmp/kkk
[root@wuyike wuyike]# ll
总用量 8
-rw-r--r-- 3 root root 18 4月 18 22:03 wuyikefile
-rw-r--r-- 3 root root 18 4月 18 22:03 wuyikefile_hard_link
查找某个文件所有的硬链接:
[root@wuyike ~]# find / -type f|xargs ls -lhi|grep 400923
fdisk -l命令:可以查看新增的磁盘
tune2fs -c -1 /dev/sdb
mkdir /app/log -p
mount -t ext4 -o defaults /dev/sdb /app/log
[root@wuyike log]# df -i
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/sda3 610800 80822 529978 14% /
tmpfs 125543 1 125542 1% /dev/shm
/dev/sda1 51200 38 51162 1% /boot
/dev/sdb 26208 11 26197 1% /app/log
[root@wuyike log]# for n in `seq 26220`;do touch stu$n;done
touch: 无法创建"stu26198": 设备上没有空间·-->有几个inode被磁盘本身占用了
touch: 无法创建"stu26199": 设备上没有空间
touch: 无法创建"stu26200": 设备上没有空间
touch: 无法创建"stu26201": 设备上没有空间
touch: 无法创建"stu26202": 设备上没有空间
touch: 无法创建"stu26203": 设备上没有空间
touch: 无法创建"stu26204": 设备上没有空间
touch: 无法创建"stu26205": 设备上没有空间
touch: 无法创建"stu26206": 设备上没有空间
touch: 无法创建"stu26207": 设备上没有空间
touch: 无法创建"stu26208": 设备上没有空间
touch: 无法创建"stu26209": 设备上没有空间
touch: 无法创建"stu26210": 设备上没有空间
touch: 无法创建"stu26211": 设备上没有空间
touch: 无法创建"stu26212": 设备上没有空间
touch: 无法创建"stu26213": 设备上没有空间
touch: 无法创建"stu26214": 设备上没有空间
touch: 无法创建"stu26215": 设备上没有空间
touch: 无法创建"stu26216": 设备上没有空间
touch: 无法创建"stu26217": 设备上没有空间
touch: 无法创建"stu26218": 设备上没有空间
touch: 无法创建"stu26219": 设备上没有空间
touch: 无法创建"stu26220": 设备上没有空间
[root@wuyike log]# touch dd
touch: 无法创建"dd": 设备上没有空间
[root@wuyike log]# df -i
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/sda3 610800 54600 556200 9% /
tmpfs 125543 1 125542 1% /dev/shm
/dev/sda1 51200 38 51162 1% /boot
/dev/sdb 26208 26208 0 100% /app/log
删除:
[root@wuyike ~]# find ./ -type f|xargs rm -f
或:
[root@wuyike ~]# ls|xargs rm -f
可以通过lsof查看被进程占用的文件
Web服务器磁盘满故障深入解析
http://oldboy.blog.51cto.com/2561410/612351
所以这种日志文件最好用>****.log来清空,而不用rm
一个文件目录中的.和当前目录的inode相同,互为硬链接
..相对路径,表示当前目录的上一级目录 软连接:
软链接的创建与知识点:
目录不可以创建硬链接,但是可以创建软链接 删除原始文件后,其硬链接文件不受影响,对应的数据依然存在,但是其对应的软连接文件失效了,原因是找不到源文件,此时,可以删除软连接文件重新创建,或者创建一个硬链接文件。
1、界山软硬链接的概念。
2、对于文件的软硬链接的区别。
3、对于目录的软硬链接区别。
企业生产中目录软链接的作用:
1、编译软件时指定版本号(/application/apache2.2.23),访问时希望去掉版本号(/application/appache),可以设置软链接到编译的路径。所有程序都访问软链接文件(/application/apache),当软件升级高版本后。只需要删除链接文件,重建到高版本路径的软连接即可(/application/apache)。
2、企业代码发布时,(PHP程序),需要把所有代码传到一个新的临时目录或者新的站点目录。发布时要么一个mv,也可以重建软链接,指向到这个新的临时目录或者站点目录。
3、不方便文件移动,使用软链接。