Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2004
    Posts
    0

    Unanswered: 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 12:38.

  2. #2
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    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

  3. #3
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •