Exclude file from a search script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Exclude file from a search script
# 1  
Old 02-09-2011
Exclude file from a search script

Hello,

I use the following script to delete files from folders.
There is an old file I wish to exclude the deletion script.
How to exclude a file by name?

Current script:
=============================
Code:
#!/bin/ksh
# ----------------------------------------------------
# clean_log_folder.sh   
# Delete log files older than 90/60 days and capture output to a log file
#-----------------------------------------------------
#
# scripts and logs are stored
export PROGDIR=/var/tmp/
export LOGDIR=/var/tmp/
 
# logfile name and location
export LOG_FILE=${LOGDIR}/del_files_fe2.${LOGNAME}.log
 
# write current date/time to log file
echo "#- Files removed from xxxyyy log folder on - $(date) ---"        >> ${LOG_FILE}
cd /xxx/xxx/xxx/xxx
find . -mtime +90 -exec ls -l {} \; >> ${LOG_FILE}
find . -mtime +90 -exec rm -r {} \;
echo "#- Files removed from yyyzzz log folder on - $(date) ---"        >> ${LOG_FILE}
cd /xxx/xxx/xxx/xxx/xxx/xxx/xxx/
find . -mtime +60 -exec ls -l {} \; >> ${LOG_FILE}
find . -mtime +60 -exec rm -r {} \;

================================================

Last edited by Franklin52; 02-09-2011 at 05:44 AM.. Reason: Please use code tags, thank you
# 2  
Old 02-09-2011
To exclude file names we can use NOT operator..
Code:
find . -mtime +60 ! \( -name 'version.sh' -o -name ary.sh \)  -exec ls -l {} \;

The above command excludes files version.sh and ary.sh. If only one file needs to be excluded then there is no need of brackets.
Code:
find . -mtime +60 ! -name 'version.sh' -exec ls -l {} \;

This User Gave Thanks to michaelrozar17 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to Exclude Files That Still On Transfer..

Hi. I want to schedule a job at some directory will several files in it. But there maybe a situation whereby some of the files at the point of the schedule are still transferring during that time. So I want to skip those files from being processed. Two method that come to my mind: 1.... (5 Replies)
Discussion started by: aimy
5 Replies

2. Shell Programming and Scripting

Need to search a particular String form a file a write to another file using perl script

I have file which contains a huge amount of data. I need to search the pattern Message id. When that pattern is matched I need to get abcdeff0-1g6g-91g3-1z2z-2mm605m90000 to another file. Kindly provide your input. File is like below Jan 11 04:05:10 linux100 |NOTICE... (2 Replies)
Discussion started by: Raysf
2 Replies

3. Ubuntu

[Solved] Using Find with an exclude/exclude file

I am familiar with using tar and exclude/include files: tar zcf backup.dirs.tgz --files-from=include.mydirs --exclude-from=exclude.mydirs --no-recursion but was wondering if I could use find in the same way. I know that you can just specify the directories to exclude but my list is... (2 Replies)
Discussion started by: metallica1973
2 Replies

4. Shell Programming and Scripting

Script to search a large file with a list of terms in another file

Hi- I am trying to search a large file with a number of different search terms that are listed one per line in 3 different files. Most importantly I need to be able to do a case insensitive search. I have tried just using egrep -f but it doesn't seam to be able to handle the -i option when... (3 Replies)
Discussion started by: dougzilla
3 Replies

5. Shell Programming and Scripting

ls to exclude file

I have cgicsave.env and cgic*, but I want to print cgic* value but NOT cgicsave.env Thanks (9 Replies)
Discussion started by: xs2punit
9 Replies

6. Shell Programming and Scripting

To search a file for a specific word in a file using shell script

Hi All, I have a sql output file has below. I want to get the values 200000040 and 1055.49 .Can anyone help me to write a shell script to get this. ACCOUNT_NO ------------------------------------------------------------ BILL_NO ... (8 Replies)
Discussion started by: girish.raos
8 Replies

7. Shell Programming and Scripting

How to exclude folders/files in search?

I have a directory with about 20 folders and many different types of files. I need to search for files and gzip in all the directories except for 1 directory. How do you exclude a directory? (2 Replies)
Discussion started by: bbbngowc
2 Replies

8. UNIX for Dummies Questions & Answers

Shell script to search for text in a file and copy file

Compete noob question.... I need a script to search through a directory and find files containing text string abcde1234 for example and then copy that file with that text string to another directory help please :eek: (9 Replies)
Discussion started by: imeadows
9 Replies

9. Shell Programming and Scripting

search for the contents in many file and print that file using shell script

hello have a file1 H87I Y788O T347U J23U and file2 J23U U887Y I99U T556U file3 I99O J99T F557J file4 N99I T666U R55Y file5 H87I T347U file6 H77U R556Y E44T file7 Y788O K98U H8I May be using script we can use file1 to search for all the files and have the output H87I file5... (3 Replies)
Discussion started by: cdfd123
3 Replies
Login or Register to Ask a Question