HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- script - check date and filename and delete files
Operating System - HP-UX
1834508
Members
2814
Online
110068
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
Forums
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
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
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
10-06-2003 12:34 PM
10-06-2003 12:34 PM
Hi
I have one file with the list of nearly 20 files.
(i.e. filename is testfile and the contents are
tcp
voice
nwint
.
.
etc )
there is one directory in which there are files starting with (tcp, voice....etc)
what I want is that script first go to the testfile and pickup the first file (ex. tcp)from it and than go the directory and check how many files starting with tcp and delete all the files starting with tcp older than 5 days.
I want script to check all the records one by one in testfile and than to the directory.
at the end if there is any file in the directory but does not exist in testfile delete it after 20 days.
thanks
I have one file with the list of nearly 20 files.
(i.e. filename is testfile and the contents are
tcp
voice
nwint
.
.
etc )
there is one directory in which there are files starting with (tcp, voice....etc)
what I want is that script first go to the testfile and pickup the first file (ex. tcp)from it and than go the directory and check how many files starting with tcp and delete all the files starting with tcp older than 5 days.
I want script to check all the records one by one in testfile and than to the directory.
at the end if there is any file in the directory but does not exist in testfile delete it after 20 days.
thanks
Solved! Go to Solution.
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2003 01:04 PM
10-06-2003 01:04 PM
Solution
Hi
Pretty straightforward, with a bit more thought you could probably do it a lot quicker, test first of course
#!/usr/bin/sh
DIR=/directory/to/check
#loop through testfile
for file in $(cat testfile)
do
cd $DIR
find . -name "$file*" -mtime +5 -exec rm -f {} \;
done
# check for files not in testfile
ls -1 | while read checkfile do
grep $checkfile testfile
if [ $? != 0 ]
then
rm $checkfile
done
cd -
HTH
Steve
Pretty straightforward, with a bit more thought you could probably do it a lot quicker, test first of course
#!/usr/bin/sh
DIR=/directory/to/check
#loop through testfile
for file in $(cat testfile)
do
cd $DIR
find . -name "$file*" -mtime +5 -exec rm -f {} \;
done
# check for files not in testfile
ls -1 | while read checkfile do
grep $checkfile testfile
if [ $? != 0 ]
then
rm $checkfile
done
cd -
HTH
Steve
take your time and think things through
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2003 06:51 PM
10-06-2003 06:51 PM
Re: script - check date and filename and delete files
Hi steven,
u hv solved my problem
Thanks
u hv solved my problem
Thanks
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.
Company
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP