- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Finding and deleting file
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
тАО08-27-2006 09:26 PM
тАО08-27-2006 09:26 PM
In your opinion, what should be the faster way to locate and delete a file. I am currently using "find" and "rm" command using a shell script. But it is taking very long. Any suggesttion?
Best regard
Henry Chua
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-27-2006 09:30 PM
тАО08-27-2006 09:30 PM
Re: Finding and deleting file
"find" and "rm" it's the right way.
Pay attention from what directory the search it's starting ;-).
regards
pg
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-27-2006 09:53 PM
тАО08-27-2006 09:53 PM
Re: Finding and deleting file
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-27-2006 09:54 PM
тАО08-27-2006 09:54 PM
Re: Finding and deleting file
So as suggested narrow find's entry path.
On Linux systems there's a tool called locate which usually is faster than find.
But it requires to have a current locate database built before (can be done by cron nightly).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-27-2006 09:57 PM
тАО08-27-2006 09:57 PM
SolutionYou don't provide any details, but here is one crucial way to maintain performance:
If you are deleting more than just a very few files, pipe the 'find' output to 'xargs' to remove the files instead of using '-exec'.
Instead of:
# find /path -xdev -type f -mtime +1 -exec rm {} \;
...use:
# find /path -type f -mtime +1 | xargs rm
...This will collect groups of filenames as multiple arguments to 'rm' thereby spawning one process to remove many files at once instead of spawning one process to remove one file at a time --- a very expensive thing to do!
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-27-2006 10:07 PM
тАО08-27-2006 10:07 PM
Re: Finding and deleting file
was wondering, if I were to use a C program to do this will there be any issue? Beside using scripting is there a faster option.. speed is imperative in this operation, so got to squeeze every ounce of juice from my box.. =)
Best regards
Henry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-27-2006 10:54 PM
тАО08-27-2006 10:54 PM
Re: Finding and deleting file
Relative to your last question of using a C program, without seeing your script, I still suspect that your performance issue is the 'exec' of multiple 'rm' processes as I delineated above.
C (or Perl) would allow you to call 'unlink(2)' which is the underlying function of 'rm'. Hence, for instance, using a Perl script and the "File::Find" module would eliminate spawning separate 'rm' processes, *BUT*, again, I still suspect that your performance issue is the 'exec' of multiple 'rm' processes as I delineated above.
Too, without seeing your whole script, it is difficult to postulate a better solution.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-27-2006 11:21 PM
тАО08-27-2006 11:21 PM
Re: Finding and deleting file
On my systems, I have functionality akin to the Linux 'locate' command, in which a search query is carried out by grepping a database of filenames.
To accomplish this, I have implemented the following cronjob:
10 01 * * * find / -local -print | compress - > /var/opt/locate/loc.db.Z # Refresh locate db
Then, to use 'locate':
# alias locate
locate='zcat /var/opt/locate/loc.db.Z | grep'
# locate '^/usr/.*/hostname$'
/usr/bin/hostname
Obviously, there are several drawbacks to this approach:
1) The database reflects the actual layout of filesystems only immediately after the database is created.
2) The database stores only filenames, not filetypes, permissions, modification time, etc. However, these other attributes could easily be added.
3) The database file can be altered by anyone with appropriate permission.
Because of these drawbacks (especially #1), I would only use 'locate' interactively (i.e. not in a script). But in this capacity, it works very well.
PCS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-28-2006 12:53 AM
тАО08-28-2006 12:53 AM
Re: Finding and deleting file
find /
is the worst possible way to locate a file!!! Not only does it interfere with every other program, it will search a mounted CDROM and NFS mounted directories. You don't want that at all. You need to limit the search to the likely location of the file. For instance, only a root user can create files in directories like /usr/bin or /etc so there is no reason to search for user files in directories where they can't write a new file.
Perhaps if you can describe how the file gets created, we can suggest a much faster way to locate it. If you are looking for large files, there has been a LOT of comments here about why this is not a good idea for disk management.
Bill Hassell, sysadmin