LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 06-21-2010, 11:01 AM   #1
rjbaca
LQ Newbie
 
Registered: Jun 2010
Posts: 1

Rep: Reputation: 0
Shell script to delete folders and files dynamically and recursively


I have an archive directory that needs to be cleaned up once per quarter. The top level (/data/archive/*) directory names change daily, as well as the subdirectories and the filenames (the application names everything according to date). Also, there are two top level directories, bin and incoming, that we can't touch. I want to write a shell script that loops through the 15 or 20 top level directories and deletes all files and subdirectories older than 3 days (skipping the bin and incoming folders). Can someone get me started on a script? I am kinda new to shell scripting.

Thanks!
 
Old 06-21-2010, 11:26 AM   #2
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Fedora38
Posts: 6,147

Rep: Reputation: 435Reputation: 435Reputation: 435Reputation: 435Reputation: 435
Up at the top of this page is a Search button.

Search LQ for find mtime rm {} and you'll see a lot of interesting threads to get you started with your script.

When testing your script [which I am sure you will do before running it] be sure to use ls {} (ie list the filenames) instead of rm {} (which will delete them)

Welcome to LQ!
 
  


Reply



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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
find -exec command to recursively delete files and folders in folders with X name Joan Murt Linux - Newbie 2 07-08-2009 04:35 PM
bash script to delete files / folders based on date and freespace nekawa Linux - Newbie 5 06-08-2009 09:00 PM
Entering folders recursively to run script on files nested inside, ubuntu 7.10 aidansmoker Linux - Newbie 4 11-11-2007 11:39 PM
shell script to recursively "compare" all files in a directory... silex_88 Programming 3 05-12-2007 04:24 AM
Delete old files and folders Script? AsteX Linux - General 4 11-11-2004 06:26 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 02:01 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration