Bash Bookmarking Snippet

Here’s a little snippet that allows you to bookmark paths in Bash. Simply type “bookmark tagname”(only one word allowed, rest is ignored), and you can type go-tagname to go to that path.

The best part is that these are preserved across all terminals and sessions, and there’s TAB completion – simply press tab after typing go-.

Feedback, suggestions and bug reports go in the comments box. Put the following code in your ~/.bashrc to get started. You may need to re-source your terminal.

</p>

<h1>BASH BOOKMARKING v0.1</h1>

<h1>anirudh -@t- anirudhsanjeev.org</h1>

<p>#</p>

<h1>Bookmark a path in bash to be able to go back to it later</h1>

<h1>Navigate to the path you want to bookmark, and say</h1>

<p>#</p>

<h1>bookmark bookmarkname</h1>

<p>#</p>

<h1>This will add an alias, go-bookmarkname. Now you can type go-bookmarkname</h1>

<h1>from any path and you'll be taken there. Bash will also do TAB-completion</h1>

<h1>for you, and it's more efficient than creating aliases.</h1>

<p>function bookmark()
{
echo "alias go-$1='cd "<code>pwd</code>"'" >> ~/.bashbookmarks
source ~/.bashbookmarks
}</p>

<h1>Make sure to load the bookmarks beforehand</h1>

<p>touch ~/.bashbookmarks
source ~/.bashbookmarks

2 Responses to “Bash Bookmarking Snippet”


  • Nice little thing that I didn’t know that I have always needed. Just got it to work. You should provide the code as ascii as well. Not only does the html-formatting make it unintelligible: it also removes information. Thus, obviously a pair of backticks have been lost around the ‘pwd’ command. Cool that you by basing it on aliases, you provide tab-completion.

  • HM:

    A wordpress update has broken my code snippets. it’s on my list of things to fix up over here.

    Glad the script could help. I plan to put it as a github gist sometime.

Leave a Reply