- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Stuck with shell scripting...
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-02-2010 05:01 AM
тАО08-02-2010 05:01 AM
- Check in a given directory how many occurrences of a file called server* (the * representes a date, obviously different for each file).
- Leave untouched the two more recent server* entries and delete the older.
How can be that done?
Regards.
Solved! Go to Solution.
- Tags:
- scripting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-02-2010 05:21 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-02-2010 05:24 AM
тАО08-02-2010 05:24 AM
Re: Stuck with shell scripting...
If it is by last modification, you could do:
ll -rt server* | tail -n +3
(This should give you the ones to remove.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-02-2010 05:27 AM
тАО08-02-2010 05:27 AM
Re: Stuck with shell scripting...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-02-2010 08:58 PM
тАО08-02-2010 08:58 PM
Re: Stuck with shell scripting...
Following command remove everything except recent two entries.
# ls -lt server* | rm `awk ' NR > 3 { print $NF }'`
HTH
Muru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-02-2010 10:22 PM
тАО08-02-2010 10:22 PM
Re: Stuck with shell scripting...
> ls -lt server* | rm $(awk 'NR > 3 { print $NF }')
Your edge arithmetic is off by one, you need: NR > 2
- Tags:
- edge arithmetic
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-02-2010 10:58 PM
тАО08-02-2010 10:58 PM
Re: Stuck with shell scripting...
I mean modification time.
The tail and awk code you gave to me prints (or removes, in this case) the two more recent items of server*.
Is there any way of printing (in my case, removing) every server* occurrence EXCEPT the two more recent ones?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-02-2010 11:09 PM
тАО08-02-2010 11:09 PM
Re: Stuck with shell scripting...
Thanks you so much!