What is the best way to sort the results of $ find . -name scripts -type d
by the occurrences of '/' and then choose the first result?
I want to create a function that would cd
down to a common folder in a project. I wanted it to be flexible based on your relative directory.
So if I have 10 projects all with similar folder structure:
~/project-a/project/folder/structure
~/project-b/project/folder/structure
~/project-c/project/folder/structure
I could:
$ cd ~/project-a
$ cdd structure
And be dropped down into ~/project-a/project/folder/structure
Update
I'm unable to sort results in any predictable way, example:
$ find . -type d -name "themes"
./wp-content/plugins/contact-form-7/includes/js/jquery-ui/themes
./wp-content/plugins/jetpack/modules/infinite-scroll/themes
./wp-content/plugins/smart-youtube/themes
./wp-content/plugins/wptouch-pro/themes
./wp-content/themes
./wp-includes/js/tinymce/themes
I'd like the cdd
function to drop down to the closest result. In this example it'd be ./wp-content/themes
.
find -depth | tac
work? Haven't tested or thought this through, but I do see the problem (thatfind
can go far down in one directory before checking other directories.) – Peter Cordes Jul 24 '15 at 02:20