DEV Community

Binary Journal
Binary Journal

Posted on

10 Terminal Productivity Tips That Actually Save Time

Introduction

We all spend a chunk of our day in the terminal. Whether you're a seasoned developer or just starting, small tweaks can compound into major time savings. I've gathered ten practical tips that I use daily, with minimal setup but maximum impact.

1. Master Tab Completion

Most shells support tab completion, but many people only use it for filenames. You can complete commands, options, and even git branches. For example, typing git che and pressing Tab might suggest checkout, cherry-pick, etc.

If you're using Bash, add the following to your .bashrc to enable case-insensitive completion and show all possible matches at once:

bind "set completion-ignore-case on"
bind "set show-all-if-ambiguous on"
Enter fullscreen mode Exit fullscreen mode

2. Use Ctrl+R for Reverse Search

Instead of scrolling through your history, press Ctrl+R and start typing a command you ran before. It searches backwards. Press Ctrl+R again to cycle through matches. This is a lifesaver for long commands.

3. Create Aliases for Common Commands

If you type the same long command repeatedly, alias it. For example, I often need to update my system packages:

alias update='sudo apt update && sudo apt upgrade -y'
Enter fullscreen mode Exit fullscreen mode

Or if you use git status a lot:

alias gs='git status'
alias gl='git log --oneline --graph --all'
Enter fullscreen mode Exit fullscreen mode

Put these in your .bashrc or .zshrc.

4. Navigate with cd - and pushd/popd

cd - takes you to the previous directory. But for more complex navigation, use pushd and popd. They maintain a stack of directories. Example:

pushd /var/www/myproject
# do some work
popd
Enter fullscreen mode Exit fullscreen mode

You'll be back where you started without typing the full path again.

5. Use fc to Fix and Rerun Commands

If you made a mistake in a long command, instead of retyping it, use fc to open the last command in your default editor. Edit it, save, and it runs. For example:

fc
Enter fullscreen mode Exit fullscreen mode

Or fc 100 to edit command number 100 from history.

6. Take Advantage of Process Substitution

Process substitution allows you to treat command output as a file. This is handy for comparing outputs without creating temporary files:

diff <(ls dir1) <(ls dir2)
Enter fullscreen mode Exit fullscreen mode

This shows the difference between directory listings without ever writing a file.

7. Use xargs for Batch Operations

xargs takes input and runs a command on each item. For instance, to delete all .log files older than 7 days:

find . -name "*.log" -mtime +7 | xargs rm
Enter fullscreen mode Exit fullscreen mode

Be careful with spaces in filenames; use -0 with find -print0 for safety.

8. Learn Keyboard Shortcuts

In your shell, learn these essential shortcuts:

  • Ctrl+A / Ctrl+E: jump to beginning/end of line
  • Ctrl+U: delete from cursor to beginning
  • Ctrl+K: delete from cursor to end
  • Ctrl+W: delete word before cursor

These save you from holding the arrow keys for ages.

9. Use !! and !$ for Quick Substitution

  • !! repeats the last command. Add sudo to it: sudo !!
  • !$ expands to the last argument of the previous command. For example, after mkdir newdir, you can do cd !$ to enter it.

10. Make a scratch Directory

Sometimes you just need a place to test things. Create a ~/scratch directory and cd there whenever you need to experiment. It keeps your main workspace clean.

Conclusion

These tips are easy to adopt. Start with a couple and build from there. Over time, you'll wonder how you managed without them. Your terminal should be your friend, not a hurdle. Happy coding!

Top comments (0)