首页 > 其他分享 >LIUNX中关于find以及dd的命令练习

LIUNX中关于find以及dd的命令练习

时间:2024-07-17 18:54:11浏览次数:16  
标签:opt test0 dd web1 LIUNX test txt root find

使⽤ls查看/etc/⽬录下所有的⽂件信息
[root@web1 ~]# ls /etc/

2.使⽤ls查看/etc/⽬录下名包含“a”字⺟的⽂件或者⽬录信息

[root@web1 ~]# ls /etc/*a*

3.使⽤ls查看/etc/⽬录下以".conf"结尾的⽂件信息

[root@web1 ~]# ls /etc/*.conf

4.使⽤ls查看/etc/⽬录中以"y"字⺟开头的⽂件信息

[root@web1 ~]# ls /etc/y*

5.find查找/var/⽬录中以“.log”⽂件

[root@web1 ~]# find /var/  -name "*.log" -type f

-name 根据文件的名称搜索文件,支持通配符*

-type f代表普通文件,d代表目录

6.在opt⽬录下创建test⽬录

[root@web1 ~]# mkdir /opt/test

7.在test⽬录中创建abc.txt,def.txt.ghi.txt,xxx.txt.yyy.txt五个⽂件

[root@web1 ~]# cd /opt/test/

[root@web1 test]# touch  abc.txt def.txt ghi.txt xxx.txt yyy.txt

[root@web1 test]# ls

abc.txt  def.txt  ghi.txt  xxx.txt  yyy.txt

8.修改以上5个⽂件的最后修改时间分别为15,14,13,12,11,10⽇

查看目前的状态:[root@web1 test]# stat abc.txt def.txt ghi.txt xxx.txt yyy.txt

[root@web1 test]# touch -m -d "2024-7-15" /opt/test/abc.txt

[root@web1 test]# touch -m -d "2024-7-14" /opt/test/def.txt

[root@web1 test]# touch -m -d "2024-7-13" /opt/test/ghi.txt

[root@web1 test]# touch -m -d "2024-7-12" /opt/test/xxx.txt

[root@web1 test]# touch -m -d "2024-7-11" /opt/test/yyy.txt

9.在test⽬录下创建a⽬录

[root@web1 test]# mkdir a

10.将以上5个⽂件复制⼀份到a⽬录中

[root@web1test]#cp/opt/test/{abc.txt,def.txt,ghi.txt,xxx.txt,yyy.txt} /opt/test/a/

11.将a⽬录⽂件做成bak.tar.gz⽂件保存到家⽬录中

[root@web1 ~]# tar -zcf /home/bak.tar.gz /opt/test/a

12.使⽤find删除test⽬录下3天前的⽂件

[root@web1 ~]# find /opt/test/ -name "*.txt" -type f -mtime +3 |xargs rm -rf

13. find删除opt⽬录下3天内的⽂件

[root@web1 ~]# find /opt/test/ -name "*.txt" -type f -mtime -3 |xargs rm -rf

14.find删除正好第三天的⽂件

[root@web1 ~]# find /opt/test/ -name "*.txt" -type f -mtime  3 |xargs rm -rf(/opt/test下的目录.txt文件全部删除万了)


15.将/opt/test/a⽬录中的⽂件复制i⼀份到/opt/test/⽬录下
 [root@web1 opt]# cp /opt/test/a/* /opt/test/

16.创建⽬录/opt/test0

[root@web1 test]# mkdir /opt/test0

17.在/opt/test0/⽬录中创建三个⽂件 a.mp4(5M),b.mp4(20M),c.mp4(80M)

[root@web1 ~]# dd if=/dev/zero of=/opt/test0/a.mp4 bs=5M count=1

记录了1+0 的读入

记录了1+0 的写出

5242880字节(5.2 MB)已复制,0.0186486 秒,281 MB/秒

[root@web1 ~]# dd if=/dev/zero of=/opt/test0/b.mp4 bs=20M count=1

[root@web1 ~]# dd if=/dev/zero of=/opt/test0/c.mp4 bs=80M count=1

18.创建⽬录/opt/test0/b/

[root@web1 ~]# mkdir /opt/test0/b

19.将/op t/test0/中的⽂件复制⼀份/opt/test0/b/⽬录中

[root@web1 ~]# cp -r /opt/test0/*.mp4 /opt/test0/b

[root@web1 ~]# ls /opt/test0/b

a.mp4  b.mp4  c.mp4

20. find查询/opt/test0/⽬录中⽂件⼤于20M的,并删除

[root@web1 ~]# find /opt/test0 ./ -size +20M -exec rm -rf {} \;

[root@web1 ~]# ls -lh /opt/test0

总用量 5.0M

-rw-r--r--. 1 root root 5.0M 7月  15 18:55 a.mp4

21.find查询/opt/test0/⽬录中⽂件⼩于20M的⽂件并删除

 [root@web1 ~]#find /opt/test0/ -size -20M | xargs rm -rf 

22.find查找/opt/test0/⽬录中⽂件size为20M的⽂件并删除

[root@web1 ~]#find /opt/test0/ -size 20M | xargs rm -rf

23./opt/test0/b中的⽂件复制⼀份到/opt/test0中

[root@web1 ~]# cp -r /opt/test0/b /opt/test0

24.打开新的虚拟主机

25.将家⽬录中的bak.tar.gz⽂件上传到新主机的/opt⽬录中

[root@web1 ~]# scp /home/bak.tar.gz [email protected]:/opt/

26.将新主机的/e tc/skel/⽬录下载到 当前主机的/opt⽬录中

[root@web1 ~]# scp [email protected]:/etc/skel/ /opt/

27. 设置计划任务,每周3将/e tc/yum.repos.d/⽬录下的.repo⽂件压缩保存到tmp,在⽂件

名中添加时间戳

[root@web1 ~]# crontab -e

 * * * * 3 /usr/bin/tar -zcvf /tmp/etc-$(date "+\%Y\%m\%d\%H\%M\%S").tar.gz

/etc/yum.repos.d/*.repo

标签:opt,test0,dd,web1,LIUNX,test,txt,root,find
From: https://blog.csdn.net/m0_72618941/article/details/140473780

相关文章

  • 测试驱动开发(TDD)三大定律
    定律一:在编写不能通过的单元测试前,不可编写生产代码。解释:这条定律的意思是,你不能直接编写实现功能的生产代码,而是在开始之前需要先编写一个单元测试来验证这个功能。这个单元测试应该是你期望生产代码通过的测试。只有在有了这个测试之后,你才能开始编写生产代码。目的:确保每......
  • LongAdder 比 AtomicLong 性能更好
    一、LongAdder入门API文档地址:https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/atomic/LongAdder.html构造方法:初始值为0LongAdder()方法:add(longx)decrement()//减1increment()//加1toString()二、LongAdder于AtomicLong性能比较通过案例比......
  • MySQL数据库基础教程(DDL、DML、DQL…)
    MySQL数据库基础教程:DDL、DML、DQL…文章目录1概述2数据库设计——DDL2.1数据库操作2.2表操作2.2.1约束2.2.2数据类型3数据库操作——DML4数据库查询——DQL4.1基本查询4.2条件查询4.3分组查询4.4排序查询4.5分页查询5多表设计5.1一对多5.2一对一5.3......
  • 从DDPM到DDIM
    从DDPM到DDIM(一)现在网络上关于DDPM和DDIM的讲解有很多,但无论什么样的讲解,都不如自己推到一边来的痛快。笔者希望就这篇文章,从头到尾对扩散模型做一次完整的推导。DDPM是一个双向马尔可夫模型,其分为扩散过程和采样过程。扩散过程是对于图片不断加噪的过程,每一步添加少量的高......
  • NetCore消息管道 Middleware
    中间件定义///<summary>///自定义中间件1///</summary>publicclassMyMiddleware:IMiddleware{publicasyncTaskInvokeAsync(HttpContextcontext,RequestDelegatenext){Console.WriteLine("MyMiddleware_1,开始处理");aw......
  • [ABC347E] Set Add Query题解
    思路通过读题发现,每个数变化当且仅当这个数在集合内。所以不妨设它被添加进来的时间点为\(L_i\),它被删除的时间点为\(R_i\),所以它被增加的数量就是这段时间内集合数量之和。所以用一个变量\(cnt\)模拟当前集合内有多少个数,前缀和维护即可。具体实现参见代码。代码#include<......
  • [ABC258Ex] Odd Steps 题解
    思路拿到这道题,第一时间肯定想到是\(dp\)题目。朴素DP用\(dp_i\)表示序列和为\(i\)的序列个数。因为原数组由奇数组成,所以\(dp\)只可能由\(dp_{i-1}\),\(dp_{i-3}\)等等转移过来,若\(i\inA\),\(dp_i=0\)。即:\[dp_i=\begin{cases}0&i\inA\\dp_{i-1}+dp_{i-3}+\c......
  • 端口被占用如何处理Error: listen EADDRINUSE: address already in use :::xxxx
    启动项目出现Error:listenEADDRINUSE:addressalreadyinuse:::9088yarnrunv1.22.19$nodesrc/index.jsevents.js:377thrower;//Unhandled'error'event^Error:listenEADDRINUSE:addressalreadyinuse:::9088atServer.setupL......
  • 数据库 -- DDL
    DDL,全称DataDefinitionLanguage,是数据库管理系统中的一种语言,用于定义和管理数据库中的数据结构。DDL主要包括以下几种语句:1、CREATE:用于创建数据库、表、索引等数据库对象。2、ALTER:用于修改数据库、表、索引等数据库对象。3、DROP:用于删除数据库、表、索引等数据库对......
  • 云计算实训06——find、stat、touch、tree、scp、crontab指令相关应用
    一、find命令1.find的作用:对文件进行搜索2.基本语法:                    find[文件路径][选项选项的值]3.常见的选项-name根据文件的名称搜索文件,支持通配符*-typef 代表普通文件,-typed代表目录4.*通配符在l......