APC Australia

Working with les in the Linux terminal

Nick Peers flexes his fingers and dives head-first into the inky darkness of the terminal to show you how to start handling the commands.

-

The terminal is an incredibly important part of your Linux desktop. It doesn’t matter how wedded you are to point and click over the command line, at some point, you’re going to have to dip your toe in the terminal’s dark expanse and use it. Don’t worry, though, because the terminal isn’t as scary as it might appear, and if you take the time to learn the basics, you’ll discover it can be a far quicker and more effective way of getting certain tasks done.

As you’d expect, a terminal effectivel­y gives you access to your Linux shell, which means it works in exactly the same way using the same language (Bash). This means you can do anything in the terminal you’d normally do at the command line, all without leaving the relative comfort of your desktop. That makes learning how to use the terminal — and Bash — doubly advantageo­us, as it gives you your first glimpse into working with the underlying Linux shell. And over the next few articles, that’s exactly what you’re going to learn — how to get to grips with the terminal.

We’re basing this tutorial on Ubuntu, so start by opening the Dash and typing “terminal” into the search box. You’ll find the termina,l of course, but you’ll also see two entries called ‘UXTerm’ and ‘XTerm’, too. This highlights the fact there are multiple terminal emulators that you can run in order to interact with the shell. There are difference­s between them, of course, but they fundamenta­lly do the same thing.

For the purposes of this tutorial, we’re sticking with the default terminal, which is basically the ‘gnome-terminal’ emulator — technicall­y, it’s emulating a TeleTYpe (TTY) session. It has all the functional­ity you’ll need, but both XTerm and UXTerm are worth noting because, although they are more minimalist tools, neither require any dependenci­es to run. This means if anything stops the main terminal from running, you can use either as a backup. As an aside, the only difference between the two is that UXTerm supports the expanded Unicode character set.

HOW BASH WORKS

The Linux shell uses the Bash shell and command language to perform tasks, and it uses a relatively straightfo­rward syntax for each command: utility command -option .

The ‘utility’ portion of the command is the tool you wish to run, such as ls for listing the contents of a directory, or apt-get to trigger the APT package management tool. The

command section is where you specify exactly what you want the

utility to do — e.g. typing apt-get install instructs the package management utility to install the named package: apt-get install vlc .

The -option section is where one or more ‘flags’ can be set to specify certain preference­s. Each flag is preceded by one or two dashes (--) and the most useful of all is the --help option, which provides a brief descriptio­n of the utility, plus lists all available commands and options, e.g. ls -l The -l flag tells the list directory tool to provide detailed informatio­n about the contents of the folder it’s listing, including permission­s, who owns the file, the date it was last modified and its size in bytes. Utilities can be run without any commands or options — e.g. ls on its own provides a basic list of all folders and files in a directory. You can also run utilities with a combinatio­n of commands and/or options.

RESTRICTED ACCESS

Open the terminal and you’ll see something like this appear:

username@pc-name:~$ . This indicates that you’re logged on to the shell as your own user account. This means that you have access to a limited number of commands — you can run

ls directly, for example, but not to install a package using apt-get , because the command in question requires root access. This is achieved one of two ways — if you’re an administra­tive user, as the default user in Ubuntu is, then you can precede your command with the sudo command: sudo apt-get install vlc . You’ll be prompted for your account password, and then the command will run. You should find that you can run more sudo-based commands without being re-prompted for your password (for five minutes) while the terminal is open. On some distros, you can log on to the terminal as the root user with su — you’ll be prompted for the root password, at which point, you’ll see the following prompt: root@pc-name:~$ .

Once logged in, you can enter commands with no restrictio­ns. We recommend you use the sudo command rather than this approach, and if you’re running Ubuntu, then you’ll find su won’t work because the root account password is locked for security reasons.

When installing some distros or adding new users to Ubuntu, you may find that your user account isn’t added to the sudo group by default. To resolve this, you need to open the terminal in an account that does have root access (or use the su command if supported) and type sudo adduser <username> sudo . You can also add the user to other groups with the command by listing all the groups you wish to add, for example: sudo adduser <username> adm sudo lpadmin sambashare .

Another handy tool is ‘gksudo’, which allows you to launch desktop applicatio­ns with root privileges. It’s of most use when wanting to use the file manager to browse your system with root access: gksudo nautilus . Make sure you leave the terminal open while the applicatio­n is running, otherwise it’ll close when the terminal does. When you’re done, close the applicatio­n window, then press Ctrl-C in the terminal, which interrupts the currently running program and returns you to the command line.

We’ve already discussed the --help flag, but there are other help-related tools you can use, too. First, there’s

whatis — which you can type with any command to get a brief descriptio­n of it and any specified elements: whatis apt-get install vlc will describe the apt-get tool, the install argument and what package vlc is. Flags are ignored.

If you’re looking for a full-blown manual, then the ‘man’ tool provides access to your distro’s online reference manual, which is started with man intro . This provides you with a long and detailed intro to the command line. Once done, press Q to quit back to the terminal. For more advice on navigating the manual, type man man or pair it with a tool, e.g. man ls .

Now you’ve taken your first steps into the world of the terminal, check out the box ‘Your first terminal commands’, above, for some useful package management commands you can work with. Next issue, we’ll look at how to navigate your filesystem from the terminal, plus launch programs and delve into more useful shortcuts to help speed up the way you interact with the command line.

 ??  ?? The ‘--help’ flag can be used with any command to find out what it does, plus what arguments to use.
The ‘--help’ flag can be used with any command to find out what it does, plus what arguments to use.

Newspapers in English

Newspapers from Australia