Expression for Finding Multiple Directories..??


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Expression for Finding Multiple Directories..??
# 1  
Old 07-07-2006
Expression for Finding Multiple Directories..??

I am writing a shell script to search for previous versions of an application...the application is called TAU and basically i want to search the users home directory and /Applications for any instances of a "TAU" folder.. If found i want to give the user the option to remove the old folders and if nothing is found i just want to continue with the script...this is what i have come up with so far...


echo "Searching for previous versions of TAU..."
found=$(find ~ /Applications -type d -maxdepth 2 -name "TAU")
if [ ! $found ]; then
**commands**
else
**other commands**
esac

the problem is that if more than one TAU folder is found the expression doesn't evaluate correctly...i get a unary or binary operator expected error...any help would be appreciated

Thanks,
meskue
# 2  
Old 07-08-2006
How about:

if [ -n "$found" ]; then
**commands**
else
**Other-Commands**
fi

Would that work for you ? Since the find command does return strings, just checking for a "non-zero" string length (-n) should
help you make your "decision".
===
An addition.

Would all the directories HAVE to be named "TAU" ? Would checking for -name '*TAU*' find all possible versions ?
[Like TAU.old , old_TAU , etc..]
==

Last edited by dsbeerf; 07-08-2006 at 02:25 AM..
# 3  
Old 07-08-2006
Code:
#!/bin/sh

find ~ /Applications -type d -maxdepth 2 -name "TAU" 2>/dev/null | while IFS= read vo
do
# file "$vo" was found, do what you want with it, e.g.
echo "$vo"
done

# 4  
Old 07-10-2006
great thanks a lot for your help works perfect
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep with Regular expression now working on file directories

Hello Everyone, I have a file sam1 with the below content SYSYSID;MANDT;/SIE/AD_Z0M_INDX;/SIE/AD_Z0M_KEY1 echo $Regex \bSYSYSID\b|\bMANDT\b|\b/SIE/AD_Z0M_INDX\b|\b/SIE/AD_Z0M_KEY1\b cat sam1 | grep -Eo $Regex I expect the result as SYSYSID MANDT /SIE/AD_Z0M_INDX /SIE/AD_Z0M_KEY1... (4 Replies)
Discussion started by: sam99
4 Replies

2. Shell Programming and Scripting

Finding directories with expression

Hi All, I need your help in finding pattern of directories. need to search for all pattern have "mypatern" from base directory folder. example ------- server1 - base directory 100 server1/ab_123456_1/mypattern 100 server1/ab_123456_2/mypattern 200 server1/ab_123457_1/mypattern... (13 Replies)
Discussion started by: lxdorney
13 Replies

3. UNIX for Advanced & Expert Users

Regular expression for finding OCR mistakes.

I have a large file of plain text, created using some OCR software. Some words have inevitably been got wrong. I've been trying to create grep or sed, etc., regular expressions to find them - but haven't quite managed to get it right. Here's what I'm trying to achieve: Output all lines which... (2 Replies)
Discussion started by: gencon
2 Replies

4. Shell Programming and Scripting

finding matches between multiple files from different directories

Hi all... Can somebody pls help me with this... I have a directory (dir1) which has many subdirectories(vr001,vr002,vr003..) with each subdir containing similar text file(say ras.txt). I have another directory(dir2) which has again got some subdir(vr001c,vr002c,vr003c..) with each subdir... (0 Replies)
Discussion started by: bramya07
0 Replies

5. UNIX for Dummies Questions & Answers

Deleting multiple directories inside multiple directories

Hi, Very unfamiliar with unix/linux stuff. Our admin is on vacation so, need help very quickly. I have directories (eg 40001, 40002, etc) that each have one subdirectory (01). Each subdir 01 has multiple subdirs (001, 002, 003, etc). They are same in each dir. I need to keep the top and... (7 Replies)
Discussion started by: kkouraus1
7 Replies

6. UNIX for Dummies Questions & Answers

using regular expression for directories in find command

Hi, I want to find the files available in a directory /var/user/*/*/data/. I tried using the command "find /var/user/ -path '*/*/data/ -name '*' -type f" it says find: 0652-017 -path is not a valid option and then i tried using "find /var/user/ -name '*/*/data/*' -type f" but its not... (3 Replies)
Discussion started by: vinothbabu12
3 Replies

7. Shell Programming and Scripting

Script for parsing directories one level and finding directories older than n days

Hello all, Here's the deal...I have one directory with many subdirs and files. What I want to find out is who is keeping old files and directories...say files and dirs that they didn't use since a number of n days, only one level under the initial dir. Output to a file. A script for... (5 Replies)
Discussion started by: ejianu
5 Replies

8. Shell Programming and Scripting

check if multiple directories exist else create missing directories

Hi , I 'm trying to check if multiple directories exist on a server, if not create the missing ones and print " creating missing directory. how to write this in a simple script, I have made my code complex if ; then taskStatus="Schema extract directory exists, checking if SQL,Count and... (7 Replies)
Discussion started by: ramky79
7 Replies

9. UNIX for Dummies Questions & Answers

Create directories with regular expression

Hi guys, can any one tell me how to create directories using regular expression? Let's say that I need to create directories test01, test02, test03.... test10. Can it be done using any regular expression? thanks. (13 Replies)
Discussion started by: mahendrt
13 Replies

10. Shell Programming and Scripting

moving directories to new directories on multiple servers

Hi - I am new to unix scripts...I need to move several directories on multiple servers to new directories. (0 Replies)
Discussion started by: mackdaddy07
0 Replies
Login or Register to Ask a Question