zoukankan      html  css  js  c++  java
  • day08---文件属性

    课程知识介绍
    	文件的属性
    		文件属性每列含义
    		文件属性每列详解
    		    文件类型
    			软链接硬链接
    			inode block
    			find命令
    
    1.文件的属性
    	ls -l  PS: ls默认是以首字母进行排序
    	   -r  逆序排序
    	   -i  inode
    	   -h  人类可读显示文件的大小
    	   PS:对于目录来说 ll -lh 只显示目录本身的大小 而不显示整个目录的大小
    -----------------------------------------------文件属性	    文件目录名    
    33575034  -	 rw-r--r--.  1 root root 1218 5月   8 10:58       passwd
    -------- ---  --------  -- ---  ---- ---- -----------------   ------
    	01	  02    03      04  05    06  07        08 				09
    
    
    01. inode 文件数据的inode信息 index node 索引节点
        inode中存放的是文件的属性和存放文件的位置
         作用:快速从磁盘中找到文件中的数据信息
    02. 文件的具体类型
        文件类型:目录 普通文件 压缩文件 设备文件
           作用:区分文件类型
    03. 文件的权限
         r  =  read	   可读  可以使用cat less more vim
    	 w  =  write   可写  vim能不能往里写入新的内容 echo 111 >passwd
    	 e  =  execute  可执行 ./passwd
    	   作用: 控制不同的用户对当前的文件或目录拥有不同的权限
    04. 文件目录的硬链接 类似于超市的多个门
    	   作用:可以从任意一个门查看数据信息
    05. 文件的属主
    	   文件的拥有者    这个文件是哪个用户创建的
    	   笔记本的拥有者  张三   文件属于root
    	       作用:区分当前文件属于哪个用户
    06. 文件的属组
    	   张三的家人在组内 张三的朋友  在组内的成员对我的笔记本拥有什么权限
    	   文件的属组用户对于文件的权限
    	       作用:当前文件属于哪个组
    07. 文件的大小
    
    08. 文件的时间信息
    
    09. 文件名称
    
    
    
    2.文件属性详细说明 文件的类型(文件属性的第二列的第一列)
       1)windows文件类型
    		    .exe 可执行文件 安装软件
    			.pdf
    			.txt
    			.mp4
    			guoli.avi
    	windows: 利用后缀名的方式来区分文件的类型
    	
    	2)Linux文件类型
    			oldboy.txt
    			oldboy.sh
    			file.rpm
    			python.py
    			.jpg
    			.config .conf
    	Linux:不用扩展名来区分文件类型 扩展名都是给我们自己看的
    	3)如何区分Linux的文件类型
    	 a.使用颜色来区分
    	 b.使用命令查看文件的属性进行区分 ll 看属性的开头的第一列
    	 c.使用命令直接查看文件的类型
    	 
    	4)Linux中常见的文件类型
    	  1. - 普通文件 
    	     普通文件的种类: - 的种类
    		  a. 普通文件 oldboy.txt /etc/passwd /etc/hosts  # 可以直接编辑的文件
    		  b. 二进制命令文件 /bin/ls /usr/bin/touch       # 命令 不可编辑文件
    		  c. 数据文件 tar.gz .rpm包 data				 # 数据文件 压缩包
    	 
    	   2. 目录 表示方法 d
    	   
    	   3. l 小写的L softlink 软链接
    	   
    	   4. b 快设备 硬件 磁盘 光驱
    	 
    	   5. c 字符设备
    		  /dev/urandom   # 生成随机数
    		  /dev/null      # 黑洞 可以把没用的信息全部输入到黑洞 定时任务 脚本使用
    		  /dev/zero      # 使用或者读取它 会提供无限连续的空的数据流 生成大文件使用
    					     # 扩展: dd if=/dev/zero of=/tmp/10G
    		---------------------------------
    		6. s  socket 套接字 网络编程文件
    		7. p 管道文件
    	  
    3. 文件相关扩展命令
    	1)which   查看命令的全路径
    	2)whereis 查看命令全路径和该命令的帮助文档的具体路径
    	3)file    查看文件的具体类型
    	4)find    查找文件或目录
    	
    	find命令
    	语法格式:
    		find 从哪里找  找什么类型  名字
    		找对象:
    		find  老家找   高矮胖瘦    小红 
    		------------
    		find       命令
    		从哪里找   路径 /etc/查找  ./ 当前目录下查找 /tmp查找  /查找(公司建议不使用)
    		什么类型   
    				Linux类型 
    					f 普通文件 
    					d 目录
    					l link
    		名字    oldboy.txt
    		------------------------
    		find ./ -type f   # 列出当前目录及目录下面所有的文件 包含隐藏文件
    		
    		
    		
    		
    	  
    	find过滤文件: 
    	[root@oldboy~/alex1]#ll
    	总用量 0
    	-rw-r--r--. 1 root root  0 5月  11 11:14 1.txt
    	-rw-r--r--. 1 root root  0 5月  11 11:14 2.txt
    	-rw-r--r--. 1 root root  0 5月  11 11:14 3.txt
    	drwxr-xr-x. 2 root root 22 5月  11 11:15 oldboy1
    	drwxr-xr-x. 2 root root  6 5月  11 11:14 oldboy2
    	drwxr-xr-x. 2 root root  6 5月  11 11:14 oldboy3
    	[root@oldboy~/alex1]#ll oldboy1/
    	总用量 0
    	-rw-r--r--. 1 root root 0 5月  11 11:15 test.txt
    	[root@oldboy~/alex1]#find ./ -type f
    	./1.txt
    	./2.txt
    	./3.txt
    	./oldboy1/test.txt
    	
    	find过滤目录
    	[root@oldboy~/alex1]#find ./ -type d
    	./
    	./oldboy1
    	./oldboy2
    	./oldboy3
    	
    	find按照名称查找
    	[root@oldboy~]#find ./ -type f -name "oldboy.txt"
    	./oldboy.txt
    	
    	find按照匹配规则查找
    	[root@oldboy~/alex1]#find ./ -type f -name "*.txt"
    	./1.txt
    	./2.txt
    	./3.txt
    	./oldboy1/test.txt
    	
    	[root@oldboy~/alex1]#find ./ -type f -name "[1-3].*"
    	./1.txt
    	./2.txt
    	./3.txt
    	[root@oldboy~/alex1]#
    	[root@oldboy~/alex1]#echo {1..3}
    	1 2 3
    	[root@oldboy~/alex1]#echo [1..3]
    	[1..3]
    	[root@oldboy~/alex1]#
    	[root@oldboy~/alex1]#find ./ -type f -name "*.*"    
    	./1.txt
    	./2.txt
    	./3.txt
    	./oldboy1/test.txt
    	./4.TXT
    	./5.TXT
    	./6.TXT
    	./7.TXT
    	
    	
    	find不区分大小写的方式查找文件
    	[root@oldboy~/alex1]#find ./ -type f -name "*.txt"
    	./1.txt
    	./2.txt
    	./3.txt
    	./oldboy1/test.txt
    	[root@oldboy~/alex1]#find ./ -type f -iname "*.txt"
    	./1.txt
    	./2.txt
    	./3.txt
    	./oldboy1/test.txt
    	./4.TXT
    	./5.TXT
    	./6.TXT
    	./7.TXT
    	
    	-type f d l    # 类型
    	-name "*.txt"  # 名字查找文件
    	-iname 		   # 不区分大小写
    	-size          # 按照大写查找文件
    		 -k -M -G  +1M 大于1
    				   -1M 小于1
    	
    	find按照文件的大写进行查找
    	#查找当前目录大于1MB的文件
    	[root@oldboy~]#ll -h
    	-rw-r--r--. 1 root root 1.3M 5月  11 11:41 all.txt
    	-rw-r--r--. 1 root root 9.4M 5月  11 10:22 etc.tar.gz
    	[root@oldboy~]#find ./ -type f -size +1M
    	./etc.tar.gz
    	./all.txt
    	
    	大于5MB的文件
    	[root@oldboy~]#find ./ -type f -size +5M
    	./etc.tar.gz
    	
    	大于1MB并且小于5MB的文件 find 默认是就是并且关系
    	[root@oldboy~]#find ./ -type f -size +1M -size -5M
    	./all.txt
    	
    	[root@oldboy~]#find ./ -type f -size +1M -and -size -5M    # -and 可以省略
    	./all.txt
    	
    	[root@oldboy~]#./etc.tar.gz			& # 可省略
    	./all.txt
    
    	[1]+  完成                  find ./ -type f -size +1M
    
    	find按照深度等级来查找文件 默认查找文件及目录下所有的
    	-maxdepth 最大深度等级
    	[root@oldboy~/alex1]#find ./ -type f
    	./1.txt
    	./2.txt
    	./3.txt
    	./oldboy1/test.txt
    	./oldboy1/alex/alex.txt
    	./4.TXT
    	./5.TXT
    	./6.TXT
    	./7.TXT
    	[root@oldboy~/alex1]#find ./ -maxdepth 2 -type f
    	./1.txt
    	./2.txt
    	./3.txt
    	./oldboy1/test.txt
    	./4.TXT
    	./5.TXT
    	./6.TXT
    	./7.TXT
    	
    	--------------
    	-mtime		  常用
    	-atime
    	-ctime
    	
    	find只能查找出文件或目录  find对查找到的文件后目录如何做操作?
    	cp
    	mv
    	rm
    	ls
    	
    	
    	操作:
    	[root@oldboy~]#file oldboy.txt /etc/passwd /etc/hosts
    	oldboy.txt:  ASCII text
    	/etc/passwd: ASCII text
    	/etc/hosts:  ASCII text
    	 
    	PS:判断上一条命令是否执行成功
    	   echo $?  0为正常 非0失败
    	   
    	   
    	 
    	 tr -d 删除指定的内容
    		-c 取反
    	 tr -cd "a-zA-Z0-9" < /dev/urandom |head -c8
    	 
    	 扩展:如何生成随机数 至少两种方法
    	 
    	 
    	
    	[root@oldboy~]#ping www.baidu.com
    	PING www.baidu.com (10.0.0.200) 56(84) bytes of data.
    	64 bytes from www.baidu.com (10.0.0.200): icmp_seq=1 ttl=64 time=0.064 ms
    	64 bytes from www.baidu.com (10.0.0.200): icmp_seq=2 ttl=64 time=0.026 ms
    	64 bytes from www.baidu.com (10.0.0.200): icmp_seq=3 ttl=64 time=0.028 ms
    	64 bytes from www.baidu.com (10.0.0.200): icmp_seq=4 ttl=64 time=0.033 ms
    	64 bytes from www.baidu.com (10.0.0.200): icmp_seq=5 ttl=64 time=0.044 ms
    	64 bytes from www.baidu.com (10.0.0.200): icmp_seq=6 ttl=64 time=0.026 ms
    	64 bytes from www.baidu.com (10.0.0.200): icmp_seq=7 ttl=64 time=0.028 ms
    	64 bytes from www.baidu.com (10.0.0.200): icmp_seq=8 ttl=64 time=0.028 ms
    	^C
    	--- www.baidu.com ping statistics ---
    	8 packets transmitted, 8 received, 0% packet loss, time 7000ms
    	rtt min/avg/max/mdev = 0.026/0.034/0.064/0.014 ms
    	[root@oldboy~]#ping -c1 -W1 www.baidu.com
    	PING www.baidu.com (10.0.0.200) 56(84) bytes of data.
    	64 bytes from www.baidu.com (10.0.0.200): icmp_seq=1 ttl=64 time=0.053 ms
    
    	--- www.baidu.com ping statistics ---
    	1 packets transmitted, 1 received, 0% packet loss, time 0ms
    	rtt min/avg/max/mdev = 0.053/0.053/0.053/0.000 ms
    	[root@oldboy~]#
    	[root@oldboy~]#ping -c1 -W1 www.baidu.com
    	PING www.baidu.com (10.0.0.200) 56(84) bytes of data.
    	64 bytes from www.baidu.com (10.0.0.200): icmp_seq=1 ttl=64 time=0.019 ms
    
    	--- www.baidu.com ping statistics ---
    	1 packets transmitted, 1 received, 0% packet loss, time 0ms
    	rtt min/avg/max/mdev = 0.019/0.019/0.019/0.000 ms
    	[root@oldboy~]#echo $?
    	0
    	[root@oldboy~]#ping -c1 -W1 www.baidurrr.com
    	ping: www.baidurrr.com: 未知的名称或服务
    	[root@oldboy~]#echo $?
    	2
    	[root@oldboy~]#ping -c1 -W1 www.baidu.com >/dev/null
    	[root@oldboy~]#echo $?
    	0
    	[root@oldboy~]#ping -c1 -W1 www.baidurrr.com >/dev/null
    	ping: www.baidurrr.com: 未知的名称或服务
    	[root@oldboy~]#ping -c1 -W1 www.baiqqdu.com
    	ping: www.baiqqdu.com: 未知的名称或服务
    	[root@oldboy~]#ping -c1 -W1 www.linuxnc.com
    	PING www.linuxnc.com (39.107.76.96) 56(84) bytes of data.
    	64 bytes from 39.107.76.96 (39.107.76.96): icmp_seq=1 ttl=128 time=22.4 ms
    
    	--- www.linuxnc.com ping statistics ---
    	1 packets transmitted, 1 received, 0% packet loss, time 0ms
    	rtt min/avg/max/mdev = 22.479/22.479/22.479/0.000 ms
    	[root@oldboy~]#ping -c1 -W1 www.linuxncc.com
    	ping: www.linuxncc.com: 未知的名称或服务
    	[root@oldboy~]#
    	[root@oldboy~]#ping -c1 -W1 www.baidurrr.com &>/dev/null
    	[root@oldboy~]#
    	[root@oldboy~]#ping -c1 -W1 www.baidurrr.com &>/dev/null
    	[root@oldboy~]#echo $?
    	2
    
    	------------------man帮助
    	[root@oldboy~]#whereis rm
    	rm: /usr/bin/rm /usr/share/man/man1/rm.1.gz
    	[root@oldboy~]#mv /usr/share/man/
    	cs/    fr/    ja/    man1p/ man3/  man4x/ man6x/ man8x/ pl/    sk/    zh_TW/
    	da/    hu/    ko/    man1x/ man3p/ man5/  man7/  man9/  pt/    sv/    
    	de/    id/    man0p/ man2/  man3x/ man5x/ man7x/ man9x/ pt_BR/ tr/    
    	es/    it/    man1/  man2x/ man4/  man6/  man8/  mann/  ru/    zh_CN/ 
    	[root@oldboy~]#mv /usr/share/man/man1/rm.1.gz .
    	[root@oldboy~]#whereis rm
    	rm: /usr/bin/rm
    	[root@oldboy~]#man rm
    	没有 rm 的手册页条目
    
    
    
    小结:
    	入职注意 态度 工作方法
    	文件属性 每列的含义
    	属性列的第一列文件类型
    	-  普通文件 二进制命令 数据文件 压缩
    	d
    	l
    	b
    	c
    	
    	1)which   查看命令的全路径
    	2)whereis 查看命令全路径和该命令的帮助文档的具体路径
    	3)file    查看文件的具体类型
    	4)find    查找文件或目录
    
  • 相关阅读:
    Linux 进程管理
    强大的bat文件搞定系统所有问题
    Java多线程设计要点
    Linux 内核
    Linux 文件和目录管理之列出、删除、复制、移动及改名
    命令dd 及简单应用
    Transferring Files with SFTP or SCP
    简述Linux文件搜索
    加强Eclipse代码自动提示的方法
    Cisco交换机配置新手篇之端口配置
  • 原文地址:https://www.cnblogs.com/weiweivip666/p/14186811.html
Copyright © 2011-2022 走看看