How do I search parent folder only?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How do I search parent folder only?
# 1  
Old 04-14-2008
How do I search parent folder only?

I have a directory /dir1/dir2/dir3/dir4/dir5.

How can I search for files only in dir4/ and not in dir5? I tried the maxdepth command, but it doesn't work in this flavor of sun OS.
When I search for files in dir4, it's giving me results from dir5 as well. I don't want this.


Thanks.
# 2  
Old 04-16-2008
How about:
Code:
ls <pattern>

eg ls -dF /dir1/dir2/dir3/dir4/*filestofind* | grep -v '/'
# 3  
Old 04-17-2008
couldn't you cd into dir4 and do a
Code:
 find . -name whaterver -print

and it will only search the current directory you are in?
# 4  
Old 04-17-2008
I am not sure if Find command with the current directory will work here as it will still search within the subdirectories of the current directory..Smilie

find . -name 'dir5' -prune -o -name whaterver -print

this will I guess take care that it will not dig further in to dir5

Last edited by rohit.shetty84; 04-17-2008 at 06:32 AM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Request for Shell script to move files from Subfolder to Parent folder and delete sub folder

Hi Team, I am new to shell script and there is a requirement where files should be moved from Subfolder to parent folder. Eg: parent folder --> /Interface/data/test/IN Sub folder -->/Interface/data/test/IN/Invoice20180607233338 Subfolder will be always with timestamp... (6 Replies)
Discussion started by: srivarun15
6 Replies

2. Shell Programming and Scripting

Search and open a folder and file

here is the path on Macintosh: Macintosh HD/Users/shawn/Desktop/ATP/ATP14 bon bon/ATP14 bon bon.jpg I need to find the folder with ATP14 in the name, then open the folder I need to find the file whose name starts with ATP14 in the folder in 1 above I had been using this in Applescript... (1 Reply)
Discussion started by: sbrady
1 Replies

3. Shell Programming and Scripting

Move parent folder if contents match a parameter

Hi all, Hoping someone can help. I'm looking to be able to search a particular folder path for folders that contain certain files / formats and then move the parent folder. eg. /foo/bar/folder1/file.exe /foo/bar/folder2/file.exe and then move the folder1/2 tp another folder. So if... (1 Reply)
Discussion started by: springs2
1 Replies

4. UNIX for Dummies Questions & Answers

Grep with parent folder

Hi, When I do ls -l | grep -h STRING I need not only to get those files, but also the parent folder of those files, no idea how do that. BTW the names of those parent folders are never longer than 3 digits, if that helps. Any assistance most welcome, /bw, OmarKN Please... (9 Replies)
Discussion started by: OmarKN
9 Replies

5. UNIX for Dummies Questions & Answers

Search current folder and subfolders with grep

Hello, Neither ‘Grep -r' nor ‘grep -R' is working in my environment. (Searching for a text pattern in the files) Any suggestions... Using SunOS 5.9 Thanks, Trinanjan. (1 Reply)
Discussion started by: bhanja_trinanja
1 Replies

6. Shell Programming and Scripting

Search in folder and subfolders

How can this be done? I mean, I want to search for all *png *jpg *bmp files in my ~/Pictures/ folder....How can I list them? Thank you geeks :) :b: (2 Replies)
Discussion started by: hakermania
2 Replies

7. Shell Programming and Scripting

To replace a string in file by its parent folder name.

Hi all, I have a directory structure like "folder1/folder2/website_name/folder3/folder4/file.php." I need to write a script which will enter into file.php and replace a particular string of characters with "website_name" folder name. In folder2,there are many such website's folders kept.So... (4 Replies)
Discussion started by: arien15488
4 Replies

8. Shell Programming and Scripting

How to read a subfolder one by one in parent folder?

Hi friends, I am getting some trubles in folder reading. I am having 10 subfolders inside server7 folder. i wanna to read a subfolder name first and check if the foldername gets started with "http". if so , i need to read a file inside that folder. This willl continue for... (1 Reply)
Discussion started by: kamatchirajan
1 Replies

9. Shell Programming and Scripting

full path of a file situated either in parent's dir. or parent's parent dir. so on...

hi experts(novice people can stay away as it is no child's game), i am developing a script which works like recycle bin of windows. the problem i am facing is that when ever i am trying to delete a file which is situated in parent directory or parent's parent directory i am unable to... (1 Reply)
Discussion started by: yahoo!
1 Replies

10. Shell Programming and Scripting

Search for a File Name in a folder

Hello All, Can you please help me with this request. I have to identify a file (having file name with perticular pattern) with in a range. Example: input file name can be: myfile2007_03 myfile2007_45 myfile2007_198 myfile2007_25 myfile2007_101 my program has to identify... (1 Reply)
Discussion started by: sbasetty
1 Replies
Login or Register to Ask a Question