Linux Terminal

The most powerful feature of the Linux operating system is its terminal. There was a time when the whole Linux system was terminal-based but with time more graphical tools have been developed. And now we have beautiful desktop environments like what we see on Ubuntu. The main difference between using the terminal and using the normal graphical methods, as we see on Mac or Windows, is that instead of pointing and clicking with a mouse to control your computer, you will be typing with a keyboard instead. Knowing how to use the terminal gives you pretty much absolute control over how your computer works. This level of control over your computer can not be achieved in any other operating system which makes the terminal an incredible skill to learn. 

Shortcut Open Terminal in Mac

Press Command + Space Bar on your Mac Keyboard

Type in “Terminal”

When you see Terminal in the Spotlight search list, click it to open the app

Our First Commands

The terminal is a very powerful tool that is designed to allow users to issue commands that are known to their computer. The computer then obeys these commands and makes stuff happen as a result. Now we will be running our first command. 

Type in your terminal echo hello and press enter. You will see that `hello` written on the screen. 

 

echo command in linux is used to display line of text/string that are passed as an argument . This is a built in command that is mostly used in shell scripts and batch files to output status text to the screen or a file.

Geeks for Geeks

Now let’s try another command cal. Type cal and press enter. You will see the current’s month calendar with today’s date highlighted. 

This is just the default behavior of cal command. With Linux commands, you don’t have to stick with the default behavior, you can customize the behavior of Linux commands to exactly what you want them to do. 

Let’s customize the behavior of cal command. So let’s say that we needed the calendar for the current year instead of the current month. we can write:

cal 2022

And we will get a yearly calendar for 2022 with today’s date highlighted. 

Now a command can also have an option that allows you to customize the behavior of any command. So if you type cal -y it will give you the same result as cal 2022. So there are two ways we can customize a command’s behavior, give it input or we can give it options. We will go into the difference between an option and input later. 

If you want to clear your terminal screen there are two ways to do that:

  1. Type clear and press enter.
  2. There is a shortcut for that as well which is on Mac Command (or Cmd) ⌘ + Control (or Ctrl) ⌃ + l.
Command History

If you want to re-enter the previous command on the terminal, you can just use the up arrow key and it will bring the previously typed command to the terminal. You can keep pressing the up arrow key and it will cycle backward through the commands that you already run. You can actually get all the commands that you have entered in the terminal with history command. Type history and press enter and you will see a list of commands run in your terminal with a number associated with it. If you want to run a command you have to enter !<command number>. So for example, if your command is at number 8. All you have to do is !8.

History command can go through potentially hundreds of commands that you have run in your terminal. If you want to run the most recent commands, you can use !! command.