AIX

AIX

Connect with fellow AIX users and experts to gain knowledge, share insights, and solve problems.


#Power
#Power
#Operatingsystems
#Servers
 View Only
  • 1.  Space Clearing

    Posted 01/05/09 10:42 AM

    Originally posted by: SystemAdmin


    Does anyone have a clever routine (script) to delete a set of subordinate directories (with directories and files subordinate to these) within a file system. We're a relatively inexperienced AIX site and any help on this would be appreciated. Thanks.
    #AIX-Forum


  • 2.  Re: Space Clearing

    Posted 01/05/09 10:46 AM

    Originally posted by: tony.evans


    cd <target parent directory>
    rm -r *

    Unless I'm missing something obvious?

    (NB: Be very careful with rm -r *)
    #AIX-Forum


  • 3.  Re: Space Clearing

    Posted 01/05/09 11:06 AM

    Originally posted by: SystemAdmin


    Thanks Tony, we'd been exporting the file list out to a pc, massaging in Excel and creating a script with thousands of commands to delete...... I thought there must be a simpler way of doing things. Prseumably your cautionary note is to ensure I'm in the correct directory and there is nothing else in there that should be retained. Thanks again for your speedy reply. Regards
    #AIX-Forum


  • 4.  Re: Space Clearing

    Posted 01/05/09 11:19 AM

    Originally posted by: tony.evans


    Yes. The -r means recursive removal, which means the rm commands go down each directory from the start point until it gets to the bottom and then deletes the content and moves back upwards. The * is a wildcard (in essence) which is expanded by the shell to every matching filename. Since * in shell terms means 'anything', then every file and directory in the top level directory is passed to the rm command.

    So, in a directory with,

    drwx------ 2 bob staff 512 31 Jul 2006 backups
    drwx------ 2 bob staff 512 03 Jul 2008 bin
    -rw------- 1 bob staff 164409 19 Jul 2007 catalog.mic

    When you type rm -r *, the * gets expanded to backups bin catalog.mic so the command that actually gets executed is,

    rm -r backups bin catalog.mic

    The rm command isn't interpreting the *, the shell expands it first before passing the results to the command.

    rm -r c* would expand to,

    rm -r catalog.mic

    for example.

    It's worth reading up on the Korn Shell (which is the default shell under AIX) to see how file expansion works, it's your friend and extremely powerful.

    There are other ways of building lists of files if you wanted to include or exclude certain values, but shell expansion is pretty flexible.

    You could get used to using -i with rm, which prompts you before each file / directory, but if you have thousands it'll take a while!
    #AIX-Forum


  • 5.  Re: Space Clearing

    Posted 01/06/09 09:59 AM

    Originally posted by: esv


    hope this is not too late,

    move to the parent directory and use: rm -R directory

    if it is a filesystem, the command will delete everything and leave the mountpont intact and will end with an error message, but that is fine, all data has been deleted, the side effect is that lost+found will be deleted as well, and it is important to keep it on hand, but : 'rm -R *' will delete it too.
    I am always wary about using "rm -R *" ; search on the internet how to recreate the lost+found directory.
    best regards,
    esv.
    #AIX-Forum


  • 6.  Re: Space Clearing

    Posted 01/06/09 10:57 AM

    Originally posted by: SystemAdmin


    Tony, Enrique, gentlemen, thank-you both so much for your time and suggestion. This has been very helpful and made what had been a painful task very straight-forward. Many thanks,. have a great 2009
    #AIX-Forum