Unix Tip #4436- May 4, 2023


SEARCH : Home : Help : Today's Tip

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
4435 - CHECKING FOR FILESYSTEMS FULL
4434 - ANOTHER CASE TRANSLATION
4433 - TEST TROUBLES IF STRING IS EMPTY
4432 - ANOTHER PROCESS FINDER
4431 - 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)
Email Address:

Yes, email me a Hot Unix Tip everday.

Enter Hot Unix Tip (optional):

Yes, I will support this tip

Captcha (not case sensitive):


Please enter the above letters:


HOME | Flavors | Admin | Network | Security | S/W | Help | Events | Vendors | Careers | Internet
About | Add Link | Feedback | Search

Copyright © 1994-2005 Unix Guru Universe