Solved

script to remove files > then 7 days old.

Posted on 2004-03-29
7
313 Views
Last Modified: 2010-04-21
I have a a directory called upload in which I create hidden directories for users  .uername1   .username2.   How would I go about creating a script that will remove files from each hidden directory that are more then 7 days old.
0
Comment
Question by:dplinnane
7 Comments
 
LVL 45

Expert Comment

by:sunnycoder
Comment Utility
Hi dplinnane,

find -type f  -ctime 7


Sunnycoder
0
 
LVL 45

Expert Comment

by:sunnycoder
Comment Utility
find <dir> -ctime +3 -type f -exec rm {}

Be careful though. You might want to replace the
     -exec rm {} \;
by
     -print
first to make sure that you are going to delete the files you really mean to delete

also as per your requirements, you may need atime in place of ctime ... refer to find man page for details
0
 
LVL 45

Expert Comment

by:sunnycoder
Comment Utility
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:dplinnane
Comment Utility
Cool, I'll check them out.
I'm a php programmer so I can run commands using  exec(sheel command);
if I wanted to run this without using php what kind of a file would I place the code in (I don't know a whole lot about shell scripting just basic commands)  filename.ext     ext?  My aim is to run a cron job every 7days. I have figured out how to do that running a php file but am curious to know an alternative method.
Thanks.
0
 
LVL 45

Accepted Solution

by:
sunnycoder earned 400 total points
Comment Utility
you can run this command from the prompt

you can store it in a file with the first line of the file being

#!/bin/bash

followed by the command(s)

store it as filename.sh

chmod 0755 filename.sh  (set mask as you want, but it should be executable for the uuser who wishes to execute it)
0
 
LVL 8

Assisted Solution

by:da99rmd
da99rmd earned 50 total points
Comment Utility
Then just make a cronjob with
crontab -e
and press insert and then write  
0 4 * * * (path to script)/filename.sh 1> /dev/null (and ev to make all err mess disaper 2> /dev/null)
then
shift+zz
and it will run every night at 4 removing those files. from those dirs.

/Rob
0
 
LVL 12

Assisted Solution

by:stefan73
stefan73 earned 50 total points
Comment Utility
Hi da99rmd,
> cronjob
That's the best place for cleanup jobs, yes.

Cheers,
Stefan
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now