?
Solved

script to remove files > then 7 days old.

Posted on 2004-03-29
7
Medium Priority
?
318 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 10711441
Hi dplinnane,

find -type f  -ctime 7


Sunnycoder
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 10711471
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
Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

 

Author Comment

by:dplinnane
ID: 10711538
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 1600 total points
ID: 10711569
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 200 total points
ID: 10712511
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 200 total points
ID: 10713361
Hi da99rmd,
> cronjob
That's the best place for cleanup jobs, yes.

Cheers,
Stefan
0

Featured Post

RHCE - Red Hat OpenStack Prep Course

This course will provide in-depth training so that students who currently hold the EX200 & EX210 certifications can sit for the EX310 exam. Students will learn how to deploy & manage a full Red Hat environment with Ceph block storage, & integrate Ceph into other OpenStack service

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

800 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