Computing.Net > Forums > Unix > Delete folder

Delete folder

Reply to Message Icon

Original Message
Name: pranav610
Date: April 22, 2004 at 13:42:56 Pacific
Subject: Delete folder
OS: linux
CPU/Ram: ??
Comment:

Have a cron job running that creates a folder using -date +"%a" in /home dir and runs daily.

Need a script that will go through /home and look for folder name that matches -date +"a" and delete it.



Report Offensive Message For Removal


Response Number 1
Name: Wolfbone
Date: April 23, 2004 at 00:22:15 Pacific
Subject: Delete folder
Reply: (edit)

Perhaps you could tell us more precisely how and where the folder is created, does it matter if it is not empty, do you want only folders to be deleted if they match the day of the running deletion script, will it also run automatically and what is your default shell.

The more information a script has about the data it encounters, the smaller the chance of unpredictable behaviour.

For example, I'm sure you wouldn't want /home/userx/Thurman_Electronics_acct_data or /home/monica/Monicas_address_book or /home/usery/Mail/Sun-Micro deleted!


Report Offensive Follow Up For Removal

Response Number 2
Name: Dlonra
Date: April 23, 2004 at 06:34:40 Pacific
Subject: Delete folder
Reply: (edit)

what is a "folder"? Is it like a directory?
cf,pwf,mkfol ?? find . -type f (folder)


Report Offensive Follow Up For Removal

Response Number 3
Name: pranav610
Date: April 23, 2004 at 07:36:21 Pacific
Subject: Delete folder
Reply: (edit)

Sorry for the confusion.

This is what my current script does:
In /home/BACK-UP dir, cron runs a script that backs up server info and transactions every day. It first creates a dir like this: mkdir ""`date +"%a"` and backs up every thing in ""`date +"%a"` dir.

What I want is not more than a weeks backup so I need to create a script [where i need help] that will search /home/BACK-UP dir for dir that matches present day and delete it.

eg. After a week, I'll have Mon, Tue, Wed ... dirs with backups in them. Starting Mon, it will delete Mon dir and so on.

I can get cron to first run the script that deletes Mon dir and then run the backup script. What I cannot figure out is hoe to delete the dirs matching present day.

Hope this helps.

Thank you


Report Offensive Follow Up For Removal

Response Number 4
Name: Dlonra
Date: April 23, 2004 at 08:20:11 Pacific
Subject: Delete folder
Reply: (edit)

if you mkdir `date +"%a"` for present day,
(BTW, why ""`date +"%a"` ?)

why not: rm -rf ""`date +"%a"` and mkdir again
or
rm -rf $(date +"%a")/*


Report Offensive Follow Up For Removal

Response Number 5
Name: pranav610
Date: April 23, 2004 at 11:44:06 Pacific
Subject: Delete folder
Reply: (edit)

Somethings in life are so simple and its so easy to make it hard on oneself

Thank you for you help.


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Delete folder

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software