- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Remove contents of directory but not the directory...
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
Discussions
Discussions
Forums
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
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
тАО01-10-2003 05:53 AM
тАО01-10-2003 05:53 AM
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-10-2003 05:58 AM
тАО01-10-2003 05:58 AM
Re: Remove contents of directory but not the directory itself
rm -rf *
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-10-2003 05:59 AM
тАО01-10-2003 05:59 AM
Re: Remove contents of directory but not the directory itself
rm /dir/*
You can use the -i option to confirm deletes.
Tom
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-10-2003 06:02 AM
тАО01-10-2003 06:02 AM
Re: Remove contents of directory but not the directory itself
I.E.
% rm /dir/.??*
or
% cd /dir
% rm -rf .??*
Notice that there are two place holders to ensure that neither "." nor ".." are removed, as that is the current and parent directories.
Regards,
Shannon
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-10-2003 06:03 AM
тАО01-10-2003 06:03 AM
Re: Remove contents of directory but not the directory itself
# rm -rf *
Regards ...
Armin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-10-2003 06:06 AM
тАО01-10-2003 06:06 AM
Re: Remove contents of directory but not the directory itself
rm -fr *
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-10-2003 07:28 AM
тАО01-10-2003 07:28 AM
Re: Remove contents of directory but not the directory itself
rm -fr *
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-10-2003 07:29 AM
тАО01-10-2003 07:29 AM
SolutionWhile:
# cd /dir
# rm /dir/*
...will accomplish what you seek in most cases, the shell's expansion of "*" may exceed ARG_MAX (see '/usr/include/limits.h').
To circumvent this, you could do:
# cd /dir
# find . \( -type d -a ! -name . \) -print|xargs rm -rf
Note that the current directory (".") is excluded.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-10-2003 07:36 AM
тАО01-10-2003 07:36 AM
Re: Remove contents of directory but not the directory itself
$ cd /dir; rm -rf `ls -A`
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-10-2003 07:37 AM
тАО01-10-2003 07:37 AM
Re: Remove contents of directory but not the directory itself
Sorry, I dropped part:
# find . \( -type f -o \( -type d -a ! -name . \) \) -print|xargs rm -rf
Regards!
...JRF...