Solved

script to remove files > then 7 days old.

Posted on 2004-03-29
7
316 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
 
LVL 45

Expert Comment

by:sunnycoder
ID: 10711499
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
inotifywait in linux 2 287
install command in linux 1 59
RHEL red hat 7.3 how can I upgrade the kernel? 12 1,022
shell script or linux command to upload a directory to artifactory? 2 266
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 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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

726 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