cd to a directory after grepping a file
I have quite a few notes generated from my Zet-CLI. These notes are stored in a time-series format which gets annoying when I need to find a specific one, then maybe change a filename or delete a file.
To avoid going back and forth grepping, cd
-ing into directories, then grepping again
I've discovered a little trick.
Finding a file then cd-ing to it
To find a file and cd
to the containing directory, I'm using this:
cd $(dirname $(find . | grep <my search string>))
This script does the following:
find
to find all files in my current directory recursively- Pipe the results to
grep
to compare the filenames to my search string - Return the results (should be 1 thing, hopefully) to
dirname
dirname
then finds the containing directory of that file- Return the containing directory to
cd
to take me there