Link to home
Start Free TrialLog in
Avatar of xoxomos
xoxomos

asked on

Linux cleanup script

I run ls -ltr and get  a listing of files in the directory.   What command(s) could I enter to  run the ls -ltr and rm everything with a date in the month of JUL?
Avatar of eXedon
eXedon

Hi xoxomos,

first, you have to focus on files query.
here are the command for getting files with a date in the month of JUL only.
ls -l | grep "Jul"

Open in new window

and verify if the result is correct.

If the result was correct, put the list to rm command.
rm -f $(ls -l | grep "Jul")

Open in new window


But please note, before you execute command, you have to change to source directory first.
Avatar of Gerwin Jansen
Hi, I don't believe the method above will work because the output of ls -ltr will look like this:

-rwxr--r--  5  user  group 1234 Jul 29 2011 file.txt

Trying to remove the above using rm will fail. Besides the fact that you will also delete files from 2011 if the rm command would work.

Do you just want to remove files from July in this year? And what about directories?
do a man on find and look at the -exec rm {} \; option with one of the -- time options (cant remember which one off the top of my head)
ASKER CERTIFIED SOLUTION
Avatar of Gerwin Jansen
Gerwin Jansen
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of xoxomos

ASKER

jools is on the right track.  It's some combination of mtime and exec with some of those squiggly characters sort of like find . -mtime +15 -exec rm {}\;
Avatar of xoxomos

ASKER

jools solution is what i was looking for:

 find -mtime +30 -exec rm {} \;
>>  find -mtime +30 -exec rm {} \;

This command is deleting files in July but it does not delete "everything  with a date in the month of JUL?" It will not delete files from July 1st to July 25th. So I'm afraid you have chosen the incorrect answer for your question. My suggestion is creating 2 'timestamp' files that are used to select files in July, did you try my suggestion at all?
You're welcome to raise this with the moderators if you think its not fair but the asked did say my response was what they were after.
Avatar of xoxomos

ASKER

I guess I'm one of those who has to see what he gets before he knows what he wants.
I'll see if the moderator can somehow let me raise the points to 500 and split them.
Avatar of xoxomos

ASKER

Guess they will work on this after the weekend

"Experts Exchange  |  AUG 26, 2012  |  04:25AM UTC
Thank you for your request; we will respond as soon as possible. Please reply to this email if you have additional information for this case. Please Note: We are currently experiencing high email volume due to an email bug we encountered during the weekend. If you were affected by this email bug please go here for more information.

This message was sent to xoxomos@gmail.com in reference to Case # #22577."
Oh well, easy come, easy go.

I would have liked to have thought I'd contributed a little to the question but I guess in this case it wasn't to be.
Avatar of xoxomos

ASKER

I agree, but sorry it's my bad.  I should have.  Like I said, it's another case of a user having to see what he gets before he can say what he wants:-(
No worries, no one died and it is after all just a question. I think the moderators were fair and I did suggest raising it if anyone wasn't happy.