A replacement for the Linux cd
An intelligent cd (change directory) that remembers where you were and allows yout set up shortcuts for directories
We called it ‘berth’ because it allows you to berth your favourite directories for recalling later. When it’s installed it acts like cd on steroids.
You can download it here.
Get Realtime’s stories in your inbox
Join Medium for free to get updates from this writer.
Berth is a better cd command.
- Set up shortcuts to your favourite directories so you go to them quickly
- Keep track of all the directories you have visited so you can return to them easily
- Load pre-set lists of directories
- Change your prompt line to show in a different colour or show the current directory shortened
- And much more!
For example, if you have directories under your home directory called:
- Documents
- Downloads
- Pictures
- Music
- Music/Classics
- Documents/Linux-tools
- Documents/Project-x
You can create shortcuts (marks) by going to the directory and setting it with the -m command:
~/Music/Classics$ cd -m clas # or -mclas - the space is optionalMarks can be displayed by @ or $ @m (by default @ is an alias for cd @):
$ @m
Marks:
mac ~/mac_share
doc ~/Documents
down ~/Downloads
pic ~/Pictures
mus ~/Music
clas ~/Music/Classics
lx ~/Documents/Linux-tools
px ~/Documents/Project-xAnd to go to the directory:
~$ cd -spx
~/Documents/Project-x$ cd -sclas
~/Music/Classics
~$ cd -sclas
~/Music/Classics$Set in your .bashrc (or equivalent):
alias @=’cd_berth @’And type @ at the command line to show the full history and presets.
Enter the -H command for full help:
$ cd -H
cd [-LPe@] [--] [dir] Change directory (a faithful cd)
cd - Toggle to the previous directory
cd <n> Go to history entry <n> (0 is previous)
cd =<text> Go to the most recent history entry matching <text>
cd -n <dir> Change directory without pushing onto the stack
cd @ List history and marks
cd @h List history
cd @m List marks
cd -m [<name>] [<dir>] Mark <dir> (default: here) as <name>
(default name: the directory's basename)
cd -s <name> Go to mark <name>
cd -d <name> Delete mark <name>
cd -a<n> Go to suggested directory <n>
cd -c Clean out entries whose directories are gone
cd -w [<file>] Write history and marks to <file>
cd -r [<file>] Read them back
cd -o List all settings
cd -o <name>=<value> ... Change settings
cd -o save [<file>] Save settings (to ~/.berthrc, or to <file>)
cd -o load [<file>] Load settings
cd -h | -H | -v Help, detailed help, version
Angle brackets mark a value you supply; do not type the brackets. Mark
names are bare words - "cd -m build" then "cd -s build", no brackets or
quotes. Names may be anything, including digits, so "cd -s3" and
"cd -s build" work the same way.
-L, -P, -e and -@ are passed to the cd builtin unchanged; use -- or -n to
reach a directory whose name begins with a dash.
Examples:
cd -m Mark the current directory under its own name
cd -m build Mark the current directory as "build"
cd -m src ~/proj/x Mark ~/proj/x as "src" without going there
cd -s build Jump to the "build" mark
cd =proj Jump to the last visited path containing "proj"
cd 2 Jump back to history entry 2
cd - Bounce between the two most recent directories
cd -o color=green Green prompt from now on
cd -o color= len= Reset colour and length to their defaults
cd -o save Make the current settings permanent
cd -o save ~/proj/x/.berthrc Write a per-project settings file
cd -o load ~/proj/x/.berthrc Load it when you switch to that project
Settings, all changed with "cd -o name=value" and made permanent with
"cd -o save". An empty value restores the default: cd -o color=
SETTING VALUE DEFAULT
color blue blue
len 40 40
prompt on on
pre "" ""
post "" ""
history 50 50
rows 9 9
file /Users/pbraham/.berthdirs /Users/pbraham/.berthdirs
dedup on on
autoload off off
autosave off off
prune on on
Settings file: /Users/pbraham/.berthrc
color Prompt colour: black red green yellow blue magenta cyan white,
or none. A raw escape sequence also works.
len Truncation length for the directory shown in the prompt.
prompt off leaves PS1 entirely alone and restores it if already set.
pre, post Override the strings placed either side of the directory.
Wrap non-printing characters in \[ ... \] yourself.
history Maximum number of stack entries kept.
rows Number of rows shown by cd @.
file Default file for -w and -r (the directory stack, not settings).
dedup on keeps the stack a true most-recently-used list.
autoload on reads the history stack and marks from the "file" setting
(default ~/.berthdirs) when berth starts up.
autosave on writes the history stack and marks to that same "file" when
the shell exits. Turn both on to have your stack and marks
persist across sessions. (autosave is skipped with a warning if
you already have your own EXIT trap.)
prune on reports and removes entries pointing at vanished directories.
Per-project settings:
"cd -o save <file>" writes the non-default settings to any file, and
"cd -o load <file>" reads them back. Keep a .berthrc in each project and
load it (by hand, or from a directory-change hook) to switch colour,
prompt length and so on as you move between projects. Your personal
~/.berthrc is always read first at startup, so a project file need only
list what differs.
The history stack is in BERTH_HIST, and marks are in BERTH_MARK_NAME and
BERTH_MARK_DIR. Directories are recorded as $PWD, so if you have set -o
physical they are physical paths, and otherwise they are the logical paths
you actually walked.
berth 1.0.0 (24-JUL-2026)






