Excluding directory during deleting


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Excluding directory during deleting
# 1  
Old 05-11-2011
Excluding directory during deleting

Hi all,

I'm trying to work on a script to delete files older then 31 day's in certain directories. Now, that works, but in one directory there are 3 other maps which contains files that can be deleted but one map which contains files that can't be deleted.

My current command is: find /ontw/log -type f -mtime +31 -exec rm {} \;
The directory that should be excluded during deletion is: /ontw/log/lost+found

Thank you for your time!
# 2  
Old 05-11-2011
Code:
 find /ontw/log -type f -mtime +31 |grep -v  /ontw/log/lost+found | xargs rm

This User Gave Thanks to palanisvr For This Post:
# 3  
Old 05-11-2011
Thanks, that worked perfect Smilie

---------- Post updated at 06:55 PM ---------- Previous update was at 05:55 PM ----------

After trying it again I received this error:
user@/ontw/bin/delete$ find /ontw/log -type f -mtime +31 |grep -v /ontw/log/lost+found | xargs rm
find: cannot read dir /ontw/log/lost+found: Permission denied
usage: rm [-fiRr] file ...

Does anyone know what the problem can be?

# 4  
Old 05-11-2011
it is throwing this error message as you don't have access to read /ontw/log/lost+found directory
# 5  
Old 05-11-2011
Well thank you but is it possible to exclude it then during the find command? In other words, is it possible to exclude a folder that you can't read before you try to delete the files in this folder?
# 6  
Old 05-11-2011
Code:
find /ontw/log -type d ! -name "/ontw/log/lost+found"   -mtime +31  | xargs rm

# 7  
Old 05-12-2011
The same problem. We should have a command that excludes the directory before reading the other directories in /ontw/log and this doesn't happen here.
First he's going to read all the directories in /ontw/log and that's why I get the error.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Find file with extension and excluding directory

Hi, I have an inquiry on how do I use the find command in Solaris Unix to find some file ends with extension : txt, err in the root directory with modified date of 30days and this find command will also need to exclude b directory and its subdirectory. All the files from the above find criteria... (5 Replies)
Discussion started by: snowfrost88
5 Replies

2. AIX

Excluding directory in my tar Backup

Hello AIX experts. Hope this topic finds you well :) Now, I will take a backup for a directory called medcbs. Inside this directory 1 subdirectory I don't want to include it in the backup. So, how to exclude it? To be more clear, take a look to the following: /bossapp1/medcbs>... (4 Replies)
Discussion started by: Mohannad
4 Replies

3. UNIX for Dummies Questions & Answers

Finding new file, but excluding directory..

hi, I need to find files that have been created less than 3 days ago. However, I need to only search specific directories. I've searched about the net and found some useful commands such as : find . -type d -name 'dir_to_exclude' -prune -o -print -mtime -3 however I cannot get it... (2 Replies)
Discussion started by: horhif
2 Replies

4. Shell Programming and Scripting

Excluding a directory

i want to search files in public_html of all users and exclude any directories named "uploads" or "albums" (because there are many files in these), just skip them completely now im doing something like find /home/*/public_html -regex ".*\(php\|html\|htm\)$" -path albums -prune -o -type f... (1 Reply)
Discussion started by: vanessafan99
1 Replies

5. Shell Programming and Scripting

excluding a directory with chown, chmod

does anyone know how to exclude a directory with chown or chmod? im trying to do something like this chown $username:$username $directory/* chown $username:$username $directory/.* chown $username:$username $directory and find $directory/* -type f -exec... (1 Reply)
Discussion started by: vanessafan99
1 Replies

6. Shell Programming and Scripting

Find all files for a user, excluding a directory

I have been searching, and cannot find an answer for this. I am trying to find all files for a user, lets call him (test001), and I want to exclude a specific directory. Here is the command I run, it finds all files: find / -user test001 I get this result: > find / -user test001 ... (4 Replies)
Discussion started by: steve2x4
4 Replies

7. UNIX for Dummies Questions & Answers

Need help in excluding a particular directory using Find commad

Hi, I have a directory structure as below /home/gad/Merl/a/a1.txt /home/gad/Merl/b/a1.txt /home/gad/Merl/c/a1.txt How can I find the file a1.txt but not from directory 'a' and it(the filw) should loaded 6 days ago.. Can any one pls help,quick reply much appriciated.. Thanks. (1 Reply)
Discussion started by: jagadish_gaddam
1 Replies

8. Shell Programming and Scripting

excluding root directory when searching

I'm writing a script that executes over several subdirectories that looks like this: cd companies #find . -print -type d | find . -type d -print | while read dirname do cd $dirname # run your code at this point if ; then #do somthing else #do something else fi... (1 Reply)
Discussion started by: melearlin
1 Replies

9. UNIX for Dummies Questions & Answers

Find Files in a Directory Excluding Subdirectories

Hi, I have a filename Location.txt in a directory /abc. Similar name file is present in its subdirectory /abc/xyz. I want to find the file which is present only in /abc and not in /abc/xyz. Please any1 of u can provide a quick suggestion. Its very urgent. Thanks, Amol (2 Replies)
Discussion started by: Amol_Dicholkar
2 Replies

10. UNIX for Advanced & Expert Users

find excluding a directory and a file

Hi I have some 5 folders and two files in the current directory. I want to delete all, expect one folder(files in the folder too should not be deleted) and a file in the current directory. Lets say the folder and file that should not be deleted as 'a'(folder name) and 'b'(file name). Can you... (1 Reply)
Discussion started by: ammu
1 Replies
Login or Register to Ask a Question