Linux下批量删除空文件(大小等于0的文件)的方法: find . -name "*" -type f -size 0c | xargs -n 1 rm -f 用这个还可以删除指定大小的文件,只要修改对应的 -size 参数就行,例如: find . -name "*" -type f -size 1024c | xargs -n 1 rm -f 就是删除1k大小的文件.(但注意 不要用 -size 1k,这个得到的是占用空间1k,不是文件大小1k的). 如果只要…
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace 进制转换 { class Program { #region 直接删除指定目录下的所有文件及文件夹(保留目录) /// <summary> ///直接删除指定目录下的所有文件及文件夹(保留目录) /// </summary> ///…
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 { class Program { #region 直接删除指定目录下的所有文件及文件夹(保留目录) /// <summary> ///直接删除指定目录下的所有文件及文件夹…
#region 直接删除指定目录下的所有文件及文件夹(保留目录) /// <summary> /// 直接删除指定目录下的所有文件及文件夹(保留目录) /// </summary> /// <param name="strPath">文件夹路径</param> /// <returns>执行结果</returns> public bool DeleteDir(string strPath) { try { // 清…
不知道大家那有没有要清理的这个事情.需要清理目录历史文件.可能后续也会有很多其他地方需要清理历史文件,可能会用到. 我这两天空闲写了个脚本,清理比较方便,有要进行清理的大量历史文件的话可以用. 脚本用到的命令只有linux才有,像solaris等就不支持,所以只能在linux上运行.如果是nas存储的话,可以挂载到一个linux主机上跑脚本清理. 另外,脚本查找文件用的是ls,但是ls也有最大文件的限度(大概10w以内),如果每天文件很多,每天都是10w+的,运行可能提示文件数过多无法ls. 还…
NULL文件,也有的称为zero文件,即全是二进制/十六进制的0文件 在powershell 中可以按如下方法生成指定大小的zero文件: 只需要修改大小即可,格式如3MB,或者2GB $tempFile=".\QQ5201351\zero.bin" $fs=New-Object System.IO.FileStream($tempFile,[System.IO.FileMode]::OpenOrCreate) $fs.Seek(3MB,[System.IO.SeekOrigin]::…
一.crontab调度 对于linux 自带crontab而言,      xxx.sh的一般编写格式以#!/bin/bash 解释器开头,可在脚本中加入: date 但是,shell脚本执行 需要 x权限,执行的方式如下: ./xxx.sh sh ./xxx.sh 其中,后缀.sh 第一行#!/bin/bash 没有,需要使用sh命令去执行 1.crontab简单调度 [root@localhost ~]# crontab -e no crontab for root - using an e…
原文链接:http://sexywp.com/bash-how-to-get-the-basepath-of-current-running-script.htm 常见的一种误区,是使用 pwd 命令,该命令的作用是“print name of current/working directory”,这才是此命令的真实含义,当前的工作目录,这里没有任何意思说明,这个目录就是脚本存放的目录.所以,这是不对的.你可以试试 bash shell/a.sh,a.sh 内容是 pwd,你会发现,显示的是执行…
需求原因:nginx不具备日志切割功能,日志量较大,方便分析. 实现目的:完成nginx日志切割,并根据时间命名   简要命令: mv /usr/local/tengine/logs/access.log /usr/local/tengine/logs/access-date.log kill -USER1 Nginx主进程号.   解释:      通过mv命令重命名日志,并且通过kill -USER1 nginx-id的命令,告诉nginx需要写新的日志, 不然nginx不会在mv之后继续写…
脚本内容如下: #!/bin/bash function delete_file { days=$[$-] for i in `find $dir -type f -ctime +$days` do rm -rf $i done } while read line do dir=`echo $line |awk '{print $1}'` days=`echo $line |awk '{print $2}'` delete_file $dir $days done < file.txt 其中,函…