1、git不能提交空文件夹
创建一个文件,使用小技巧提交上去
find ./ -type d -empty -execdir touch {}/.gitkeep {} \;
-type -d 搜索文件夹
-empty 只搜索空文件夹
-execdir touch {}/.gitkeep ; 在当前空文件夹下建立文件.gitkeep, .gitkeep只是个名字,可以是其他名字
2、查看某目录下文件信息
目的是查找/u03目录下名称为server.xml的文件,根据查找的结果进行grep搜索,搜索其中包含9080的文本
find /u03 -name server.xml -exec grep '9080' {} \;
<Connector port ="9080" redirectPort ="9443" connectionTimeout ="20000" URIEncoding ="utf-8"
port="9080" protocol="HTTP/1.1"
port="9080" protocol="HTTP/1.1"
<Connector port ="9080" redirectPort ="9443" connectionTimeout ="20000" URIEncoding ="utf-8"
port="9080" protocol="HTTP/1.1"
3、删除指定时间的文件
删除10天前的文件
find /home/user/logs -mtime +10 -type f -exec rm -f {} \;
4、假如在一个目录中保留最近30天的文件,30天前的文件自动删除
find /tmp -mtime +30 -type f -name *.sh[ab] -exec rm -f {} \;
/tmp --设置查找的目录;
-mtime +30 --设置时间为30天前;
-type f --设置查找的类型为文件;
-name *.sh[ab] --设置文件名称中包含sha或者shb;
-exec rm -f {} / --查找完毕后执行删除操作;
注意
在{}和\之间必须要有空格,否则会报错
网友评论