Community

HOW TO

The Terminal Is Where Linux Begins – and Where You Should, Too

Linux terminal

Once you have a sense of the vast potential of Linux, you may be eager to experience it for yourself. Considering the complexity of modern operating systems, though, it can be hard to know where to start.

As with many things, computers can be better understood through a breakdown of their evolution and operation. The terminal is not only where computers began but also where their real power still resides. I’ll provide here a brief introduction to the terminal, how it works, and how you can explore further on your own.

Terminal, Command Line, Shell

Although “terminal,” “command line,” and “shell” are often used interchangeably, it helps to learn the general distinctions between these terms. The word “terminal” comes from the old days of Unix — the architecture on which Linux is based — when university campuses and research facilities had a room-sized computer, and users interacted with it by accessing keyboard-and-screen terminals scattered around the campus and connected to the central hub with long cables.

Today, most of us don’t deal with true terminals like those. Instead, we access emulators — interfaces on Unix-like systems that mimic the terminal’s control mechanism. The kind of terminal emulator you’re most likely to see is called a “pseudo-terminal.”

Also called a “terminal window,” a pseudo-terminal is an operating system application on your normal graphical desktop session. It opens a window allowing interaction with the shell. An example of this is the Gnome Terminal or KDE Konsole. For the purpose of this guide, I’ll use “terminal” to refer exclusively to terminal emulators.

The “command line” is simply the type of control interface that one utilizes on the terminal, named for the fact that you write lines of text that are interpreted as commands.

The “shell” is the program the command line uses to understand and execute your commands. The common default shell on Linux is Bash, but there are others, such as Zsh and the traditional Unix C shell.

File Organization

The last thing you need to know before diving in is how files are organized. In Unix-like systems, directories are ordered in an upside-down tree, with the root filesystem (notated as “/” and different from the “/root” directory) as the starting point.

The root filesystem contains a number of directories within it, which have their own respective directories and files, and so on, eventually extending to encompass every file your computer can access. The directories directly within the root filesystem, in directory notation, are given right after the “/”.

For example, the “bin” directory contained right inside the root would be addressed as “/bin”. All directories at subsequent levels down are separated with a “/”, so the “bin” directory within the “usr” directory in the root filesystem would be denoted as “/usr/bin”. Furthermore, a file called “bash” (the shell), which is in “bin” in “usr” would be listed as “/usr/bin/bash”.

So, how do you find these directories and files and do stuff with them? By using commands to navigate.

To figure out where you are, you can run “pwd” (“print working directory”), and you will get the full path to the directory you’re currently in. (Note that in all code snippet examples, the first “$” represents the command prompt, the string of text on every line before the command you enter.)

$ pwd

To see where you can go, run “ls” to list directory contents.

$ ls

When run by itself, it returns the contents of the current directory, but if you put a space after it and then a path to a directory, it will print the contents of the directory at the end of the path.

$ ls /directory/another_directory

Using “ls” can tell you more than that, though. If you insert “-l” between the command and the path with a single space on either side, you will get the “long” listing specifying the file owner, size, and more.

$ ls -l

Commands, Options, Arguments

This is a good time to explain the distinction between commands, options, and arguments. The command, which is the program being run, goes first.

After that, you can alter the functionality of the command by adding options, which are either one dash and one letter (“-a”) or two dashes and a word (“–all”).

$ ls -a$ ls –all

The argument — the thing the command operates on — takes the form of a path. Many commands do not need arguments to provide basic information, but some lend far greater functionality with them or outright require them.

Things to Do

The next step is moving between directories, which you do by running “cd” (“change directory”).

$ cd

If you supply a path as an argument, it will move you to that directory. If you don’t, it will return you to the user’s home directory (e.g., for user “pablo”, “/home/pablo”).

$ cd /home/pablo

There are two kinds of paths — absolute and relative. Absolute paths, or full paths, are ones that start from root. However, you also can give a path from the directory you’re in, in which case it is relative.

Now that you know how to find files, you’ll want to be able to do something with them. One option is to copy them with “cp”. To use it, you must supply two arguments, separated by a space: the file to be copied and where you want it to go.

$ cp original copy

If the second argument is a directory, it will place an exact copy there, but if it is a filename, it will place a copy with the given filename in the directory before the last slash.

Be aware that if a file already exists at the same place and with the same name as the second argument, the former will be overwritten.

You also can move files with the “mv” command. As with “cp”, “mv” takes the original file as the first argument and the new location as the second. Also like “cp”, if the second argument is a file name, it will rename the file to that.

$ mv original_location new_location

The overwriting, or “clobbering,” rule of “cp” applies to “mv”, too.

Off You Go

These are just the basics, but knowing them is sufficient for you to explore the system. One key to success in learning computers is to realize that it doesn’t require learning every minute detail but rather learning how to learn.

In that spirit, I want to leave you with a few resources for answering your own questions — though you can certainly ask others, including me!

If you want to examine what’s in a file without accidentally messing it up, run “less” with the file as an argument.

$ less filename

This opens it with a viewer, which prevents you from editing, giving you free rein to scroll through at your leisure.

If you’re not sure what kind of file something is, run “file” on it (again, with the file as the argument).

To get an idea of what command might be useful in a certain situation, you can run “apropos” with a keyword, and you’ll receive a list of relevant programs.

$ apropos keyword

If you want to get a sense of what a command does, along with a reference sheet for the options and arguments a command can take, you can run “man” (for “manual”) followed by the command name.

$ man command_name

In future installments, I plan to demonstrate some of the terminal’s more advanced capabilities, but if you’re looking to supplement this introduction, I recommend checking out “The Linux Command Line,” a free PDF by William Shotts.

Another good resource is the beginner Linux video series “Linux Terminal — Getting Started!” by hak5.

This should be more than enough to keep even the most ambitious of you busy until my next installment appears. Until then, happy terminal testing!

Editor’s Note – March 13, 2017: The original published version of this article did not include code snippet examples. Author Jonathan Terrasi added them in response to reader durandaltheta’s helpful suggestion.

Jonathan Terrasi

Jonathan Terrasi has been an ECT News Network columnist since 2017. In addition to his work as a freelance writer, he is a full-time computer science educator and IT decision-maker. His main interests are information security, with a focus on Linux desktops, and the influence of technology trends on current events. His background also includes providing technical commentary and analysis for the Chicago Committee to Defend the Bill of Rights.

9 Comments

  • I respectfully disagree. I drive my car every day, that doesn’t mean I should know the inner workings of my vehicle in order to be able to use it successfully. I am a long time Linux user and I am comfortable at a shell, but I prefer to use gui tools whenever possible for general usage. Most users are the same, this is the day and age of point, click, tap. If someone is inclined to learn more about cli computing, great. However, modern Linux can be used just fine daily without ever needing to drop to a shell, as it should be.

    • If your goal is to use an OS to surf the web, check emails, etc, then I think your statement is fine, you don’t need to understand the inner workings of Linux terminal and shell.

      However, if your goal is to be an efficient developer and/or sys admin with Linux, learning the shell and terminal in my opinion is vital. It will improve your efficiency and productivity 10x+.

      I would imagine the goal of the article was to help people understand how they can become more proficient with Linux, and I agree that learning shell + terminal is a great way to accomplish that.

      • >>However, if your goal is to be an efficient developer and/or sys admin with Linux, learning the shell and terminal in my opinion is vital. It will improve your efficiency and productivity 10x+. <<

        Uh wrong.. Windows doesn’t NEED any terminal or command line to do ANY function whatsoever.

        So we are trying to improve adoption of a different OS, namely Linux.

        This is why it’s been slow the command line is a necessary part of Linux, but it’s NOT for Windows.

        The reason why Linux isn’t larger than 4% world wide use is EXACTLY this.. at least a big part of it.

        We should NOT need to use command line for ANYTHING.

        I can literally do everything in a GUI in Windows, PERIOD. EVERY THING *ZERO* Exceptions.

        Why can’t Linux?!?!?! IF we want to move to a viable alternative you can’t go back to the 80’s to do it, sorry but your response is invalid.

        • >>Certainly you can work within Linux distro without using a terminal. But this article certainly shows why you should know how to use it.<<

          so you are basically saying that EVERY user should know how to use command prompt or command line for any OS? What for?

          What is the purpose to use typing just to run a command? It’s going backwards not forwards..

          I used 1.0 DOS, so I *KNOW* what I am talking about. Even OS/2 1.3.. there are lots of OS that have come and gone and they literally live and die by the command line.. nobody WANTS to use command line it’s archaic and prone to typos sorry but we should NOT need a command line or terminal to do ANYTHING at ANY point, sorry but you are like the other guy, I think you are USED to using command line but new adopters should not NEED any knowledge of knowing a command line string to perform a function that can easily be made a GUI program..

          Windows has evolved to this point, why not Linux? And I am an EXPERT user of Linux I know both Linux and Windows equally well, and I would simply find my world infinitely easier if I didn’t have to use putty to do my job, it’s just a lazy uncessary step, someone doesn’t consider it important enough to make a GUI equivalent that’s ALL this is.. has nothing to do with being better or more knowledgeable.. GUI is the state of OS, you want to type commands on your phone too?

          LOL

          Sorry but this makes ZERO sense to have knowledge of something that should have been removed 20 years ago.

          • >>Perhaps provide some lines all to themselves with your examples to improve clarity for very new readers. <<

            If you are an expert you don’t need real world examples. This article is targeted at new users, hence start at terminal.. in the name of the article. to start with a basic starting point.

            The write also gives a reference:

            >>but if you’re looking to supplement this introduction, I recommend checking out "The Linux Command Line," a free PDF by William Shotts.<<

            If you are interested in real world examples you can check that or google any of these command, no need to needlessly include stuff that can be found elsewhere.

          • The point of the article is that, although there is a GUI for every Linux function at this point, it is sometimes more efficient to use the terminal. As far as Windows is concerned, I have to use it at work. There is one function that I do which involves copying files from another server using SSH. There is a GUI available to do the job, but I find it is actually faster and more efficient to do it using Windows Command.

          • As a recent convert to Linux I have to say I agree with both sides of this discussion.

            I personally think you can do more, faster and more directly with the command line.

            I don’t profess to know how to make it do just about anything, but there a lot of people online who do, and copy and paste is alive and well, thank you very much.

            As my wife’s "IT person", I find it very useful.

            As for my wife, who just uses her computer, and wants it to "just work", the terminal doesn’t even exist as far as she is concerned. She doesn’t need to know how to use it for her everyday computing.

            So we’re both happy!

            I used to do a lot of troubleshooting for Windows users (friends and relatives).

            I have been slowly converting them to Linux and have way fewer "service" calls.

  • Certainly you can work within Linux distro without using a terminal. But this article certainly shows why you should know how to use it. I grew up on using terminal commands with DOS and even my Commodore 64. It’s also no secret that if your looking to solve a issue with Linux chances are one is going to involve a terminal command. Even today Windows has a command prompt. Unfortunately the terminal is probably one thing that scares users from trying Linux and with good reason. Most have probably never used a terminal before linux. So this article is a great intro to the terminal, its too bad more people don’t embrace it and learn how to use it.

  • Hey Jonathan, this is a helpful post for newbies. I’m an advanced power user for linux systems and I just wanted to comment to say your article would benefit from having explicit complete command examples. I’ve always found when learning about new terminal or coding functionality that I learn more from a complete example than multiple paragraphs of text.

    Perhaps provide some lines all to themselves with your examples to improve clarity for very new readers. Here is a complete command to enter at the terminal to move to pablo’s home directory:

    cd /home/pablo

Leave a Comment

Please sign in to post or reply to a comment. New users create a free account.

LinuxInsider Channels