Delete script


 
Thread Tools Search this Thread
Operating Systems Linux Delete script
# 1  
Old 01-11-2011
Delete script

Hi
I need a script that will remove the contents out of a common named folder on our server and all its contents.
We have folder called temp which resides within several different folders and i need to delete the contents at a set time in the night
thanks
Treds

Last edited by pludi; 01-12-2011 at 07:10 AM..
# 2  
Old 01-11-2011
type:
Code:
crontab -e

as the requisite user, and enter something like:
Code:
0 1 * * * rm -rf /path/to/folder/* 2>/dev/null

Where "0" is zero minutes (ie on the hour), "1" is 1am, and /path/to/folder is the directory.
# 3  
Old 01-12-2011
there are hundreds of folders in different locations, needs to search file system for name then delete
thanks
Treds
# 4  
Old 01-12-2011
Code:
0 1 * * * find /path -name "dirname" -type d -exec rm -rf {} \; 2>/dev/null


Last edited by citaylor; 01-12-2011 at 07:12 AM.. Reason: typo
# 5  
Old 01-18-2011
thanks for the last post citaylor, can i extend this
I have folders automated created where people dump files into. But i would like to automate the deleting with a cron.
Folders are dates eg
Code:
2011-01-17
2011-02-29

what i like to do is remove all the 01 at the end of one month then all the 02 the next .....
using your script can i extended this to do this function...
I tried to put a * after the 2011-01* but that did not work
Code:
find /gpfs/SHARED/Studios_Share/ -name ".2011-01" -type d -exec rm -rf {} \; 2>/dev/null

any ideas will be grateful takes us ages every month to clear

Treds

Last edited by Scott; 01-18-2011 at 01:56 PM..
# 6  
Old 01-18-2011
-name "2011-01*" should work fine (make sure the asterisk is escaped or quoted as in my example)
# 7  
Old 01-18-2011
Hi
sorry it does not work

Code:
find /gpfs/SHARED/Studios_Share/ -name "2011-01*" -type d -exec rm -rf {} \; 2>/dev/null

any other ideas

thanks for looking at this anyway
treds

Last edited by Scott; 01-18-2011 at 01:55 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

SFTP Shell Script Get & Delete && Upload & Delete

Hi All, Do you have any sample script, - auto get file from SFTP remote server and delete file in remove server after downloaded. - only download specify filename - auto upload file from local to SFTP remote server and delete local folder file after uploaded - only upload specify filename ... (3 Replies)
Discussion started by: weesiong
3 Replies

2. Shell Programming and Scripting

Script needed to delete to the list of files in a directory based on last created & delete them

Hi My directory structure is as below. dir1, dir2, dir3 I have the list of files to be deleted in the below path as below. /staging/retain_for_2years/Cleanup/log $ ls -lrt total 0 drwxr-xr-x 2 nobody nobody 256 Mar 01 16:15 01-MAR-2015_SPDBS2 drwxr-xr-x 2 root ... (2 Replies)
Discussion started by: prasadn
2 Replies

3. Shell Programming and Scripting

Files delete script

Friends, I had written a small script to delete files from deletefiles.txt file. However, I want to add one more piece to script, so as to check if the file(file abc) which was already deleted earlier exists in 'deletefiles.txt' file, script should comment out that "file abc doesnt exist". Can... (5 Replies)
Discussion started by: fop4658
5 Replies

4. Shell Programming and Scripting

Delete Script

I 'm trying to write a unix script with delete statement on DB2 tables based on the date.The issue I have is that I need to delete the records on 2 tables but only one table have date field and based on another key I have to delete the related records. Table 1:- DateID KeyColumn Field 1... (5 Replies)
Discussion started by: anita81
5 Replies

5. Red Hat

Need Script to ZIP/SAVE & then DELETE Log file & DELETE ZIPS older than 12 months

ENVIROMENT Linux: Fedora Core release 1 (Yarrow) iPlanet: iPlanet-WebServer-Enterprise/6.0SP1 Log Path: /usr/iplanet/servers/https-company/logs I have iPlanet log rotation enabled rotating files on a daily basis. The rotated logs are NOT compressed & are taking up too much space. I... (7 Replies)
Discussion started by: zachs
7 Replies

6. UNIX for Dummies Questions & Answers

script to delete old files

Hi, I want to delete files that are older than 60 days.... i need to execute the script in 7 differnt folders.... i can run the script in crontab to regularly check.... I am struck @ finding out how the file is 60 days old or not... Can u please help me on this? Thanks, NithZ (6 Replies)
Discussion started by: Nithz
6 Replies

7. Shell Programming and Scripting

Script to delete old directories

Hi, I have a requirement like, I need to create the directory with date and time stap (i.e YYYYMMDDHMS) every day end need to delete the old directories which is 12 months old. I have tested with following script cd /export/home/sbeeravo/; find . -type d -mtime +365 -exec rm -rf {} \; ... (2 Replies)
Discussion started by: ShirishaReddy
2 Replies

8. Shell Programming and Scripting

script to delete one digit.

Hi User, I have a text file with a lot of customer records (over 10,000). Each record contained one field called "charge" and it must start with some space (each record may have 15 space, 17 spece, 9 space,etc, then start with <charge> and end with </charge>, in between is a value. How can I... (3 Replies)
Discussion started by: happyv
3 Replies

9. Shell Programming and Scripting

perl script to check if empty files are created and delete them and run a shell script

I have a local linux machine in which the files are dumped by a remote ubuntu server. If the process in remote server has any problem then empty files are created in local machine. Is there any way using perl script to check if the empty files are being created and delete them and then run a shell... (2 Replies)
Discussion started by: hussa1n
2 Replies

10. Shell Programming and Scripting

Please (Delete script)

Hello everybody. Actually I would like to ask you who can I make delete commend by shell script to delete some files from anywhere in my director and send it to specific place but whit the PATH because if want to restore it will return to the original place which I delete it from (As recycle pan... (7 Replies)
Discussion started by: falm
7 Replies
Login or Register to Ask a Question