Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

removing dirs with FIND 2

Status
Not open for further replies.

sandeepmur

Programmer
Dec 14, 2003
295
PT
Hi,

I need to exclude some directories in my find cmd:
> find . -name "*"
Output:

./Repubs/2.4.5_ResetPrd_Rep
./Repubs/1.4.3_SendCommonDamage_Rep
./Repubs/2.3.5_Sendsh_Rep


how can I achieve this ?

thnx
 
say i want to exclude the dir "2.4.5_ResetPrd_Rep" from my above find cmd output.. how do I go about it ?

I tried using grep -v but its not working out..

thnx
 
find . ! -name '2.4.5_ResetPrd_Rep'
Anyway, man find

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Nope, its not working.. or rather, its not excluding the directory..
 
sorry.. actually the above works.. whats not working is something else.. I am trying to pipe the output of the find cmd to an awk which is not working..

find . ! -name "2.4.10_MemoryCleaning_Repub" | awk '{if (int($NF)!=0) {a+=1}} END {print int(a)}' a=0 FS="/"

any suggestions ?

thnx
 
Try putting xargs after the pipe:

...pub" | xargs awk...
 
Another xargs thing you can do is:

find . -type d > list

Edit the list and remove the directory trees you want to keep.

Run command "cat list | xargs -l /bin/rm -rf
 
Word of caution here.

/bin/rm -rf

is not necessarily your best friend if used incorrectly. Remember the old DOS days when DELTREE asked "Are you sure"? Well, UNIX assumes you know what you're doing and won't belittle you by asking for permission to wipe out your entire system.

In this case, double-check the contents of "list". There's a good chance you'll have a single "." in there. Ouch!
 
Hi bfitzmai,

In the cmd "cat list | xargs -l /bin/rm -rf" where do I mention the directories to be removed ?

thnx
 
In the 'list' (ie a file you have created using bfitzmal's find earlier in that post). Take good note of motoslide's warning about rm -rf!
 
hi,

I am getting lost here and frankly the rm command frightens me !

I have come up with a similar but alternative solution but need your help..

how do I remove entries from a file.. For ex, if my file has the fwg:

./Starters/3.1.8_CreateDispute_Starter
./Starters/2.4.1_SynchronizeAddress_Starter/4200492
./Starters/2.4.1_SynchronizeAddress_Starter/4200493
./Repubs/1.3.11_ReceiptRequest_Repub

I want to delete all entries which has the string "2.4.1_SynchronizeAddress_Starter" in it, giving me the output:

./Starters/3.1.8_CreateDispute_Starter
./Repubs/1.3.11_ReceiptRequest_Repub

TIA
 
Solution 1:
If your file is created by a find command, modify it the way PHV told you above, in order not to include this string.

Solution 2:
Use grep command to create a new file without this string;
something like
grep -v string oldfile > newfile
btw, man grep

hope this helps
 
hm ...
It seems my 'Solution 1' won't work, because your string is not the name of a file,
sorry.
But try #2 !
 
Hi,

I have the fwg which is working satisfactorily but would be much better if I can reduce the amount of code (especially the shell script part)..

appreciate some ideas:

find . ! -type d > temp.txt
grep -v "3.1.2_UpdateCollectionStatus_Starter" temp.txt > temp1.txt
grep -v "2.4.1_SynchronizeAddress_Starter" temp1.txt > temp2.txt

TotalFILES=`cat temp3.txt | awk '{if (int($NF)!=0) {a+=1}} END {print int(a)}' a=0 FS="/"`

rm *.txt

TIA
 
a few ideas:

you create files temp.txt, temp1.txt, temp2.txt;
then you use temp3.txt. Where does this file come from? What is wrong here?

If the only use of temp*.txt is to supply an input for your next command, you may as well replace it with pipes. (Read your shell man pages about it.)
Something like
find . ! -type d | grep -v xyz | grep -v abc | awk ...
or, as you already have,
TotalFILES=`find ... | ... | awk ...`

Two 'grep -v' may be combined into a single one; I don't know exactly how, but 'man grep should tell you. (I confess, I usually use two greps myself in such a case!)

hope this helps

 
And what about this ?
TotalFILES=`find . ! -type d | grep -Evc '3.1.2_UpdateCollectionStatus_Starter|2.4.1_SynchronizeAddress_Starter'`

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hi,

code
Code:
TotalFILES=`find . ! -type d | grep -Evc '3.1.2_UpdateCollectionStatus_Starter|2.4.1_SynchronizeAddress_Starter'`

was working fine when I was trying to exclude only 3/4 dirs but when I added 10 directories, its not working.. I can neither run the command at the shell nor via a shell script (my final objective).

any suggestions ?

thnx
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top