Find directories only and delete them created 3 days before


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find directories only and delete them created 3 days before
# 1  
Old 07-16-2010
Find directories only and delete them created 3 days before

Hello

I have some directories and files created under /export/local/user

I would like to delete directories only under /export/local/user, created before 3 days

Can someone help me with command to do this task?

Thanks
# 2  
Old 07-16-2010
If you delete a directory with files in it you have to delete the files, too.

Plus there no notion of 'created date' in unix.
mtime=last modification atime=last time of access ctime=last inode change

Code:
find /export/local/user  -type d  -mtime +3 -exec rm -r {} \;

# 3  
Old 07-24-2010
Delete all files in a directory which starts with "XXX*"

Hi,

How can I delete all files in a directory that starts with the name "STW*" through a shell script ksh. Can I use the mtime in this case. Will the following command work, or let me know how I could do it with other alternatives. Please note that this would be part of a ksh script and the command is not run manually.

Code:
 
find /export/local/user/tmp \( -name "STW*" \) -mtime +0 -exec rm -f {} \;

# 4  
Old 07-24-2010
Hi Jmathew99,

Could you please explain why have u used -mtime here? I don't see any use of it here. And also I don't think u need to put -name wthin braces.

Thanks
# 5  
Old 07-24-2010
Delete all files in a directory which starts with "SWT*"

Hi,

Can you please let me know the code after correction.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find the sum of files created 5 days before

Hi, I want to find the sum of all the files created 5 days ago and store it in a variable. (os is HP-UX) can this be extracted from ls -l Is there any other way of getting the sum of all the files created (4 Replies)
Discussion started by: bang_dba
4 Replies

2. Shell Programming and Scripting

Find directories that are not used for 500 days

How to list the directories that are not acessed for more than 500 days? i used find in the following way find . -type d -atime +500 -exec du -sh {} \; but it is listing all the sub direcories of the parent directories which satisfy above condiion.I would like to get just name of the... (1 Reply)
Discussion started by: sajuatl
1 Replies

3. Shell Programming and Scripting

what is the find to command to find the files created last 30 days

what is the find to command to find the files created last 30 days (5 Replies)
Discussion started by: rajkumar_g
5 Replies

4. Shell Programming and Scripting

Find unix file created how many days ago?

i want to find unix file created how many days ago? (4 Replies)
Discussion started by: utoptas
4 Replies

5. UNIX for Dummies Questions & Answers

How to find files created some days before?

HI, I have 2 questions. 1> Is there any code to see files that created some day or some time before in a directory??? 2> how or where i will find the last exit status of a process?? thanks (6 Replies)
Discussion started by: jyotidas
6 Replies

6. Shell Programming and Scripting

Find the directory modified/created before 4 days

Hi, I have an application which creates some directories while running. I want to delete these directories which are 4 days older. i tried find . type d -mtime +1 -print And it is working fine.. but find . type d -mtime +4 -print is not giving any results which are 4 days... (6 Replies)
Discussion started by: Tuxidow
6 Replies

7. Shell Programming and Scripting

Using cron to delete directories 90 days old

We use Solaris 10 x86 and I want to use a cron job to remove directories +90 old. Currently I have the command below but it only cleans the files and keeps the directory. What am I doing wrong? /opt/tesk/batch/kit/archive/* -mtime +90 -exec rm -r {} \: Thank you (3 Replies)
Discussion started by: oh-daa
3 Replies

8. Red Hat

Find files older than 30 days in directories and delete them

Hi, I have dummies questions: My script here can find the files in any directories older than 30 days then it will delete the files but not the directories. I would like to also be able to delete the directories that hold old files more than 30 days not just the files itself. find . -type f... (2 Replies)
Discussion started by: lamoul
2 Replies

9. Shell Programming and Scripting

Delete files from sub-directories over 7 days

Can any one please help me in deleting all the Files over 7 days from sub-directories A, B, C... Top-Directory Sub-Directory-A File-1 File-2 ..... File-n Sub-Directory-B File-1 File-2 ..... File-n Sub-Directory-C File-1 ... (1 Reply)
Discussion started by: sureshcisco
1 Replies

10. HP-UX

Command for delete the directories which are older than 7 days

Hi, My requirement is need to delete the directories (Including files also) which are older than 7 days. So I used below command in one script (script takes 2 input parameters) #$1 - Path of the directory from where we have to delete the directories.# #$2 - Number of days older... (1 Reply)
Discussion started by: sridhar sivakot
1 Replies
Login or Register to Ask a Question