ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

python 全栈 day07 软链接

2020-11-07 19:02:03  阅读:218  来源: 互联网

标签:oldboyedu tar python day07 全栈 hosts txt root find


Day07复习总结
Cpu负载
1.查看负载 w 或 cat /proc/loadavg
什么是负载
负载衡量我们操作系统繁忙程度 负载值越高 说明系统越繁忙 压力越大 处理数据越慢
什么硬件导致负载过高: CPU 磁盘 读写 IO
达到什么值才能说明系统负载已经过高?
负载的值达到接近于我们的总的核心数量 说明负载过高 非常繁忙
4核心====负载值最高4 说明繁忙

使用命令进行查看
Uotime
08:48:49 up 18 min, 1 user, load average: 0.02, 0.03, 0.05
当前时间 运行了多久 当前登录用户数 平均负载 1分钟 5分钟 15分钟

知识点回顾
33584647 -rw-r--r-- 1 root root 1048576000 Nov 5 11:20 1g.txt
第一列
inode号 索引 block 4k
第二列
权限位 文件类型
-普通文件 二进制文件 数据文件
d目录
b块设备 硬件设备 磁盘表示方式 第一块磁盘sda 第一个分区 sda1 第二个分区 sda2 第三个分区 sda3 第二块磁盘 sdb
c字节设备
/dev/urandom
/dev/zero
/dev/null

1>标准正确输出重定向

2>标准错误输出重定向
2>>
把执行命令输出的结果 重定向到文件或是null中
生成数据文件
dd if=/dev/zero of=./test.txt bs=1M count =10000
S
P
rw-r--r--
三位一组权限位

课程大纲
软链接
硬链接
文件类型 压缩包 打包压缩 解压
如何查找目录下所有的普通文件 目录 软链接
find文件相关命令
1.软链接 类似于windows的快捷方式
特点
类似于windows快捷方式
创建软链接 ln -s
文件和目录都可以做软链接
删除软链接不影响源文件
删除源文件软链接失效
inode号码不同
文件类型不同 -l
最好使用绝对路径创建
ln -s/etc/hosts test.hosts
lrwxrwxrwx 1 root root 10 Nov 6 09:52 test.hosts -> /etc/hosts

软链接的作用
可以跨文件系统(磁盘)
补充:
fdisk -l
feisk 分区
mkfs.xfs (路径/dev/sdb)格式化
mount /dev/sdb /mnt (挂载)
df-h 看一下

mv 1g.txt(源文件名)/mnt/(目标路径)
ln -s /mnt.txt lg.txt

2.硬链接 文件的多个入口 类似于超市的多个门
硬链接特点
创建硬链接ln 源文件 目标文件
目录无法做硬链接
只能对文件做硬链接
不能跨文件系统
默认目录硬链接数量为2 文件为1
删除一个硬链接 对文件无影响力 同事删除所有的硬链接
删除源文件不影响
只要硬链接数为0 inode为0 没有被进程调用文件才被真正的删除
硬链接的作用:
文件安全
把重要的文件做硬链接 防止误删操作 实时备份
in passwd passwd.bak
ll -i passwd passwd.bak
3.文件压缩为什么要使用文件压缩 什么情况下使用压缩
备份 数据传输 从服务器把数据备份到备份服务器 需要打包
1.节省磁盘空间
2.减少带宽使用
3.减少负载 减少IO操作
tar 命令打包
语法格式
tar zcvf(包的名字).tar.gz 打包的内容 多个文件 多个目录
参数: z 压缩
c 创建
v显示过程
f指定文件名称
x解压缩
c指定解压缩的位置
t查看文件中的文件名称
打包文件:

打包当前的hosts文件

tar zcvf hosts.tar.gz hosts

打包多个文件

tar zcvf hosts.tar.gz hosts oldboy.txt passwd
打包目录 tar zcf etc.tar.gz /etc
不让提示 使用相对路径打包 tar zcf etc.tar.gz etc
打包后的文件直接放在某个目录
[root@oldboyedu /]# ll /opt/
total 0
[root@oldboyedu /]# tar zcf /opt/etc.tar.gz etc
[root@oldboyedu /]# ll opt/
total 10012
-rw-r--r-- 1 root root 10248462 Nov 6 10:42 etc.tar.gz

			解压
			[root@oldboyedu opt]# tar xf hosts.tar.gz 
			解压到固定的位置
			[root@oldboyedu ~]# ll /opt/
			total 0
			[root@oldboyedu ~]# tar xf /tmp/hosts.tar.gz -C /opt/
			[root@oldboyedu ~]# ll /opt/
			total 82516
			-rw-r--r-- 1 root root 84485563 Nov  5 10:43 hosts
			-rw-r--r-- 1 root root       85 Nov  4 10:56 oldboy.txt
			-rw-r--r-- 1 root root      986 Nov  6 10:16 passwd

			
			查看压缩包中的文件名称
			
			[root@oldboyedu ~]# tar tf /tmp/hosts.tar.gz 
			hosts
			oldboy.txt
			passwd

			批量打包文件中的内容
			--exclude=PATTERN  排除不需要打包的文件
			[root@oldboyedu ~]# tar zcvf test.tar.gz --exclude=all.hosts ./*
			./all.tar.gz
			./dir/
			./dir/oldboy/
			./hehe.txt
			./hosts
			./oldboy.txt
			./passwd
			./test.
			./test.avi
			./test.sh

			--exclude-from=FILE
			[root@oldboyedu ~]# tar zcvf test.tar.gz --exclude-from=exclude.txt ./*
			./exclude.txt
			./passwd
			./test.
			./test.avi
			./test.sh

zip
打包
zip 包名字 需要打包的内容
解压
unzip 包名字
-d 指定解压的位置
4.find 查找文件或目录
find格式:
find /data -type f
find /data -type f -name "name"
find /公司 -类型 身材好 -姓名 "fengjie"

	   [root@oldboyedu ~]# find ./ -type f 		# 查找当前目录 并且显示隐藏文件  默认显示目录及目录以下所有符合的文件
	   

		[root@oldboyedu dir]# find ./ -type f -name "1.txt"	# 按照名称查找
		./1.txt

		* 表示匹配任意的字符
		[root@oldboyedu dir]# find ./ -type f -name "*.txt"	# 匹配以.txt结尾的文件
		./oldboy/test.txt
		./1.txt
		./2.txt
		./3.txt
		./4.txt
		./5.txt

		[root@oldboyedu dir]# find ./ -type f -name "*.bak"
		./oldboy.bak

		[root@oldboyedu dir]# find ./ -type f -name "[1-3].txt"
		./1.txt
		./2.txt
		./3.txt


		[root@oldboyedu dir]# find ./ -type f -name "1.t?t"		# 通配符匹配  ?代表任意单个字符 大部分命令都支持
		./1.txt


	   [root@oldboyedu dir]# cat 1.txt
		123456
		123456789
		12
		[root@oldboyedu dir]# cat 1.txt|wc -L
		9
		[root@oldboyedu dir]# echo abrt-action-analyze-vmcore|wc -L
		26

	   [root@oldboyedu dir]# cat /etc/passwd|sed -r 's#[:\]# #g'|xargs -n1|sort |uniq -c|sort -rn

	

	    find 按照大小查找 
			 -size k M G
			 
			[root@oldboyedu ~]# find ./ -type f -size +90M		# 查找大于90M的文件
			./all.hosts
		
			[root@oldboyedu ~]# find ./ -type f -size -90M		# 查找小于90M的文件

		    查找大于80并且小于90的文件
			-and  并且 
			-or   或者
			[root@oldboyedu ~]# find ./ -type f -size +80M -and -size -90M
			./hosts

			[root@oldboyedu ~]# find ./ -type f -size +80M -or -size +600M
			./hosts
			./all.hosts

			find默认就是并且关系
			[root@oldboyedu ~]# find ./ -type f -size +80M  -size -90M
			./hosts

		文件的大小是否在目录上能够看到 能够体现?
		不会影响目录的大小
		如何影响目录的大小 目录中存放着下级的所有的文件名和目录名
		文件越多 目录越大  小文件过多 inode不够用
		如何找小文件 目录越大 小文件越多
		find ./ -type d -size +1M
		
		find dir/ -type f -name "*.txt"|xargs rm

		
		[root@oldboyedu ~]# du -h
		0	./.pki/nssdb
		0	./.pki
		0	./dir/oldboy
		651M	./dir
		731M	.
		[root@oldboyedu ~]# du -h dir/
		0	dir/oldboy
		651M	dir/
		[root@oldboyedu ~]# du -h dir/*
		651M	dir/all.hosts
		0	dir/oldboy
		0	dir/oldboy.bak

		
		
		[root@oldboyedu ~]# du -h /mnt
		9.8G	/mnt
		[root@oldboyedu ~]# du -h /mnt/*
		9.8G	/mnt/10g.txt

		
		find查找到的文件 如何cp rm move
		方法1: cp
		      [root@oldboyedu ~]# find ./ -type f -name "test.sh"|xargs -i cp {} /opt
	    方法2: cp 
			  [root@oldboyedu ~]# find ./ -type f -name "test.sh" -exec cp {} /tmp \;
				[root@oldboyedu ~]# ll test.sh /tmp/test.sh 
				-rwxr-xr-x. 1 root root 4 Nov  3 11:31 test.sh
				-rwxr-xr-x  1 root root 4 Nov  6 12:05 /tmp/test.sh
		      
		方法3: cp 
				[root@oldboyedu ~]# cp `find ./ -type f -name "test.sh"` /etc/

		
		作业:rm mv 使用三种方法测试
		
		
		; 在shell命令行特殊的含义 命令的分隔符
		
		[root@oldboyedu ~]# ls;ll;pwd;cd

                    -------------------180天计划

7/180
加油 努力

标签:oldboyedu,tar,python,day07,全栈,hosts,txt,root,find
来源: https://www.cnblogs.com/0jiaqing0/p/13941918.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有