- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Remove only files recursively, to preserve directo...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2007 06:52 PM
04-08-2007 06:52 PM
Being a newbie in UNIX, I'm wondering what's the easiest way to remove all files recursively in a filesystem but preserve the directories structure. I'm looking at ~800GB of data.
My customer has this weird request to remove all the data, but need the directory structure to remain intact.
Appreciate all the help. Thanks.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2007 06:58 PM
04-08-2007 06:58 PM
Re: Remove only files recursively, to preserve directory
$ find root-of-path-to-remove -type f -exec rm -f +
You can pass multiple paths if you need.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2007 08:11 PM
04-08-2007 08:11 PM
Re: Remove only files recursively, to preserve directory
Dennis' solution can be modified as below
$ find root-of-path-to-remove ! -type d -exec rm -f {} +
because as per Dennis' solution it will remove
only files of type file (will not remove directories but will keep device files, named pipes etc.)
-Santosh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2007 11:54 PM
04-08-2007 11:54 PM
Re: Remove only files recursively, to preserve directory
having many files in the directories, it's better to use 'xargs', so no new process needs to be started for the remeval of every single file:
find dir ! -type f | xargs rm
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2007 05:37 AM
04-09-2007 05:37 AM
SolutionHe's right though, if that 800G is composed of lots and lots of files, then xargs would be a much faster solution.
find
Or better yet, all but directories (which is what you asked for).
find
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2007 05:48 AM
04-09-2007 05:48 AM
Re: Remove only files recursively, to preserve directory
As for the use of 'xargs' instead of '-exec' as an argument to 'find', notice that Dennis used the newer "+" termination in lieu of the older ";".
Using '-exec cnd \+' causes bundling (aggregation) of arguments like 'xargs' does; vastly increasing performance. The problem with '-exec cmd \;' is that a new process is spawned for every entity found.
The "+" terminator must be escaped as "+" is special to the shell just like ";". This works on 11.11 and above.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2007 12:25 PM
04-09-2007 12:25 PM
Re: Remove only files recursively, to preserve directory
"+" is not special in any "real" shell that I know of. (Though the man page indicates what you said.) At one time "+" was special for context sensitive files for diskless, but that's gone.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2007 06:34 PM
04-09-2007 06:34 PM
Re: Remove only files recursively, to preserve directory
find dir ! -type d | xargs rm
Rgds,
Art