Recently we have concentrated on the desktop aspects of Linux, particularly on the Ubuntu Linux distributions.
This time we will move away from the desktop and instead take a look at the shell environment, which needlessly terrorises many newcomers to Linux and Unix. We will also examine file permissions, what they mean and how to manipulate them.
The shell
It is a common misconception that Linux is a text-based operating system with a
graphical user interface that sits on top. This belief perhaps stems from the
older Microsoft Windows days, when the OS was indeed a GUI that ran on top of
Dos. In Linux this is not true. The base operating system is simply the kernel,
as it is for Apple’s OSX and other Unix variants.
The operating system can have many user interfaces to it. On a network router it may be a web interface, on a handheld device it could be a pure GUI interface or over a terminal a command-line one. No interface requires any other. The oldest of these is the text-based shell interface, which is very well supported under any Unix-based operating system.
A shell is an advanced command interpreter. It is a program that can run interactively, where you type commands in turn, or automated, where it runs through a script and where simple programming techniques can be used to carry out tasks. The shell executes the commands in question and lets them output information back to you.
A shell runs in a terminal. This can be a real hardware terminal or through software as a terminal application. A typical Linux system will have the Linux console (which runs outside of a GUI environment), Gnome’s ‘terminal’ or KDE’s ‘konsole’ and the venerable ‘xterm’; while on OSX the ‘Terminal’ application is supplied.
When a terminal application starts up, a shell is launched. On OSX and most Linux systems this is GNU Bash, which we will look at here. The first thing you see is the shell prompt. Because this is configurable it will vary from system to system, but as a rule it ends with a dollar sign if you are logged in as a normal user, or a hash (#) sign if root.
You can cause endless damage by running commands as root, so it is useful to see this on the prompt itself. On an Ubuntu system the shell prompt defaults to your user name, the computer name and the current directory, for example, ‘barry@mycomputer:~ $’. The tilde (~) is shorthand for your home directory, thus ~/Desktop would refer to /home/barry/Desktop.
Running commands is a simple case of typing them in and pressing Enter. You can use the cursor keys to move around the line and the backspace and delete keys to edit. The first word you type (separated by spaces) is the command and every other word (again separated by spaces) is a command argument information supplied to the command to control how it works. If you type ‘bring me some coffee’, the shell will return the message ‘bring: command not found’. Entering a more likely ‘mkdir stuff’ will have the shell locate the ‘mkdir’ command and run it with ‘stuff’ as an argument. The mkdir program will then create a directory called ‘stuff’ in the current directory.
Keyboard shortcuts
As commands can often be long, there are a few ways to help save your fingers
from too much typing. As above, you can edit the current line, but you can also
retrieve a previous line by pressing the up key. If you followed the two
previous examples, pressing the up key once would place the mkdir command back
at the prompt and pressing it again the bring command. You can move forward by
using the down key.
Entering file names and directories can be done more quickly using the Tab key. If you enter a portion of the name and press Tab, the shell will attempt to complete the rest of the name for you. If it cannot (as it could match more than one name), pressing Tab again will show you a list of possibilities.
This shortcut is exceptionally useful for long directory structures or file names. The method works intelligently with newer versions of Bash, including the version supplied with Ubuntu. If you typed ‘rmdir’ followed by Tab, it would display directories only. If you typed nothing after the command, two Tab presses would display all the directories.
All Open Source and Linux Tags: Linux and Unix
