find at tar命令详解

一、find命令

1.背景

linux操作系统下一切皆文件,find命令是十分好用的查找文件的命令,如果使用find命令不设置任何参数的话,find命令将在当前目录下查找匹配的内容,

并将查找到的子目录和文件全部显示,经常与通配符联合使用。

2.语法、参数

find命令格式

find path -option [-print] [-exec -ok command] {} \

find参数介绍

1)path 要查找的目录

2)print 表示将结果输出到标准输出(查找目录并列出目录下的文件,为找到的每一个目录单独执行ls命令,没有选项-print时,文件列表前一行不会显示目录名称)

3)exec 对匹配的文件执行该参数所给出的shell命令

4)ok 与exec作用相同,区别在于在执行命令之前会给出提示,让用户确认是否执行

5)command shell命令

6)option 选项

常用选项如下:

-name filename 查找名为filename的文件

-perm 按执行权限来查找

-user username  按文件属主来查找

-group groupname 按文件属组来查找

-mtime -n +n 按文件更改时间来查找文件,-n指n天以内,+n指n天以前

-atime -n +n 按文件的访问时间来查找,-n指n天以内,+n指n天以前

-ctime -n +n 按文件的创建时间来查找,-n指n天以内,+n指n天以前

-nouser 查找无有效属主的文件即文件的属主在/etc/passwd中不存在

-nogroup 查找无有效属组的文件即文件的属组在/etc/groups中不存在

-type  b/d/c/p/l/f 查是块设备、目录、字符设备、管道、符号链接、普通文件

-prune 忽略某个目录

-size 匹配文件的大小+50KB为查找超过50KB的文件-50KB表示查找小于50KB的文件

3.find实战举例

在根目录下查找名为etc的文件或目录

[root@andy ~]# find / -name etc
/run/initramfs/state/etc
/etc
/usr/etc
/usr/local/etc
[root@andy ~]#

在根目录下查找只有执行权限的文件

[root@andy ~]# find / -perm 200

在根目录下查找属主为andy1的文件

[root@andy ~]# find / -user andy1

在根目录下查找属组为andy2的文件

[root@andy ~]# find / -group andy2

在根目录下查找一天内的更改过的文件

[root@andy ~]# find / -mtime -1

在根目录下查找一天内访问过的文件

[root@andy ~]# find / -atime -1

在根目录下查找一天内创建的文件

[root@andy ~]# find / -ctime -1

二、at命令

1.介绍

在linux系统下有两个命令可以用来作为计划任务而执行,

at:一次性定时计划执行

crontab:周期定时任务计划执行

2.安装

1)下载at程序

[root@andy ~]# yum install at -y

2)启动服务

[root@andy ~]# systemctl start atd

3)查看是否启动成功

[root@andy ~]# ps aux | grep atd
root 2420 0.0 0.0 25844 932 ? Ss 19:20 0:00 /usr/sbin/atd -f
root 2423 0.0 0.0 112664 972 pts/0 R+ 19:21 0:00 grep --color=auto atd
[root@andy ~]#

3.at应用

at计划任务的特殊写法

在某天 :[root@andy ~]# at 20:00 2019-12-18

在10min后执行:[root@andy ~]# at now +10min

明天下午5点执行:[root@andy ~]# at 17:00 tomorrow 

在3天后的下午6点执行:[root@andy ~]# at 6:00 pm +3 days

at实战(保存、查看、删除)

[root@andy ~]# at 22:00                                        #在22点设置任务

at> ls /root                                                                #在22点列出root下的目录
at> <EOT>                                                               # crtl +d保存at的计划
job 6 at Tue Dec 17 22:00:00 2019

[root@andy ~]# at -l                                                 #列出当前的at计划
6 Tue Dec 17 22:00:00 2019 a root

[root@andy ~]# atq                                                   #第二种查看at计划任务命令
6 Tue Dec 17 22:00:00 2019 a root

[root@andy ~]# atrm 6                                              #删除编号为6的计划任务

三、tar命令

1.介绍

tar是linux下最常用的打包程序,使用tar程序打出来的包称为tar包,tar包文件的命令通常都是以.tar结尾的,生成tar包就可以使用其他命令压缩了

2.参数

常用选项

-c创建压缩文件

-x解开压缩文件

-t查看压缩包内有那些文件

-z用Gzip压缩或解压

-j用bzip2压缩或解压

-v显示压缩或解压的过程

-f目标文件名

-p保留原始的权限与属性

-P使用绝对路径来压缩

-C指定解压到的目录

常用参数

czvf:创建压缩文件

xzvf:解压缩

3.压缩

[root@andy test]# touch test{1,2,3,4,5,6}

[root@andy test]# tar czvf test.tar .
./
./test1
./test2
./test3
./test4
./test5
./test6
./test.tar
[root@andy test]# ls
test1 test2 test3 test4 test5 test6 test.tar

4.解压缩

[root@andy ~]# tar xzvf test.tar.gz
./
./test1
./test2
./test3
./test4
./test5
./test6

posted @ 2019-12-17 23:55  Y_Andy  阅读(524)  评论(0编辑  收藏  举报