Linux文件目录常用管理命令
ln 默认创建硬链接命令
-s 创建软链接
[root@localhost tmp]# touch f1
[root@localhost tmp]# ln f1 f2
[root@localhost tmp]# ln -s f1 f3
[root@localhost tmp]# ls -li
total 0
8388681 -rw-r--r--. 2 root root 0 Feb 2 18:35 f1
8388681 -rw-r--r--. 2 root root 0 Feb 2 18:35 f2
8389026 lrwxrwxrwx. 1 root root 2 Feb 2 18:36 f3 -> f1硬链接文件f2与原文件f1的inode节点相同,均为8388681,而f3软连接文件的inode节点不同
file 识别文件内容类型
-f file :读取文件file中文件列表,并查看文件内容类型,而非查看file
-b:不显示文件名
split 文档分割命令 默认是按照每1000行进行分割
-b:指定每一个文件的大小
-d:以数字作为后缀 -a 指定后缀长度
链接文件
硬链接:通过inode索引节点来进行连接
软链接:类似于Windows的快捷方式
[root@localhost tmp]# ls -li
total 12
8389076 -rw-r--r--. 1 root root 83 Jan 22 15:47 file
8388681 -rw-r--r--. 2 root root 6 Jan 22 10:53 world
8388681 -rw-r--r--. 2 root root 6 Jan 22 10:53 world_hard
8389074 lrwxrwxrwx. 1 root root 5 Jan 22 10:56 world_sort -> world
Linux文件系统
inode block superblock(磁盘的容量由inode和block同时决定 )
superblock:记录文件系统整体信息,包括inode/block的总量,使用量,剩余量 文件系统类型以及文件系统相关信息
inode:记录文件的属性,一个文件占用一个inode,同时记录文件的内容存放的block号码
block:实际记录文件内容的磁盘空间,不同文件大小,占用不同数量的block 一般一个block是4k大小,若文件太大时,会占用多个block。
Linux文件系统的文件权限(rwx),文件属性(拥有者,群组,时间参数等)及文件的内容。文件系统通常会将这两部分的数据分别存放在不同的区块,权限和属性放置到inode中,实际内容放置到date block区块中。另外,还有一个超级区块(superblock)会记录整个文件系统的整体信息,包括inode与block的总量,使用量,剩余量等。
Linux文件删除原理
Linux是通过link的数量来控制文件删除的,只有当一个文件不存在任何link的时候,这个文件才会被删除。
两个link计数器
i_count:调用的次数
i_nlink:文件的链接次数(硬链接)
linux文件处理工具
cut:文件切割
-b:以字节为单位进行切割0
-c:以字符为单位进行切割
-d:自定义分隔符
-f:与-d一起使用,指定显示哪个区域
[root@localhost tmp]# vi test
[root@localhost tmp]# cat test
hello world hello world hello world
hello world !
[root@localhost tmp]# cat test | cut -b 3,5
lo
lo
[root@localhost tmp]# cat test | cut -b 3-4,5
llo
llo
[root@localhost tmp]# cat test | cut -b 3-4,7
llw
llw
[root@localhost tmp]# cat test | cut -b -3
hel
hel
[root@localhost tmp]# cat test | cut -b 3-
llo world hello world hello world