加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

六、Linux计划任务及压缩归档

发布时间:2020-12-13 23:43:12 所属栏目:Linux 来源:网络整理
导读:1. find:用来查找文件 格式:find 目录名 选项 参数 -a … ? -name ?根据名称查找 find /?-name "ww" find / -name "ken*" | xargs rm -rf ? -perm 权限(为完全匹配,-为包含匹配 find / -perm 777 Ls -ld / 随便查看一个 find / -perm 444 Ls -ld / 随便

1. find:用来查找文件

格式:find 目录名 选项 参数 -a …

?

-name

?根据名称查找

find /?-name "ww"

find / -name "ken*" | xargs rm -rf

?

-perm

权限(为完全匹配,-为包含匹配

find / -perm 777

Ls -ld / 随便查看一个

find / -perm 444

Ls -ld / 随便查看一个

?

-user

匹配所有者

Find / -user ken

?

-group

?属组

-mtime:修改时间

Find / -mtime +2

-atime: 访问时间

-ctime: 修改时间

?

-nouser

匹配无用户所有者文件

find / -nouser

?

-nogroup

匹配无组所有者文件

?

-type

f/d/l/b/c/p 匹配文件类型

?

-size:

?+ - ?匹配文件大小

?

-exec:

?- nouser -exec 命令 {} ;

find /ww -name “*txt”-exec rm -rf {} ;

find /ww -name “*txt”| xargs rm -rf

?

2. tar 压缩归档

-c: 创建

-z: gzip 压缩

-v: 显示过程

-f: 指定包名

-x: 解压

?

zip 结尾的包:unzip

gz 结尾的包:gunzip

tar.gz 结尾的包:xzvf

?

?

常用选项组合:

压缩归档

czvf

减压

xzvf

?

?

?

案例:

压缩归档:

tar czvf files.tar.gz./*

Mkdir / test

Cp files.tar gz /test ???(gz : gzip )

Cd /test

Ls

?

解压: tar xzvf files.tar.gz

tar xzvf files.tar.gz -C /ww 指定解压到哪个目录下

unzip ; ww.zip

yum install unzip -y

mount /dev/cdrom/mnt挂载硬件

yum install unzip -y

unzip ?ww.zip

cd ww

?

3.计划任务

at :一次性计划任务:at (atd):执行完退出

?

实例:

1. 下载at程序

?yum install at -y

2. 启动atd服务

?systemctl restart atd

?systemctl ?enable ?atd ?开机自启

3. 设置at计划任务

[[email?protected] ~]# at 10:00???????????????????????

at> touch /tmp/test1 ????????????????????????#输入你要执行的命令

at> <EOT> ???????????????????????????????????#按ctrl+d保存

job 1 at Fri Mar ?1 10:00:00 2019

[[email?protected] ~]# at -l ?????????????????????????#查看计划任务1????Fri Mar ?1 10:00:00 2019 a root

[[email?protected] ~]# atq ???????????????????????????#查看计划任务1????Fri Mar ?1 10:00:00 2019 a root

?

(ctrl + backspace删除)

atq 查看计划任务或者 at-l

按ctrl d 保存

删除计划任务atrm

?At -l查看

atrm 名字 ?删除

?

5. at计划任务的特殊写法

[[email?protected] ~]# at 20:00 2018-10-1???在某天

[[email?protected] ~]# at now +10min ??在 10分钟后执行

[[email?protected] ~]# at 17:00?tomorrow ??明天下午5点执行

[[email?protected] ~]# at 6:00?pm +3?days ??在3天以后的下午6点执行

?

?

4.周期性计划任务:crontab

?

作用:定时任务的使用

-l: list 查看计划任务

-e: edit编辑计划任务

-r: remove 删除计划任务

-u: user指定用户

?

四个符号:

?

*:表示取值范围中的每一个数字

-:做连续区间表达式的,要想表示1~7,则可以写成:1-7

/: 每隔,例如:每隔10分钟一次,则可以在分的位置写:*/10

,:表示多个取值,比如想在1点,2点6点执行,则可以在时的位置写:1,2,6

编写格式:

*

?*

?*

*

?* ?

绝对路径

执行命令

?

minute

hour

?日

Day of month

month

Day of week

?

?

0~59?

0~23?

1~31?

1~12

0~7

0和7表示星期天

?

?

?

实例:

1. 查看进程是否启动

[[email?protected] ~]# ps aux | grep crond

root ???????621 ?0.0 ?0.3 126284 ?1600 ? ???????Ss ??17:46 ??0:00 /usr/sbin/crond -n

root ??????1194 ?0.0 ?0.1 112704 ??956 pts/0 ???S+ ??18:05 ??0:00 grep --color=auto crond

2. 查看计划任务

[[email?protected] ~]# crontab -l

no crontab for root

3. 编写计划任务

支持#号注释,不执行。

[[email?protected] ~]# crontab -e ??????????????????

?#编写计划任务* * * * * echo "123"?>> /root/ken.txt ??????

[[email?protected] ~]# tail -f ken.txt ????????????

??#查看计划任务执行结果123123

?

4. 删除计划任务

[[email?protected] ~]# crontab -l* * * * * echo "123"?>> /root/ken.txt

[[email?protected] ~]# crontab -r

[[email?protected] ~]# crontab -l

no crontab for?root

?

0 1 * * * /usr/bin/tar czf ` touch $ (date “+%F””)` ?/ww

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读