HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- grep and remove
Operating System - HP-UX
1836014
Members
2388
Online
110088
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
09-06-2001 02:55 PM
09-06-2001 02:55 PM
I'm trying to list files inside a directory that includes all of Jan - Dec 2000, after which I want to delete all of them since it's building up space.
Is there of syntax I should use to grab all files between jan through Dec and delete it also??
Need help..
Jade
Is there of syntax I should use to grab all files between jan through Dec and delete it also??
Need help..
Jade
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2001 03:18 PM
09-06-2001 03:18 PM
Solution
Hi:
We can take advantage of JulianDays to do this:
Today 09/06/2001 is JD 2452159; 01/01/2000 is JD 2451545; 12/31/2000 is JD 2451910.
Today - 12/31/2000 = 249; Today - 01/01/2000 = 614.
So I want to get all regular files in the current directory files older than 248 days and younger than 613 days.
Here is a test version of the command:
find . -type f \( -mtime +248 -a -mtime -613 \) -exec ls -l {} \;
Here is a actual version of the command (MAKE CERTAIN YOU ARE IN THE DESIRED DIRECTORY):
find . -type f \( -mtime +248 -a -mtime -613 \) -exec rm {} \;
Man find for details. In case you are wondering about how I got those strange Julian Days, I've attached the script.
Regards, Clay
We can take advantage of JulianDays to do this:
Today 09/06/2001 is JD 2452159; 01/01/2000 is JD 2451545; 12/31/2000 is JD 2451910.
Today - 12/31/2000 = 249; Today - 01/01/2000 = 614.
So I want to get all regular files in the current directory files older than 248 days and younger than 613 days.
Here is a test version of the command:
find . -type f \( -mtime +248 -a -mtime -613 \) -exec ls -l {} \;
Here is a actual version of the command (MAKE CERTAIN YOU ARE IN THE DESIRED DIRECTORY):
find . -type f \( -mtime +248 -a -mtime -613 \) -exec rm {} \;
Man find for details. In case you are wondering about how I got those strange Julian Days, I've attached the script.
Regards, Clay
If it ain't broke, I can fix that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2001 04:17 PM
09-06-2001 04:17 PM
Re: grep and remove
Hi Jade:
Since you want to remove all files whose modification timestamp is for the year 2000, we could do this:
# cd
# ls -al | awk '$8~/2000/ {system("rm " $9)}'
This will remove all *files* (field-9 in the 'ls' output), while skipping directories (because 'rm' doesn't remove them), whose modification timestamp (field-8 in the 'ls') is "2000".
Regards!
...JRF...
Since you want to remove all files whose modification timestamp is for the year 2000, we could do this:
# cd
# ls -al | awk '$8~/2000/ {system("rm " $9)}'
This will remove all *files* (field-9 in the 'ls' output), while skipping directories (because 'rm' doesn't remove them), whose modification timestamp (field-8 in the 'ls') is "2000".
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2001 06:07 AM
09-07-2001 06:07 AM
Re: grep and remove
Hi Jade:
Here?s yet another way to meet your objective.
One of the values of using ?find? is that it recursively descends the directory you specify. Try this for a solution.
# cd mydir
# touch ?mt 200001010000 myref1
# touch ?mt 200012312359 myref2
# find . -type f -newer myref1 -a ! -newer myref2 | awk '{system("rm " $0)}'
# rm myref1 myref2
This will find and remove all files whose modification timestamp is more recent than ?myref1? (here, Jan 1, 2000 at 0000) and equal or less than ?myref2? (here, Dec 31, 2000 at 2359).
In reality, the file ?myref2? will be removed as a part of the ?find? process.
Regards!
...JRF...
Here?s yet another way to meet your objective.
One of the values of using ?find? is that it recursively descends the directory you specify. Try this for a solution.
# cd mydir
# touch ?mt 200001010000 myref1
# touch ?mt 200012312359 myref2
# find . -type f -newer myref1 -a ! -newer myref2 | awk '{system("rm " $0)}'
# rm myref1 myref2
This will find and remove all files whose modification timestamp is more recent than ?myref1? (here, Jan 1, 2000 at 0000) and equal or less than ?myref2? (here, Dec 31, 2000 at 2359).
In reality, the file ?myref2? will be removed as a part of the ?find? process.
Regards!
...JRF...
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