| 
     
       |  |  |  | 
            
              | 
             
               | 
               
                 |  | UGU: Unix Guru Universe - Unix Tip #4008- February  1, 2012
 -  Home : Help
 : Today's Tip Unix Tip #4008- February  1, 2012
 
 
SPECIFIC REMOVALS 
To remove every file in
 the folder that is not
 dated March:
 
 rm ` ls -al | grep -v "Mar" | awk '{print $9}'`
 
 Or a specific date in March:
 
 rm ` ls -al | grep -v "Mar 28" | awk '{print $9}'`
 
 Note: that this is a
 dangerous command to issue
 since it assumes that you
 are consciously using it
 on a directory which is
 full of files that are out
 of date or not belonging to
 March or whatever.
 
 (If this is not the case you
 might get some undesirable
 results.)
 
 The other thing is that you
 might want to keep more than
 one month's worth of files.
 You would then need to move
 the files from the other month
 out into a temporary subfolder
 while you "clean" the top
 folder.  Then move them back
 in. Also, note that you have
 two types of single quote,
 the first and last are from
 the key under the escape key
 and the one that is used to
 delimit the awk print
 statement is the one next to
 the hash key. I have used this
 command myself regularly with a
 few extra pipes (to do certain
 specific things which are
 irrelevant here) in order to
 clean out subdirectories where
 the df is running at 100%!
 This has been a time-saver
 when I have had to log on to
 different servers around the
 world and do a regular purge.
 
 
 THIS TIP IS NOT SUPPORT,
 UGU ADVICES TESTING BE FOR
 USING.
 
 
 
 NOTE: All tips provided are USE AT YOUR OWN RISK. Tips are submitted
by various unix admins around the globe. UGU suggest you read and
test each tip in a non-volitile environment before placing into
production.
 
 LAST 5 TIPS
 4007
 - CHECKING FOR FILESYSTEMS FULL
 4006
 - ANOTHER CASE TRANSLATION
 4005
 - TEST TROUBLES IF STRING IS EMPTY
 4004
 - ANOTHER PROCESS FINDER
 4003
 - VI REVERSAL
 I want to 
 SUBSCRIBE
 and get a UGU Tip everyday.
 I want to 
 UNSUBSCRIBE
 and NOT get a UGU Tip everyday.
 If you have a UNIX TIP let us know, we just may use it:
(All tips become the property of the Unix Guru Universe)
 |  |  
                 |  |  
                 |   Copyright 1994-2024 Unix Guru Universe 
 |  |  |  |  |