7.15 find及dd等命令练习

find查找文件

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

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

[root@localhost ~]# touch /opt/zbr

[root@localhost  ~]# find / -name "zbr"

/opt/zbr

[root@localhost ~]# find / -name "zbr" -type f

/opt/zbr

[root@localhost  ~]# find / -name "*zb*"

/usr/lib/firmware/mts_mt9234zba.fw

/usr/share/locale/zbl

/usr/share/mime/application/x-nzb.xml

/usr/share/mime/image/vnd.zbrush.pcx.xml

/opt/zbr

[root@localhost  ~]# find /opt/ -name "*zb*"

/opt/zbr

以..为结尾:

[root@localhost  ~]# ls -l /etc/*.conf

-rw-r--r--. 1 root root   55 4月  11 2018 /etc/asound.conf

-rw-r--r--. 1 root root 1108 4月  13 2018 /etc/chrony.conf

Window中的时间

创建,修改,访问时间:stat查看

[root@localhost ~]# stat /opt/zbr

  文件:"/opt/zbr"

  大小:0          块:0          IO 块:4096   普通空文件

设备:fd00h/64768d Inode:34723422    硬链接:1

权限:(0644/-rw-r--r--)  Uid:(    0/    root)   Gid:(    0/    root)

环境:unconfined_u:object_r:usr_t:s0

最近访问:2024-07-15 09:09:10.474719595 +0800

最近更改:2024-07-15 09:09:10.474719595 +0800

最近改动:2024-07-15 09:09:10.474719595 +0800

创建时间:-

[root@localhost ~]# touch /opt/a.txt

创建的时候修改日期,touch 文件名 -m -d “日期时间格式”

[root@localhost ~]# touch /opt/b.txt -m -d "2024-7-14 00:00"

[root@localhost  ~]# touch /opt/d.txt -m -d "2024-7-12 00:00"

[root@olocalhost  ~]# ls -l /opt/

-rw-r--r--. 1 root root        0 7月  15 09:32 a.txt

-rw-r--r--. 1 root root        0 7月  14 00:00 b.txt

使用find按时间搜索,找到旧的文件删掉

[root@localhost ~]# find /opt/ -mtime +3  //三天前的

/opt/d.txt

[root@localhost~]# find /opt/ -mtime -3

/opt/

/opt/zbr

/opt/a.txt

/opt/b.txt

/opt/c.txt

根据时间查找删除:

find /opt/ -mtime +3| rm -rf

[root@localhost ~]# find /opt/ -mtime +3 -exec rm -rf {} \;

追加覆盖:

[root@localhost ~]# vim /opt/a.txt

[root@localhost~]# ls -l /opt/ >> /opt/a.txt

[root@localhost~]# cat /opt/a.txt

总用量 33092

drwxr-xr-x. 6 root root       99 7月   9 00:27 apache-maven-3.9.8

-rw-r--r--. 1 root root  9083702 7月   8 16:25 apache-maven-3.9.8-bin.tar.gz

Size,根据值搜索

搜索文件大于100:

传输文件内容到:

[root@localhost~]# scp -r root@192.168.195.11:/opt/a.txt /opt/b.txt

Please type 'yes' or 'no': yes

root@192.168.195.11's password:

a.txt                                                      100%  948     1.2MB/s   00:00    

[root@localhost~]# cat /opt/b.txt

Scp root@192.168.71.135:/opt/a.txt /opt/

下载,把数据从远程主机保存到本地主机

上传,把本地文件保存到远程主机

传到另一台机子上

[root@localhost~]# scp -r /opt/d0/a.txt root@192.168.195.12:/opt/d1

crontab 选项

-l list查看当前用户的计划任务信息

-e edit编写计划任务

编写任务计划书:crontab 详细路径

[root@localhost ~]# crontab -e    //编写

no crontab for root - using an empty one

crontab: installing new crontab

分时日月钟

[root@localhost ~]# crontab -l

30 * * * * /usr/bin/echo "我是三十分钟执行的" >> /root/echo.txt

*/1 * * * * /usr/bin/echo "我是每分钟都执行的" >> /root/min.txt

[root@localhost  ~]# cat /root/min.txt

每分钟都执行

[root@localhost  ~]# cat /root/echo.txt

三十分钟执行

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

记录了1+0 的读入

记录了1+0 的写出

5242880字节(5.2 MB)已复制,0.0236586 秒,222 MB/秒

[root@localhost  ~]# ls /opt/

aaaa.mp4  aaa.txt  d1

压缩打包:把etc目录下的东西打包载/tmp/etc.tar.gz下

[root@localhost  ~]# tar -zcvf /tmp/etc.tar.gz /etc

[root@localhost ~]# ls /tmp

etc.tar.gz

[root@localhost  ~]# crontab -l

*/2 * * * * /usr/bin/tar -zcvf /tmp/etc.tar.gz /etc/  //每两分钟打包一次

[root@localhost  ~]# rm -rf /tmp/etc.tar.gz

/var/spool/mail/root有新文件,//不理解但后面ls /tmp的时候有文件etc.tar.gz

[root@localhost  ~]# crontab -l  //在脚本中出现%得用转义符\

*/1 * * * * /usr/bin/tar -zcvf /tmp/etc_$(date "+\%Y \%m \%d \%h").tar.gz /etc/  //每分钟都打印一个包

[root@localhost  ~]# ls /tmp/

etc_202407157月.tar.gz

  • 14
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值