rm -f filename
删除一个目录
rmdir dirname
删除一个目录(包括子目录)
rm -fr dirname
拷贝文件
cp filenmae destpath -f
system(cmd)
所以你要做的就是拼一个字符串
char cmd[128]
memset(cmd,0, 128)
sprintf(cmd,"rm -f %s",filename)
仅供参考
linux下快速删除大量文件假如你要在linux下删除大量文件,比如100万、1000万,像/var/spool/clientmqueue/的mail邮件,像/usr/local/nginx/proxy_temp的nginx缓存等,那么rm -rf *可能就不好使了。rsync提供了一些跟删除相关的参数 rsync --help grep delete --del an alias for --delete-during --deletedelete files that don't exist on the sending side --delete-before receiver deletes before transfer (default) --delete-during receiver deletes during transfer, not before --delete-after receiver deletes after transfer, not before --delete-excludedalso delete excluded files on the receiving side --ignore-errors delete even if there are I/O errors --max-delete=NUMdon't delete more than NUM files其中--delete-before 接收者在传输之前进行删除 *** 作可以用来清空目录或文件,如下:1、先建立一个空目录mkdir /data/blank2、用rsync删除目标目录rsync --delete-before -d /data/blank/ /var/spool/clientmqueue/这样目标目录很快就被清空了又假如你有一些特别大的文件要删除,比如nohup.out这样的实时更新的文件,动辄都是几十个G上百G的,也可 以用rsync来清空大文件,而且效率比较高1、创建空文件touch /data/blank.txt2、用rsync清空文件rsync -a --delete-before --progress --stats /root/blank.txt /root/nohup.outbuilding file list ...1 file to considerblank.txt 0 100% 0.00kB/s 0:00:00 (xfer#1, to-check=0/1)Number of files: 1Number of files transferred: 1Total file size: 0 bytesTotal transferred file size: 0 bytesLiteral data: 0 bytesMatched data: 0 bytesFile list size: 27File list generation time: 0.006 secondsFile list transfer time: 0.000 secondsTotal bytes sent: 73Total bytes received: 31 sent 73 bytes received 31 bytes 208.00 bytes/sectotal size is 0 speedup is 0.00tips:当SRC和DEST文件性质不一致时将会报错当SRC和DEST性质都为文件【f】时,意思是清空文件内容而不是删除文件当SRC和DEST性质都为目录【d】时,意思是删除该目录下的所有文件,使其变为空目录最重要的是,它的处理速度相当快,处理几个G的文件也就是秒级的事最核心的内容是:rsync实际上用的就是替换原理作者 张慧函数名: remove
功 能: 删除一个文件
用 法: int remove(char *filename)
程序例:
#include <stdio.h>int main(void)
{
char file[80]
/* prompt for file name to delete */
printf("File to delete: ")
gets(file)
/* delete the file */
if (remove(file) == 0)
printf("Removed %s.\n",file)
else
perror("remove")
return 0
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)