How to keep only 5 most recent files in certain folder

Ask a Question related to SCO, Design and Development.

  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. Similar Questions and Discussions

    1. Function Open recent files in file menu doesn't show
      When I try to open recent files from file menu there is no opportunity to choose it? I've installed ID 2.0.2 CE on Win 2000 again and it's the same....
    2. How include IDD files in My Recent Documents on XP Start Menu?
      ..IDD files (Windows, 2.0) do not show up with other files in the My Recent Documents submenu on the XP Start Menu. Any way to change that? ...
    3. Lacking recent files in 'File' menu
      The list of recent files in the 'Files' menu is static and inactive. It simply states 'Recent File' (greyed out). I am using acrobat standard...
    4. Open Recent Files in CS
      Any reason Illustrator CS doesn't seem to hold an updated list of recent files? On start-up Open Recent Files in the file menu always defaults to a...
    5. Unable To Open "Recent Files"
      I've seen this discussed before, but since the Forum Search Engine does not seem to be working, I'll ask it again: I am unable to open files from the...
  3. #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]racpop@tenzing.org[/email]
    Roger Cornelius Guest

  4. #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]newsgroups@howie.org.uk[/email]
    Mail to "newsgroups" will be rejected.
    Mail to my forename will not.

    Richard Howlett Guest

  5. #4

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

    Scott McMillan <smcm@usa.net> wrote in message news:<a6t6kvcsqnap44h71plkpu31kccn1hu9ug@4ax.com>. ..
    > On Wed, 20 Aug 2003 01:37:52 GMT, scriptOmatic
    > <ScriptOmatic@ChironComputing.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

Posting Permissions

  • You may not post new threads
  • You may 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