目录中删除所有文件(没有在他们接触任何文件夹或任何东西) [英] Remove all files in a directory (do not touch any folders or anything within them)

查看:109
本文介绍了目录中删除所有文件(没有在他们接触任何文件夹或任何东西)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否 RM 可以删除一个目录中的所有文件(但不包括子文件夹中的子文件夹或文件)?

I would like to know whether rm can remove all files within a directory (but not the subfolders or files within the subfolders)?

我知道有些人是:

rm -f /direcname/*.*

但是这是假定的文件名具有不是所有的都(我想要的所有文件 - 有或没有延伸到被移除)的扩展。

but this assumes the filename has an extension which not all do (I want all files - with or without an extension to be removed).

推荐答案

虽然找到,您可以使用 -exec RM {} \\删除文件; 您可以使用

Although find allows you to delete files using -exec rm {} \; you can use

find /direcname -maxdepth 1 -type f -delete

和它比较快。使用-delete意味着-depth选项,目录之前,这意味着进程目录的内容。

and it is faster. Using -delete implies the -depth option, which means process directory contents before directory.

这篇关于目录中删除所有文件(没有在他们接触任何文件夹或任何东西)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆