@查看文件的属性信息

文件的类型和属性
[root@qls ~]# ls -li
total 24
134317708 drwxr-xr-x. 2 root root  22 Jul 13 19:06 backup
    16346 drwxr-xr-x. 2 root root  22 Jul 13 19:06 data
134317704 -rw-r--r--. 1 root root  28 Jul 13 16:53 file.txt
134317705 -rw-r--r--. 1 root root  75 Jul 14 20:17 ip.txt
134317678 -rw-r--r--. 1 root root 798 Jul 14 19:13 passwd


第一列:	134317708			#inode号  索引节点  

第二列:	-rw-r--r--.        #文件的类型和权限 

第三列:	2					#文件的硬链接的数量 

第四列:	root				#文件的所有者   属主 

第五列:	root				#文件的所属组   属组 

第六列:	798					#文件的大小  

第七八九列	Jul 13 19:06  		#文件创建时间或最后的修改时间    

第十列:	passwd				 #文件的名称   不属于文件的属性 






#查看目录的大小  

	-s		#显示大小 
	
	-h		#以B MB GB的格式显示大小

[root@qls ~]# du  -sh  /etc
31M	/etc



文件类型 

drwxr-xr-x.
-rw-r--r--.
lrwxrwxrwx
crw-rw-rw-
srw-rw-rw-
prw-------.

第一个字符为文件的类型信息

第二个到第10个	文件权限 


文件类型的种类:


	-		#普通文件    二进制  日志 文本  脚本 
	
	d		#目录 
	
	l		#软链接文件   
	
	b		#块设备   磁盘 硬盘  磁盘分区  镜像  光盘 
	
	c		#字符设备  
    
    s		#套接字文件  socket文件 
    
    p		#管道文件  
	
	
#详细显示文件的属性信息

[root@qls ~]# stat  passwd 
  File: ‘passwd’
  Size: 798       	Blocks: 8          IO Block: 4096   regular file
Device: 803h/2051d	Inode: 134317678   Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Context: unconfined_u:object_r:admin_home_t:s0
Access: 2020-07-14 19:13:16.904691535 +0800
Modify: 2020-07-14 19:13:12.935691465 +0800
Change: 2020-07-14 19:13:12.935691465 +0800
 Birth: -

#  -c		指定格式输出    %a  以8进制显示文件的权限  

[root@qls ~]# stat -c %a  passwd
644



file		#详细显示文件的信息  


[root@qls ~]# file passwd 
passwd: ASCII text

[root@qls ~]# file  /opt/
/opt/: directory

[root@qls ~]# file  /bin/ls
/bin/ls: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=ceaf496f3aec08afced234f4f36330d3d13a657b, stripped

[root@qls ~]# ll  /bin/ls
-rwxr-xr-x. 1 root root 117680 Oct 31  2018 /bin/ls

[root@qls ~]# file  /etc/grub2.cfg 
/etc/grub2.cfg: symbolic link to `../boot/grub2/grub.cfg'

[root@qls ~]# file  /dev/log
/dev/log: socket

[root@qls ~]# file /run/systemd/initctl/fifo
/run/systemd/initctl/fifo: fifo (named pipe)


后缀名:

Linux中对后缀没有任何的要求,  系统存在一些带后缀名的文件,只是为了方便程序人员的使用  

Linux中是区分大小写的  


	.txt
	
	.log
	
	.xml
	
	.conf
	
	.cnf
	
	.html
	
	.php
	
	.sh
	
	.py
	
	.mp3
	
	.jpg
	
	.png
	
	.tar
	
	.tar.gz
	
	.gz
	
	.zip
	

链接文件

文件的组成:

元数据:	metadata 	属性信息    大小 时间  属主  属组 权限  inode   索引节点   

用户数据:	user data 	数据块   硬盘存放真实数据的地方     block  


文件分为硬链接文件  hard link 和软链接文件或者符号链接   symbolic link  ==  soft link


软链接文件:

	概念:  就是相当于Windows上面的快捷方式   里面存放的是文件的路径  及可以执行这个文件 
	
	软链接文件和源文件属于不同的文件  inode是不一样 
	
[root@qls ~]# ll -i /etc/sysconfig/selinux
134477906 lrwxrwxrwx. 1 root root 17 Jul  6 02:14 /etc/sysconfig/selinux -> ../selinux/config
[root@qls ~]# ll -i /etc/selinux/config
223842 -rw-r--r--. 1 root root 543 Jul  6 02:14 /etc/selinux/config


创建软链接通过 ln命令 

选项:

	-s		#创建软链接 

ln  -s		源文件      链接文件 


[root@qls ~]# ln -s /etc/sysconfig/network-scripts/ifcfg-eth0  /root/eth0
[root@qls ~]# ll
total 0
lrwxrwxrwx. 1 root root 41 Jul 15 20:01 eth0 -> /etc/sysconfig/network-scripts/ifcfg-eth0



	
应用场景:

1. 企业的代码发布  Jenkins    秒级发布  

2. 软件版本升级 	

3. 不方便移动的目录或者文件 


[root@qls ~]# mkdir   nginx-1.17.0
[root@qls ~]# ll
total 0
drwxr-xr-x. 2 root root 6 Jul 15 19:59 nginx-1.17.0
[root@qls ~]# mkdir  nginx-1.18.0
[root@qls ~]# ll
total 0
drwxr-xr-x. 2 root root 6 Jul 15 19:59 nginx-1.17.0
drwxr-xr-x. 2 root root 6 Jul 15 19:59 nginx-1.18.0

[root@qls ~]# ll
total 0
lrwxrwxrwx. 1 root root 41 Jul 15 20:01 eth0 -> /etc/sysconfig/network-scripts/ifcfg-eth0
drwxr-xr-x. 2 root root  6 Jul 15 19:59 nginx-1.17.0
drwxr-xr-x. 2 root root  6 Jul 15 19:59 nginx-1.18.0
[root@qls ~]# ln  -s nginx-1.17.0/    nginx
[root@qls ~]# ll
total 0
lrwxrwxrwx. 1 root root 41 Jul 15 20:01 eth0 -> /etc/sysconfig/network-scripts/ifcfg-eth0
lrwxrwxrwx. 1 root root 13 Jul 15 20:04 nginx -> nginx-1.17.0/
drwxr-xr-x. 2 root root  6 Jul 15 19:59 nginx-1.17.0
drwxr-xr-x. 2 root root  6 Jul 15 19:59 nginx-1.18.0
[root@qls ~]# rm -f  nginx  &&  ln -s  nginx-1.18.0/  nginx		#版本升级
[root@qls ~]# ll
total 0
lrwxrwxrwx. 1 root root 41 Jul 15 20:01 eth0 -> /etc/sysconfig/network-scripts/ifcfg-eth0
lrwxrwxrwx. 1 root root 13 Jul 15 20:04 nginx -> nginx-1.18.0/
drwxr-xr-x. 2 root root  6 Jul 15 19:59 nginx-1.17.0
drwxr-xr-x. 2 root root  6 Jul 15 19:59 nginx-1.18.0


[root@qls ~]# rm -f nginx  &&  ln -s  nginx-1.17.0/  nginx		#版本回退  
[root@qls ~]# ll
total 0
lrwxrwxrwx. 1 root root 41 Jul 15 20:01 eth0 -> /etc/sysconfig/network-scripts/ifcfg-eth0
lrwxrwxrwx. 1 root root 13 Jul 15 20:07 nginx -> nginx-1.17.0/
drwxr-xr-x. 2 root root  6 Jul 15 19:59 nginx-1.17.0
drwxr-xr-x. 2 root root  6 Jul 15 19:59 nginx-1.18.0




&&		#前面的命令执行成功  才会执行后面的命令 


||		#前面的命令执行失败,才会执行后面的命令 



软链接的特点:

概念

创建 

跟源文件是不同类型的文件,inode是不一样的

软链接可以对目录创建 也可以跨文件系统 

rm  -f

删除软链接文件对源文件没有任何影响 

删除源文件,软链接存在,但是会失效   出现 红底白字闪烁状  



硬链接

概念:	多个文件的数据指向同一个数据块,多个不同的入口,inode是相同的,这样的文件互为硬链接 

防止文件被误删除  

创建 

	ln命令直接创建   只能对文件创建  不能对目录创建  
	
	ln   源文件    硬链接文件 
	
	

[root@qls ~]# cp  /etc/hosts   ./
[root@qls ~]# ll
total 4
lrwxrwxrwx. 1 root root  41 Jul 15 20:01 eth0 -> /etc/sysconfig/network-scripts/ifcfg-eth0
-rw-r--r--. 1 root root 158 Jul 15 20:18 hosts
lrwxrwxrwx. 1 root root  13 Jul 15 20:07 nginx -> nginx-1.17.0/
drwxr-xr-x. 2 root root   6 Jul 15 19:59 nginx-1.17.0
drwxr-xr-x. 2 root root   6 Jul 15 19:59 nginx-1.18.0
[root@qls ~]# ln  hosts    hosts_hard
[root@qls ~]# ll
total 8
lrwxrwxrwx. 1 root root  41 Jul 15 20:01 eth0 -> /etc/sysconfig/network-scripts/ifcfg-eth0
-rw-r--r--. 2 root root 158 Jul 15 20:18 hosts
-rw-r--r--. 2 root root 158 Jul 15 20:18 hosts_hard
lrwxrwxrwx. 1 root root  13 Jul 15 20:07 nginx -> nginx-1.17.0/
drwxr-xr-x. 2 root root   6 Jul 15 19:59 nginx-1.17.0
drwxr-xr-x. 2 root root   6 Jul 15 19:59 nginx-1.18.0
[root@qls ~]# ll -i 
total 8
134317677 lrwxrwxrwx. 1 root root  41 Jul 15 20:01 eth0 -> /etc/sysconfig/network-scripts/ifcfg-eth0
134317704 -rw-r--r--. 2 root root 158 Jul 15 20:18 hosts
134317704 -rw-r--r--. 2 root root 158 Jul 15 20:18 hosts_hard


[root@qls ~]# cat hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
[root@qls ~]# cat hosts_hard 
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
[root@qls ~]# echo "123" >>hosts_hard
[root@qls ~]# cat hosts_hard 
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
123
[root@qls ~]# cat hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
123


删除源文件或者硬链接文件都没有什么影响    只有硬链接为0时,这个文件才会被真正的删除 



企业面试题:软链接和硬链接的区别? 

1. 从概念   

2. 从创建方式 

3. 从创建对象 

4. 从删除 


posted @ 2021-03-13 09:37  ଲ一笑奈&何  阅读(44)  评论(0编辑  收藏  举报