Unix Technical Forum

Automate deletion of files

This is a discussion on Automate deletion of files within the Debian Linux support forums, part of the Debian Linux category; --> Hi all, Although I am not a newbie to Linux, I am to Linux scripting. All my scripting skills ...


Go Back   Unix Technical Forum > Unix Operating Systems > Debian Linux > Debian Linux support

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-19-2008, 08:30 AM
Hugh Janus
 
Posts: n/a
Default Automate deletion of files

Hi all,

Although I am not a newbie to Linux, I am to Linux scripting. All my
scripting skills are with Windows so they don't apply! Anyway, I am
running a Debian server as part of a programming project and I have a
requirement for a script that hopefully someone can help me with!

Under the /home path I have several user folders. What I would like to
have is a script that deletes the entire contents of specific folders
on a regular basis. The criteria for files to be deleted with have a
prefix on the filename like "DEL-" or something similar. The criteria
for which folders to scan will be whatever paths I list in a text file
somewhere on the server.

Any help would be greatly appreciated! As I said, I have no Linux
scripting experience whatsoever so I am hoping that someone will have a
similar script that they could post and help me modify.

Thanks a million in advance!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 01-19-2008, 08:30 AM
Dave Kelly
 
Posts: n/a
Default Re: Automate deletion of files

Hugh Janus wrote:
> Hi all,
>
> Although I am not a newbie to Linux, I am to Linux scripting. All my
> scripting skills are with Windows so they don't apply! Anyway, I am
> running a Debian server as part of a programming project and I have a
> requirement for a script that hopefully someone can help me with!
>
> Under the /home path I have several user folders. What I would like to
> have is a script that deletes the entire contents of specific folders
> on a regular basis. The criteria for files to be deleted with have a
> prefix on the filename like "DEL-" or something similar. The criteria
> for which folders to scan will be whatever paths I list in a text file
> somewhere on the server.
>
> Any help would be greatly appreciated! As I said, I have no Linux
> scripting experience whatsoever so I am hoping that someone will have a
> similar script that they could post and help me modify.
>
> Thanks a million in advance!
>



#!/bin/bash

for i in *jpg; do echo $i; convert -size 320x240 $i -resize 320x240 $i; done

A short script like this could do the job. Where it is looking for
files with the '*.jpg' extension, you could change that to look for the
'DEL*' prefix.

Where this used 'convert' to resize the images, read the manual on 'rm'
for the flags you will need to force removal without human responce.

And then ask questions here again.

dave
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 01-19-2008, 08:30 AM
Dan N
 
Posts: n/a
Default Re: Automate deletion of files

On Wed, 04 Jan 2006 12:53:05 -0800, Hugh Janus wrote:

> What I would like to
> have is a script that deletes the entire contents of specific folders on a
> regular basis.


Use the script that was suggested and run it as a cron task (man cron).

Dan


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 01-19-2008, 08:30 AM
Michael C.
 
Posts: n/a
Default Re: Automate deletion of files

On 4 Jan 2006 12:53:05 -0800,
Hugh Janus <my-junk-account@hotmail.com> wrote:
>
>
> Hi all,
>
> Although I am not a newbie to Linux, I am to Linux scripting. All my
> scripting skills are with Windows so they don't apply! Anyway, I am
> running a Debian server as part of a programming project and I have a
> requirement for a script that hopefully someone can help me with!
>
> Under the /home path I have several user folders. What I would like to
> have is a script that deletes the entire contents of specific folders
> on a regular basis. The criteria for files to be deleted with have a
> prefix on the filename like "DEL-" or something similar. The criteria
> for which folders to scan will be whatever paths I list in a text file
> somewhere on the server.
>
> Any help would be greatly appreciated! As I said, I have no Linux
> scripting experience whatsoever so I am hoping that someone will have a
> similar script that they could post and help me modify.
>
> Thanks a million in advance!
>


#!/bin/sh

for directory in `cat directory-list` ;
do
echo rm /home/mike/${directory}/DEL-* ;
done ;

Remove echo, and substitute your own home as needed.

Michael C.
--
mcsuper5@usol.com http://mcsuper5.freeshell.org/

If we work together we share together.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 01-19-2008, 08:30 AM
Hugh Janus
 
Posts: n/a
Default Re: Automate deletion of files


>
> #!/bin/sh
>
> for directory in `cat directory-list` ;
> do
> echo rm /home/mike/${directory}/DEL-* ;
> done ;
>
> Remove echo, and substitute your own home as needed.
>
> Michael C.
> --
> mcsuper5@usol.com http://mcsuper5.freeshell.org/
>
> If we work together we share together.



Wow! Thanks everyone for the help! I'll get on it and hopefully have
something working in the next couple of days!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 01-19-2008, 08:58 AM
the enemies of god
 
Posts: n/a
Default Re: Automate deletion of files

Dave Kelly wrote:
> Hugh Janus wrote:
>
>> Hi all,
>>
>> Although I am not a newbie to Linux, I am to Linux scripting. All my
>> scripting skills are with Windows so they don't apply! Anyway, I am
>> running a Debian server as part of a programming project and I have a
>> requirement for a script that hopefully someone can help me with!
>>
>> Under the /home path I have several user folders. What I would like to
>> have is a script that deletes the entire contents of specific folders
>> on a regular basis. The criteria for files to be deleted with have a
>> prefix on the filename like "DEL-" or something similar. The criteria
>> for which folders to scan will be whatever paths I list in a text file
>> somewhere on the server.
>>
>> Any help would be greatly appreciated! As I said, I have no Linux
>> scripting experience whatsoever so I am hoping that someone will have a
>> similar script that they could post and help me modify.
>>
>> Thanks a million in advance!
>>

>
>
> #!/bin/bash
>
> for i in *jpg; do echo $i; convert -size 320x240 $i -resize 320x240 $i; done
>
>

this is why linux sucks

--

unmade in the distance

unmade in her watery eyes
clouds under the stars, fenceposts
words turned into signs

clouds of the revolution

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 05:08 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com