We see terms like Terminal, Shell, and Alias thrown around all the time. But what do they mean? What is the difference? How can we utilize them more efficiently to our benefit? In this blog, my aim is to demystify these concepts by using the awesome power of Keyboard Shortcuts and Aliases. But first...
The DEC VT100, a widely emulated computer terminal
What is the Terminal?
Before the days of fancy Graphical User Interfaces(GUI) like Windows or Mac, there was the terminal. A simple screen interface that one could enter command prompts for the machine to execute. A modern version of this is the Terminal Emulator which is included in the GUI. The terminal serves as a text input and output environment for your computer. You can enter and execute commands with it and receive a visual representation of what is going on under the hood. If you think a console is the same thing, you are basically correct! The only difference is that the console is a specific interface that communicates only with the attached computer system.
What is a Shell? Shell is terminology that refers to an interface that provides the user access to the services of an operating system. They can be command line shells (like Unix or DOS) or GUI shells (like Microsoft Windows)
What is the Bash?
A bash is simply, one of the command line shells. It is one of the more popular ones that are available. A bash’s main job is to start other programs.
I know the abyss of the dark screen seems daunting at first, but let us look into some helpful tips to help navigate the waters. The more you learn about something, the less intimidating it becomes. So let’s explore some of the more useful keyboard shortcuts to become more efficient at using terminals.
After researching, I have pulled together a list of shortcuts I find to be the most helpful.
Ode to Tab
As Waseem Mansour put it in their blog https://www.redhat.com/sysadmin/top-10-shortcuts, "Tab is my ultimate friend - it never lets me down. It is the handiest shortcut and time saver ever developed." After a busy morning of reviewing and toy problems, I can't count how often I clone down a repository only to type "cd" into the terminal and then look blankly at the screen. What was the name of the directory that I was to code in again? Enter The Tab button. One press and it will either autocomplete the string or it will display the available options.
//go from this...
James-MacBook-Pro:Junior jprogram$ cd //uhhhh
//to this with TAB
James-MacBook-Pro:Junior jprogram$ cd //tab populates the list!
immersion-20XX-09-self-assessment-week-00/
immersion-20XX-09-self-assessment-week-01/
immersion-20XX-09-classiest-of-dance-parties/
immersion-20XX-09-underbar-again/
James-MacBook-Pro:Junior jprogram$
CTRL + L
Is your terminal cluttered? Ctrl + L will "clear" your Terminal Screen. You can still see your command history if you scroll up!
CTRL + U and CTRL + K
Typing in a long command only to realize you messed up in some way? Instead of pressing Backspace twenty times, position your cursor to where the mistake is. CTRL + U will erase everything from the beginning of the line to the cursor, CTRL + K will erase everything from the end of the line to the cursor.
CTRL + _
How many times have I pressed Ctrl + Z in my terminal only to see nothing undone? Ctrl + _ to the rescue!
CTRL + N and CTRL + P
Finally, Ctrl + N and Ctrl + P are the next command from the history and the previous command from the history, respectively. You can use these to pull up commands from your recent history instead of retyping.
Aliases
Not content with default shortcuts? Why not make your own?
Aliases are a fun little time saver that you can program yourself into your Code Editor! In your terminal, type alias, followed by the keystrokes you want to assign to the alias, the equal sign, and then the command you want to truncate in quotes.
git commit -m "so tired of typing git commit"
//let us use an alias!
alias gc="git commit -m"
gc "so much easier"
If you want to untether your alias, simply type unalias <-and your alias-> and press enter. Your imagination is really the limit when it comes to creating these timesavers!
Note: aliases are exclusive to their individual terminals, if you exit out or create a new terminal, you will have to set the alias up again. If you want a permanent alias setup method here are some instructions:
//first open your file editor. In this case, VSCode
// Then enter:
code ~/.zshrc
This will open the zshrc file in your editor. Enter the aliases you want to use and then save the file. Here are some examples:
Finally, run your source command, which sources the file to your current shell to make the aliases in that file available:
source ~/.zshrc
//You will have to run this on every new terminal
//to access your alias list
Now you will have a list of aliases ready to go! The efficiency is staggering!
In conclusion, I hope this blog helps you to become more familiar with the quality-of-life features that are built into your terminal. Mastering these shortcuts and aliases can level up your programming experience if you make an effort to use them. Soon they will become second nature faster than you can say 'Command + C and Command + V'!
Sources:
Terminal/Shell:
https://en.wikipedia.org/wiki/Computer_terminal
https://simple.wikipedia.org/wiki/Shell_(computing)
Keyboard Shortcuts:
https://www.redhat.com/sysadmin/top-10-shortcuts
https://stackoverflow.com/questions/9679776/how-do-i-clear-delete-the-current-line-in-terminal
Aliases:
https://jonsuh.com/blog/bash-command-line-shortcuts/
https://www.atatus.com/blog/14-useful-bash-aliases-that-make-shell-less-complex-and-more-fun/
Permanent Aliases:
https://adamtheautomator.com/zsh-alias/#:~:text=But%20remember%2C%20creating%20an%20alias,available%20in%20each%20new%20shell.
https://www.youtube.com/watch?v=hFCb-hFjHf0&t=260s
Top comments (0)