Searching Directory names

Reply

Join Date: Apr 2009
Posts: 23
Reputation: Usura is an unknown quantity at this point 
Solved Threads: 1
Usura Usura is offline Offline
Newbie Poster

Searching Directory names

 
0
  #1
Apr 4th, 2009
Hey im completely new to bash scripting and have no idea how to search the directory name then print out the path where it was found, the filename is entered thru the command line like "./search.sh pictures" and then would make the script print all directory path names which contain the word "pictures" and print them out in order of closest to furthest but only going as deep as 5 directories, and printing an error if no directories are found with that name, is this possible?

I’ve been reading intro tutorials and searching google but haven’t found a way to do this, any help would be very appreciated
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: Searching Directory names

 
0
  #2
Apr 4th, 2009
You could look into using find: find / -name $1 or you could try doing it by piping it to grep: find / | grep "$1" , but in order for you to make it go from shallowest to deepest, you might have to do something with sort, such as piping the data to it: find / | grep "$1" | sort -g. As for only going 5 levels deep, and printing errors if not found, you are probably bound to rely on awk and/or sed.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC