If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Looking for shell script assistance…

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-11-04, 11:13
xcntrk75 xcntrk75 is offline
Registered User
 
Join Date: Oct 2004
Posts: 0
Looking for shell script assistance…

Hello, I’m looking to write a shell script that performs what I believe to be very rudimentary clean-up of a directory. I’ve been searching and trying several different techniques but as a very novice shell programmer, am still having trouble.

What I’m trying to do is write a script to look for the number of files that exist in a directory. If the number exceeds X then I want the script to delete the excess by date (oldest). For example:

[$ls]

file1
file2
file3
file4

If the output quantity is more than 2, I’m looking to delete the excess older files. If the output is 2 or less then I want nothing to be done. I have another automated process that continues to roll these files out and plan to call this script via cron to continually delete the excess and retain the most recent two files.

All comments and feedback is appreciated…

Last edited by xcntrk75; 10-11-04 at 11:38.
Reply With Quote
  #2 (permalink)  
Old 10-11-04, 15:50
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,456
Cool

Have you tried coding anything yet?

Here are some maybe usefull (or not) hints:

ls -1t | head -2 #<- lists the two 'latest modified' files.
ls -1t | wc -l #<- counts the number of files in a directory.

__________________
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
Reply With Quote
  #3 (permalink)  
Old 10-11-04, 15:51
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,456
Cool

Have you tried coding anything yet?

Here are some maybe usefull (or not) hints:

ls -1t | head -2 #<- lists the two 'latest modified' files.
ls -1 | wc -l #<- counts the number of files in a directory.

__________________
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On