get a list of folders and find files older than...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting get a list of folders and find files older than...
# 1  
Old 02-26-2010
get a list of folders and find files older than...

I am trying to get a list of folders contained in a given directory and would then like to delete any folders/files older than 60mins.

So far I am able to get the list of folders using:

Code:
ls -l /home/uploads | grep '^d.*'

the output:
Code:
drwxr-xr-x  6 flk  flk       4096 2010-02-11 13:30 APC-3.0.14
 drwxr-xr-x  5 flk  flk       4096 2010-01-08 12:52 downloads
 drwx------ 15 flk  flk       4096 2010-02-23 15:27 irclogs
 drwxr-xr-x  2 flk  flk       4096 2010-01-25 21:40 logs

Sadly the above output is far too much info, I just want the folder names so that i can do something like:

Code:
find /home/uploads/APC-3.0.14 -name "dontdelete" -prune -o -type f -mmin +60 -print -delete
find /home/uploads/downloads  -name "dontdelete" -prune -o -type f -mmin +60 -print -delete

Anyone know how i could possibly combine the ls grep with the find so that it iteratively walks the folders?
# 2  
Old 02-27-2010
You can achieve it by the following command.

find /home/uploads -type d | find -type f -mmin +60 -exec rm -rf {} \;
# 3  
Old 02-27-2010
MySQL solution

Is this you want ,

Code:
#!/bin/sh

# Get the directory you want to search as the command line argument
# For eg : /home/uploads/ as $1

dirs=`ls -l $1 | grep '^d.*'| cut -d ' ' -f 9 `
for dir in $dirs
do
  find $1/$dir -name "dontdelete" -prune -o -type f -mmin +60 -print -delete
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

List files older than 10 days.

Hello all, I want to list the files older than 10 days. Currently am using find ./ -mtime +10 -exec ls -ltr {} \; command. But I want to execute the same command in 16 directories at a time and want an output asking to remove those file? Please help me to design the script. regards, Ajay (3 Replies)
Discussion started by: 02Ajay
3 Replies

2. Shell Programming and Scripting

Find older files than specified date

Hi, I need to find out list of files which are older than specific date. I am using 'find, and newer' commands but its not giving the correct result. Can you please help to findout the list of files. thanks (2 Replies)
Discussion started by: Satyak
2 Replies

3. Shell Programming and Scripting

Find and delete files and folders which are n days older from one unix server to another unix server

Hi All, Let me know how can i find and delete files from one unix server to another unix server which are 'N' days older. Please note that I need to delete files on remote unix server.So, probably i will need to use sftp, but question is how can i identify files and folders which are 'N'... (2 Replies)
Discussion started by: sachinkl
2 Replies

4. UNIX for Advanced & Expert Users

find files older than 30 days old

Hello, I have a script which finds files in a directory that are older than 30 days and remove them. The problem is that these files are too many and when i run this command: find * -mtime +30 | xargs rm I run this command inside the directory and it returns the error: /usr/bin/find:... (8 Replies)
Discussion started by: omonoiatis9
8 Replies

5. UNIX for Dummies Questions & Answers

Find files older than 2010?

Hi, I need to delete all files, in a folder, older than 2010 that is 2009, 2008 ,.. files... Can anyone suggest the command for that,... Thanks ---------- Post updated at 03:29 PM ---------- Previous update was at 02:53 PM ---------- humm,.. ok right now I am using the following:... (4 Replies)
Discussion started by: Mack1982
4 Replies

6. Shell Programming and Scripting

List the files which are older than 7 days

Hi Frnds, I have to list the files which are older than 7 days in the given directory. it should consider only the files and should not show subdirectories. Thanks, Raja (3 Replies)
Discussion started by: smr_rashmy
3 Replies

7. UNIX Desktop Questions & Answers

Find files older than 10 days

What command arguments I can use in unix to list files older than 10 days in my current directory, but I don't want to list the hidden files. find . -type f -mtime +15 -print will work but, it is listing all the hidden files., which I don't want. (4 Replies)
Discussion started by: Pouchie1
4 Replies

8. AIX

how to find files older than 2 hours

I need help to find files in a directory that are older than 2 hours. Any help would be great. (3 Replies)
Discussion started by: pt14
3 Replies

9. Shell Programming and Scripting

delete files and folders older than 3 days

find /basedirectory -type f -mtime +3 >> /tmp/tempfile find /basedirectory -type d -mtime +3 >> /tmp/tempfile mailx -s "List of removed files and folders" myemail@domain.com < /tmp/te mpfile rm /tmp/tempfile find /basedirectory -type f -mtime +3 -exec rm {} \; find /basedirectory -type d... (7 Replies)
Discussion started by: melanie_pfefer
7 Replies

10. Shell Programming and Scripting

Find files older than 20 days & not use find

I need to find files that have the ending of .out and that are older than 20 days. However, I cannot use find as I do not want to search in the directories that are underneath the directory that I am searching in. How can this be done?? Find returns files that I do not want. (2 Replies)
Discussion started by: halo98
2 Replies
Login or Register to Ask a Question