How to use a terminal

4 min read

In this article, I’ll go over the fundamentals you need to understand the terminal. The aim of this article is not to explain all the possibilities, rather it is to give you a foundation from which you can build on.

The commands I will use in this article work on MacOS and other Unix base operating systems. However, the same principles should apply to any other command line interface (e.g. Windows).

What is a terminal?

You may be already familiar with the graphical user interface (GUI), that is one way of telling your computer what to do.

The terminal is another. It is mostly text-based and can feel more primitive, but it is also often more powerful.

To open your terminal, you can just search for an application called terminal and open it. It will likely look like a blank box, with a cursor and the name of your computer

It can look quite scary but it really isn’t. Let’s jump into it and run a few commands.

Running a command

To use a terminal, we type out a command and press enter to send it as our input, then the computer runs the command and sends out an output.

A very common command is ls. This will list out the contents of the current directory.

That may look a little familiar, that is because it is the same as this:

Another command you will likely use very often is cd. What that does is to change directory. Meaning, if we want to look inside the desktop folder, we would type cd Desktop and then press enter. We can then list the files inside the Desktop folder by using the ls command.

To see some more details about the files, for example when the file was last modified, we can run ls -l.

Now that you’re getting a feel for it, let’s break it down.

The anatomy of a command

Commands are generally made up of 3 parts.

  • The name of the program, for example, cd or ls.
  • Arguments. These are any extra values passed to the program, for example, we passed Desktop as an argument to cd when we ran cd Desktop.
  • Flags. These are normally used to modify the behavior of the command. You will be able to identify them because they are usually prefixed with one or two hyphens. For example, we pass the -l flag to the ls command to make it print more details when we ran ls -l.

At this point, you may have some questions:

How do I know which commands are available?

If you want to learn how to do a new thing, you can search for it through google. I assure you there will be tons of examples and recommendations.

The commands you will interact with most often are not too many, and you will likely get the hang of those pretty quickly. Here are a few

  • touch: Used to create a new file
  • mkdir: To create a new directory
  • rm: To delete files of directories
  • cp: To copy files or directories
  • mv: To move(i.e. rename) files or directories

It is possible that you will install other command line programs on your computer, such as git, homebrew, docker and so on.

How do I know the arguments and flags to pass to a command?

Most inbuilt programs come with a manual that you can access using the command man, which is fittingly a command-line tool itself. For example, to view the manual of the ls command, we would run man ls.

A convention among most external tools is to use the —help flag to display the help for the command. As an example, see git:

What to do next?

Google, Google, Google!

Search for how to do something, and try it out. If you encounter an error, search for the error and figure out what is wrong.

Don’t try to memorize things. The commands you use frequently will become second nature pretty quickly, and the ones you don’t you can always find when you need it.

Powered By Swish

Comments