Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 273
  • Last Modified:

Simple Linux script question about deleteing files after x days

Hi,

I know my around Linux but i'm a novice when it comes to shell scritping.

I want to add a few lines to a script that will find all files older than x days and delete them,
it must start at a directory i specifiy and work on all subdirectories below.
Some of the filenames may contain spaces and mixed case letters etc.
I don't want to use perl or anything other than standard shell script commands.

Background:
Its a script to run on an FTP server that our mobile staff use for transferring stuff to and from the office.  In the office the FTP server is just a windows share and so people tend to use windows filenames - hence the spaces etc.  Of course they just wont keep the area tidy so i want to add a script that will remove everything older than 4 or 5 days.

The FTP server is running under Fedora Core 3.

thanks,

Simon.

0
simonenticott
Asked:
simonenticott
  • 2
1 Solution
 
danny_ebbersCommented:
#!/bin/sh
find . -ctime +$1 -exec rm -rf {} \;




----------------------------------
for testing you should first use this

find . -ctime +$1 -exec echo Marked for deletion: {} \;



0
 
danny_ebbersCommented:
#!/bin/sh
find $1 -ctime +$2 -exec rm -rf {} \;




----------------------------------
for testing you should first use this:

find $1 -ctime +$2 -exec echo Marked for deletion {} \;



write the 2 lines in a plain text file

run:
chmod 755 filename

then you can use:
./yourfilename <path> <nr of days old>

0
 
simonenticottAuthor Commented:
Thanks danny, i've spent ages trying to figure this out !

Simon,
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now