How to search a directory in unix


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to search a directory in unix
# 1  
Old 10-24-2008
How to search a directory in unix

Hi,

I'm very new to shell script. Try to search a directory named construction using : find construction -type d.

but don't know the path. so it can not stat.

want to return the path of directory construction.
can anyone help me.
# 2  
Old 10-24-2008
If I understand you, you want to find the directory 'construction' and return its path?

If so, it would be as simple as:

find / -type d -name "construction"

This can take a long time, so if you know where it can be (say under /usr), you can restrict the search:

find /usr ...
# 3  
Old 10-24-2008
thanks for reply.
scenario is same what u understand.

Actually I'll run a script which will search whether the "construction" directory is present or not. if present then only run the script and the path for "construction" is variable.

is there any other way to implement this.
# 4  
Old 10-24-2008
Finding a directory, if the its availble run the Script.

Hi, i think below script will help you something.....

vari=`find . -name "construction" | grep construction`

if [ "$vari != "" ]
then

run the script. (Give your Script name here) eg: $home/bin/run.ksh
else

echo "There is no variable like Construction, going to Exit"
fi
# 5  
Old 10-24-2008
This will find directories named construction and pass them into the script.

Code:
for all in `find / -name "construction" -type d -print`
do
  /bin/scripttorun.ksh $all
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Extract directory name from the full directory path in UNIX using shell scripting

My input is as below : /splunk/scrubbed/rebate/IFIND.REBTE.WROC.txt /splunk/scrubbed/rebate/IFIND.REBTE.WROC.txt /splunk/scrubbed/loyal/IFIND.HELLO.WROC.txt /splunk/scrubbed/triumph/ifind.triumph.txt From the above input I want to extract the file names only . Basically I want to... (5 Replies)
Discussion started by: IshuGupta
5 Replies

2. UNIX for Dummies Questions & Answers

To do directory tree search

Hello Everyone, I need to find the file / directory with the maximum timestamp in a directory tree having many files / directories. Could you please help. Thanks, H squared (3 Replies)
Discussion started by: H squared
3 Replies

3. Shell Programming and Scripting

Change to directory and search some file in that directory in single command

I am trying to do the following task : export ENV=aaa export ENV_PATH=$(cd /apps | ls | grep $ENV) However, it's not working. What's the way to change to directory and search some file in that directory in single command Please help. (2 Replies)
Discussion started by: saurau
2 Replies

4. Shell Programming and Scripting

Search in Unix home directory

I have many views in my Linux home dir under different folders mentioned below. Home 1. CCVIEWS 2. views 3. Development 4. testproject : : etc. Now i want to list all the clearcase views in my linux dir in below format to work on other script. 1) user_test_Work1.vws ... (4 Replies)
Discussion started by: saku
4 Replies

5. Shell Programming and Scripting

Checking directory permissions on UNIX directory

Hi, How do i check if I have read/write/execute rights on a UNIX directory? What I'm doing is checking read access on the files but i also want to check if user has rights on the direcory in whcih these files are present. if then...... And I check if the directory exists by using... (6 Replies)
Discussion started by: chetancrsp18
6 Replies

6. UNIX for Dummies Questions & Answers

search for a pattern in a directory?

Hi, i need help on how to do this: to make a shell script that reads 2 parameters in command line, one directory and pattern. Then it must search for the string in all files starting from the indicated directory (including subfolders) and excluding binary files. The results should show the... (1 Reply)
Discussion started by: ubu-user
1 Replies

7. Shell Programming and Scripting

File transfer from one directory to another directory in unix

Hi, I have to transfer five files from one directory to another directory in unix with the help of shell scripts. This shell script calling the param file as input parameter. Every day one file will come and fall on my source directory. Remaining files will fall on any one of the day of the... (5 Replies)
Discussion started by: easterraj
5 Replies

8. Shell Programming and Scripting

Move a file from windows directory to unix directory

Move a file from windows directory to unix directory, is this possible? if it is, can someone help me on this? Thanks! God bless! (1 Reply)
Discussion started by: kingpeejay
1 Replies

9. UNIX for Dummies Questions & Answers

Unix find command to print directory and search string

Hi i need to print pathname in which the string present using 'find' command sample output like this Pathname String to be searched ---------- -------------------- /usr/test/myfile get /opt/test/somefile get Thanks in... (4 Replies)
Discussion started by: princein
4 Replies

10. UNIX for Dummies Questions & Answers

moving files from a unix directory to a windows directory

Any body any ideas i'm failry new to this so any help would be appreciated. Cheers Steve (2 Replies)
Discussion started by: gleads
2 Replies
Login or Register to Ask a Question