- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: How do I create a script to Purge all files in...
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
08-21-2000 08:38 AM
08-21-2000 08:38 AM
How do I create a script to Purge all files in a Directory except for the latest 100???
A DBA who I work with is looking for a script that inside a directory will only keep that latest 100 files. I guess the database he works with continually fills up the directory.
Unfortunately, I am lacking in knowledge of writing scripts and if anyone has any ideas how to do this, has done any or can get me started I would greatly appreciate it.
Thanks! You can email me at SAldrich@chaptersinc.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2000 08:59 AM
08-21-2000 08:59 AM
Re: How do I create a script to Purge all files in a Directory except for the latest 100???
find . -mtime +100 -ok rm {} \;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2000 09:00 AM
08-21-2000 09:00 AM
Re: How do I create a script to Purge all files in a Directory except for the latest 100???
Try this:
=====begin=====
nr_of_files=$(ll -l /your/directory | grep ^- | wc -l)
set $(ls -art1 /your/directory)
while [ $nr_of_files -gt 100 ]
do
if [ -f $1 ]
then
rm $1
let nr_of_files=nr_of_files-1
fi
shift
done
=====end======
This should remove all but 100 regular files in the directory /your/directory.
Bye,
Rik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2000 09:08 AM
08-21-2000 09:08 AM
Re: How do I create a script to Purge all files in a Directory except for the latest 100???
I am not very good at all at creating scripts so any help is greatly appreciated!!!
Thanks, Shaun Aldrich
You can email me at SAldrich@chaptersinc.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2000 09:31 AM
08-21-2000 09:31 AM
Re: How do I create a script to Purge all files in a Directory except for the latest 100???
find . -mtime +100 -ok rm {} \;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2000 09:35 AM
08-21-2000 09:35 AM
Re: How do I create a script to Purge all files in a Directory except for the latest 100???
Shaun Aldrich
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2000 09:49 AM
08-21-2000 09:49 AM
Re: How do I create a script to Purge all files in a Directory except for the latest 100???
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2000 10:05 AM
08-21-2000 10:05 AM
Re: How do I create a script to Purge all files in a Directory except for the latest 100???
x=$(ls -Ft /path/path/path | grep -v "/$" | tail +100)
for i in $(echo "$x")
do
rm ${i}
done
probably should test this.....don't know if it works right
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2000 12:00 AM
08-22-2000 12:00 AM
Re: How do I create a script to Purge all files in a Directory except for the latest 100???
Try this........
#! /bin/sh
# ---------------------------------
# Removes all but the last two
# files in the redo diretory
# ---------------------------------
X=1
for Files in `ls -t /path/your_file_spec_here.* `
do
# -------------------------------
# Test for your upper limit here
# -------------------------------
if test $X -gt 2
then
echo "Removing File $Files $X"
# Put your removal command here
else
echo $Files not removed.
fi
let X=X+1
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2000 11:08 AM
08-23-2000 11:08 AM
Re: How do I create a script to Purge all files in a Directory except for the latest 100???
That's exactly what my script does.
The command 'ls -art1' gives a 1 column list of all files in the current directory, ordered from oldest ( at the top) to youngest (at the bottom). So, by deleting all files but 100 starting from the beginning of that list, you end up with the 100 youngest file in that directory.
Right?
Bye,
Rik.