0

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

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by Comatose
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.