Speed Up Terminal Workflow - Part 1


I am currently enrolled in a course called CS246 at the University of Waterloo where they are teaching us an introduction to the command line, bash and OOP principles with C++.

Something I've noticed amongst beginners is that they are entering the same repetitive commands again and again without taking full advantage of what the terminal has to offer!

This short post will give some tips and tricks on how you can speed up your terminal workflow on a linux/mac environment.

1. Add ssh aliases

If you have worked with servers before, you are probably familiar with ssh. Ssh'ing into a server can be very tedious, especially if the server address is very long...

For example:

ssh dverma@linux.student.cs.uwaterloo.ca

Why anyone would type something like that every time they log in to a server is mind blowing.

Here are 2 solutions to this:

1.1 Solution 1

cd ~/.ssh      # go into .ssh folder on your computer
touch config   # create config file
vim config     # edit config file

Now in the config file, add the following:

Host waterloo
    HostName linux.student.cs.uwaterloo.ca
    User dverma

This allows you to type the following command in your terminal:

ssh waterloo

which maps to the following command:

ssh dverma@linux.student.cs.uwaterloo.ca

1.2 Solution 2

The second solution is to create a bash alias. On your pc, you probably have a .bash_aliases or a .bashrc file in your home directory (which you can access by cd ~).

These files hold configurations for your shell. Open up either one of these files and add the following to the bottom of the file (.bashrc is where most begin putting their aliases):

alias school="ssh dverma@linux.student.cs.uwaterloo.ca"

Now, all I have to do on my terminal is type:


and I have ssh'd into the school servers.

2. SSH Keys

Something else very annoying with ssh is having to type your password in every time. One way to fix this is to generate an ssh key on your local computer, add your public key to the server, and then when you try and ssh, the server will compare your public key and the public key stored on the server. If they match then you are granted access without any password. To get started with this, first create an ssh key pair (If you have already generated an ssh key pair in the past then ignore this step):

ssh-keygen -t rsa

You will be prompted with a few questions. Just click enter for these questions as the defaults will suffice:

Enter file in which to save the key (/home/demo/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):

In the end you will be prompted with some fancy art and your public key will be stored in ~/.ssh/id_rsa.pub.

Now, to add your public key to the school server, just type the following command:

ssh-copy-id dverma@linux.student.cs.uwaterloo.ca

# NOTE: Make sure to replace your username and server name of course!

You will be prompted for your password one final time and then you are done. Now test if this worked by ssh-ing into school servers.

3. Create multiple files with similar names

A common requirement in the CS246 course is to make multiple test files. touch is a command to create an empty file. A quick and easy way to create multiple similar files is:

touch test{1..10}.txt

This will create 10 test files in the current directory ranging from test1.txt ... test10.txt

4. Incrementing numbers in vim

Another common requirement in the course is to make a suite file which stores the names of every test file. Doing such a task is tedious if you are typing each file one by one, and still hard with copy pasting.

This is where the power of vim saves the day. :)

The solution is to use a vim for loop.

In vim, open a file and access the vim command mode by type :. Now enter the following into the vim command line:

:for i in range(1,10) | put='test'.i | endfor

You should now see the following in your file:


I really hope these tips help you speed up your workflow! Let me know what you think down below and if there is something about your workflow you would like to improve.