- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Shell scripting challenges.
Operating System - HP-UX
1752862
Members
4440
Online
108791
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Discussions
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- 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
09-06-2010 12:33 AM
09-06-2010 12:33 AM
Shell scripting challenges.
Hi All
I'm having a few challenges with a shell script.
In our environment, we have a few vxfs filesystems exported to users windows PCs.
The users create files and directories on these filesystems using the standard windows directory naming convention ( with spaces and and \ in directory names ). One of the softwares we run has a bug and creates direcotries recursively several levels deep.
These deep directories are causing all sorts of problem. I'm trying to write a script which can identify empty directories and delete them if they are empty. I do not have perl knowledge, hence I decided to write a shell script.
The directories can be in the form
'/var/tmp/TEST/directory 1'
'/var/tmp/TEST/directory 2\'
'/var/tmp/TEST/directory_3\'
and there can be several such directories and several levels deep.
I have to iterate through all these directories and delete the ones that are empty.
Thanks in advance for all your suggestions.
Kaushik
I'm having a few challenges with a shell script.
In our environment, we have a few vxfs filesystems exported to users windows PCs.
The users create files and directories on these filesystems using the standard windows directory naming convention ( with spaces and and \ in directory names ). One of the softwares we run has a bug and creates direcotries recursively several levels deep.
These deep directories are causing all sorts of problem. I'm trying to write a script which can identify empty directories and delete them if they are empty. I do not have perl knowledge, hence I decided to write a shell script.
The directories can be in the form
'/var/tmp/TEST/directory 1'
'/var/tmp/TEST/directory 2\'
'/var/tmp/TEST/directory_3\'
and there can be several such directories and several levels deep.
I have to iterate through all these directories and delete the ones that are empty.
Thanks in advance for all your suggestions.
Kaushik
1 REPLY 1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2010 01:16 AM
09-06-2010 01:16 AM
Re: Shell scripting challenges.
Actually you don't need to identify if a directory is empty: a "rmdir" operation will be successful _only_ if a directory is empty.
To remove chains of otherwise empty directories, you'll need to walk the directory tree in so-called "depth-first" order:
If a directory has sub-directories, check them first; after that, if the directory has now become empty (i.e. the sub-directories were empty and were removed), remove the directory too.
If I understood your problem correctly, this one-liner should be all that's needed:
find /var/tmp/TEST -depth -type d -exec echo rmdir {} \+
NOTE: in the above form, the command will just echo out the command lines it would execute. Verify that the command does what you want, then remove the word "echo" to make the command actually delete stuff.
MK
To remove chains of otherwise empty directories, you'll need to walk the directory tree in so-called "depth-first" order:
If a directory has sub-directories, check them first; after that, if the directory has now become empty (i.e. the sub-directories were empty and were removed), remove the directory too.
If I understood your problem correctly, this one-liner should be all that's needed:
find /var/tmp/TEST -depth -type d -exec echo rmdir {} \+
NOTE: in the above form, the command will just echo out the command lines it would execute. Verify that the command does what you want, then remove the word "echo" to make the command actually delete stuff.
MK
MK
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP