// I need to

ModernizeUpgrade without breaking it RescueFix what someone else started Build NewTurn an idea into a product Reach More PeopleGet found, get used, include everyone

// Company

Case StudiesExpertiseAbout + CareersResourcesContact Book a call →
≡articleBuild New

Finessing the Command Line for Fun and Profit

Repeating the same shell commands all day? Simple Bash tips to save time, starting with folder bookmarks via the To tool and handy cd shortcuts.

Art+Logic Jun 24, 20132 min read

From the Art+Logic archive · written in 2013. The tools may have moved on; the thinking still holds.

Software screen capture

As someone who spends a lot of time using the command line, I’m often repeating the same commands and jumping through the same hoops. Over the years I’ve learned a few lessons. Here are some simple tips to save you time in the ’shell.

Folder bookmarking

For a single project, I may have a handful of directories I often need to switch to from the command line. Over time, this can become tedious. A solution might be to create aliases such as “cdbanana” to take me to the Banana Stand project base directory, but that itself is kind of messy.

“To”, written by Mara Kim, alleviates this problem by allowing you to set bookmarks from folders you’re cd’ed into, and jump to them from anywhere else. The source is released under the GPL on Github.

Set a bookmark on the current directory using: to -b <new bookmark name>

Jump to your bookmarked directory from anywhere else:to <bookmark name>

Example:

bananaProj $ cd Web/protected
protected $ to -b banana
protected $ cd /some/other/folder
folder $ to banana
protected $

Bash shortcuts

You can use cd - repeatedly to switch to the previously-selected directory.

home $ cd radams
radams $ cd -
home $ cd -
radams $&lt;/pre&gt;
You can also refer to the previous directory in other commands, like:
&lt;pre&gt;radams $ cd ~/Documents
radams $ find ~- -name &#039;.bash*&#039;

Not the best example, but you see how it works.

You can also easily re-issue commands from your Bash history:

radams $ history | grep revert 
474  git revert e3ac6a088eef1502875d96d3b7d678b6740a3a24
radams $ !474

As soon as I hit enter, the entire command is entered and executed.

You can also enter !find, !grep and so on to re-execute commands from your history whose initial text matches the word after the exclamation mark. If it’s easier to find by an argument you passed to one of those commands, use a question mark after the exclamation, e.g. !?secret-doodle would match a mysqldump -u root -p"secret-doodle".

And finally, don’t forget about the built-in history search, which you’re sure to enter by mistake some day while furiously pounding the keyboard. Ctrl+R will prompt for a search, and when you find a command from your history you want to run, hit enter, or arrow left or right to edit it.

keep going

More to explore in Build New.

All Build New resources →
let's talk

Got a problem like this one?

Tell us what's stuck. A real person replies within one business day.

Talk to our team →

Talk to people who know software, not a sales script.

Your first call is with Aja, our VP of Sales. He'll help make sure you're solving the right problem. Here's what you'll cover together:

  1. What you're trying to accomplish

    The business goal first, then the technology.

  2. Possible approaches

    And the tradeoffs of each, in plain language.

  3. Risks you may not have considered

    Technical and business, before they cost you.

  4. Whether AI changes the math

    What's practical, and what's just hype for your project.

  5. Sensible next steps

    Even if the right next step is not us.

book-a-call.ics

Loading the scheduler…

Open the booking page →

Some problems are easier to explain in writing. Send us a few lines about what you're working on, and we'll reply within one business day. Helpful to include:

  1. What the software does, or should do
  2. What's stuck, or what's worrying you
  3. Any deadline or budget you have in mind
note.md

Loading the form…