iTranslated by AI
Bringing the 'Back' Button to CLI: Navigating cd History with bd
Click here for the article on design and implementation
Why I made it
Web browsers have a "Back" button.
On the other hand, the terminal's cd doesn't offer the same experience.

When it comes to going back in the terminal...
-
cd -is useful, but it can only return to the immediately preceding directory. -
pushd/popd/dirsare invaluable in shell scripts, but they are a bit cumbersome for everyday directory navigation.
So, I created a CLI tool to trace the movement history of cd called back-directory (the bd command).
What you can do with the bd command
bd is a tool that treats directory navigation as "history."
-
bd: Go back to the previous directory -
bd ls: List recent movement history -
bd 003cN003e: Go back by specifying a number -
bd c: Undo the lastbdcommand (Cancel)
Installation
The installation steps are also documented in the README, but you can install it using the following command:
curl -fsSL https://raw.githubusercontent.com/01-mu/back-directory/main/scripts/install.sh | sh
Checking Movement History (bd ls)
First, move around as usual with cd.
$ cd ~/work/project
$ cd frontend
$ cd app
$ cd dashboard
$ pwd
~/work/project/frontend/app/dashboard
Now, run bd ls.
bd ls
Output:
[3] ~/work/project
[2] ~/work/project/frontend
[1] ~/work/project/frontend/app
- The numbers represent the "distance you can go back."
- The recent movement history relative to your "current location" is listed at the top.
Go back to the previous directory / Go back by number (bd / bd <N>)
Look at the list and specify the number you want to go back to.
bd 2
Now you can go back to ~/work/project/frontend.
You can focus only on the "back" operation without having to worry about "where you came from."
Also, if you want to go back to the previous directory, use bd.
bd is a shortcut for bd 1.
In actual usage, I believe there will be more situations where you simply run bd repeatedly to go back rather than picking from the list via bd ls → bd <N>.
Undo (bd c)
This is a cancel command for cases where you've accidentally gone back too far.
bd 3
# Whoops, went back too far
bd c
bd c cancels the previous bd command and returns you to where you were.
Summary
bd is a tool that treats directory navigation as history and allows you to retrace your steps.
-
bd: Go back to the previous directory -
bd ls: View history -
bd <N>: Go back by number -
bd c: Undo the lastbdcommand (Cancel)
I focused on "going back" and aimed for simplicity.
I think it will really resonate with those who frequently move back and forth between directories in the terminal.
Discussion
アカウント再作成に伴い、昨日投稿の本記事を再投稿しています。
何卒ご容赦ください。