- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Script to delete files
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
12-17-2007 07:23 PM
12-17-2007 07:23 PM
I have some programs/scripts in HP-UX which generate logs by name/date series continuously.
I want to delete those files using script without deleting the last 2-3 files using creation date.
Can anyone help me regarding this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2007 07:44 PM
12-17-2007 07:44 PM
Solution$ echo rm -f $(ll -r prefix* | awk '{print $9}' | tail -n +4)
Remove the echo if you are happy with what you are removing.
If the files don't have a sortable name and you can assume the last modification date is ordered, you can use "ll -t".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2007 08:32 PM
12-17-2007 08:32 PM
Re: Script to delete files
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2007 01:01 AM
12-19-2007 01:01 AM
Re: Script to delete files
find . -mtime 1 -type f -name *.log | xargs rm
this will rmove your file modified between 24 and 48 hours ago (about creation see previos post). Type the correct regular expression istead of *.log
HTH,
Art
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2007 01:09 AM
12-19-2007 01:09 AM
Re: Script to delete files
What i wanna do is, i have a directory which contains files like this manner
-rw-r--r-- 1 user group 24033 Dec 19 13:05 History_2007121913.log
-rw-r--r-- 1 user group 24110 Dec 19 14:04 History_2007121914.log
-rw-r--r-- 1 user group 23575 Dec 19 15:04 History_2007121915.log
Last log is running. If i want to delete the files keeping the last one what will be the procedure?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2007 01:58 AM
12-19-2007 01:58 AM
Re: Script to delete files
History_2007121913.log
These are ordered by name.
>If i want to delete the files keeping the last one what will be the procedure?
$ echo rm -f $(ll -r History_* | awk '{print $9}' | tail -n +2)
Remove the "echo" when you are sure it removes only the files you want.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2007 03:21 AM
12-19-2007 03:21 AM
Re: Script to delete files
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2007 06:44 AM
12-19-2007 06:44 AM
Re: Script to delete files
log files older than 2 days get gzipped.
log files older than 5 days get deleted.
I run the find command from the spot where the files are so I do not accidentally delete stuff I care about. I also use the -name option in find for the same reason.
cd /directory/path
find . -type f -mtime 2 -name "log*" -exec gzip {} \;
find . -type f -mtime 5 -name "log*gz" -exec rm {} \;
And here's another way
cd /directory/path
LIST1=`find . -type f -mtime 2 -name "log*"`
for F in $LIST1
do
gzip $F
done