Solved

script to remove files > then 7 days old.

Posted on 2004-03-29
7
317 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 400 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 50 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 50 total points
ID: 10713361
Hi da99rmd,
> cronjob
That's the best place for cleanup jobs, yes.

Cheers,
Stefan
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

705 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