943,935 Members | Top Members by Rank

Ad:
Apr 4th, 2009
0

Searching Directory names

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 1
Light Poster
Usura is offline Offline
30 posts
since Apr 2009
Apr 4th, 2009
0

Re: Searching Directory names

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.
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: Need help writing a shell script to do the following:
Next Thread in Shell Scripting Forum Timeline: Zip files by date





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC