Professional Web Applications Themes

How to keep only 5 most recent files in certain folder - SCO

Hi, I am trying to make a script that would run every couple hours and purge all files in certain folder except last five files (most recent). Files are being added to that folder constantly. Can you help me ? Thanks...

  1. #1

    Default How to keep only 5 most recent files in certain folder

    Hi,

    I am trying to make a script that would run every couple hours and purge all
    files in certain folder except last five files (most recent).
    Files are being added to that folder constantly.

    Can you help me ?

    Thanks


    Sinisa Guest

  2. #2

    Default Re: How to keep only 5 most recent files in certain folder

    Sinisa wrote:
    >
    > Hi,
    >
    > I am trying to make a script that would run every couple hours and purge all
    > files in certain folder except last five files (most recent).
    > Files are being added to that folder constantly.
    >
    > Can you help me ?
    Here's one solution:

    cd /whereever
    n=5 # save $n most recent
    set -- `/bin/ls -t`
    if test $# -gt $n
    then
    shift $n
    /bin/rm -f "$"
    fi
    --
    Roger Cornelius [email]racpoptenzing.org[/email]
    Roger Cornelius Guest

  3. #3

    Default Re: How to keep only 5 most recent files in certain folder

    Sinisa wrote:
    > Hi,
    >
    > I am trying to make a script that would run every couple hours and purge all
    > files in certain folder except last five files (most recent).
    > Files are being added to that folder constantly.
    Adapted from the standard way in .procmailrc to keep the latest n files in a
    backup directory where n is 5 to satisfy your criteria:

    rm -f dummy `ls -t |sed -e 1,5d`

    The reference to dummy is to ensure rm always has at least one filename as a
    parameter.

    --
    Richard Howlett
    [email]newsgroupshowie.org.uk[/email]
    Mail to "newsgroups" will be rejected.
    Mail to my forename will not.

    Richard Howlett Guest

  4. #4

    Default Re: How to keep only 5 most recent files in certain folder

    Scott McMillan <smcmusa.net> wrote in message news:<a6t6kvcsqnap44h71plkpu31kccn1hu9ug4ax.com>. ..
    > On Wed, 20 Aug 2003 01:37:52 GMT, scriptOmatic
    > <ScriptOmaticChironComputing.Com> wrote:
    >
    > >Sinisa wrote:
    > >>
    > >> Hi,
    > >>
    > >> I am trying to make a script that would run every couple hours and purge all
    > >> files in certain folder except last five files (most recent).
    > >> Files are being added to that folder constantly.
    > >>
    > >> Can you help me ?
    > >>
    > >> Thanks
    > >
    > >use
    > >/bin/ls -tr "-t" for sort by time
    > > "-r" for sort reverse
    > >
    > >the top 5 lines will be the 5 NEWEST files, e.g:
    >
    > Actually, using the -r option on SCO Openserver would place the OLDEST
    > files first. Just using -t will place the NEWEST files first. Since
    > the OP didn't even hint at the flavor/version of his/her system but
    > posted to the c.u.s.m NG I'm assuming he/she is using either SCO
    > Openserver or Unixware.
    >
    > >
    > >
    > >/bin/ls -tr | head -5
    > >
    > >should do it
    >
    >
    > Scott McMillan
    head -5 will give you the first or newest 5.
    I'd suggest

    rm `ls -t * | tail +6`

    you can pretty it up and handle the null set and figure out what to
    do with directories if they exist.

    Regards…Dan.
    Dan Skinner Guest

Similar Threads

  1. Unable To Open "Recent Files"
    By Dennis Brody in forum Adobe Photoshop 7, CS, CS2 & CS3
    Replies: 11
    Last Post: June 20th, 01:55 PM
  2. Function Open recent files in file menu doesn't show
    By Matjaz@adobeforums.com in forum Adobe Indesign Windows
    Replies: 2
    Last Post: July 22nd, 09:57 PM
  3. How include IDD files in My Recent Doents on XP Start Menu?
    By Carol_Hornung@adobeforums.com in forum Adobe Indesign Windows
    Replies: 0
    Last Post: July 10th, 01:37 PM
  4. Lacking recent files in 'File' menu
    By Gert_Caspersen@adobeforums.com in forum Adobe Acrobat Windows
    Replies: 7
    Last Post: May 25th, 06:44 AM
  5. Open Recent Files in CS
    By Steph_Bannister@adobeforums.com in forum Adobe Illustrator Macintosh
    Replies: 4
    Last Post: March 6th, 06:05 PM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139