Simple clear advice in plain English

Hands on: A word in your shell

The Linux command line is less frightening than you might think

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.

Reader Comments

   

Add your comment

All fields must be completed. Your email address will not be displayed or used to send marketing messages.

All messages will be checked by moderators before appearing on the site.

See our Privacy Policy for more information.

Related articles

Security shield illustration

How to use the Command Prompt

Lurking under Windows is the little-known world of the command line. We explain how to use this to fix faults and make your PC much more secure

Make email newsletters with Word illustration

Use Word 2003 or 2007 to create attractive email newsletters

Word can help you make an email newsletter containing photos and clickable links. We show you how to make the most of Microsoft's templates

Manage files and folders with FarManager illustration

Bypass Windows and speed up the management of files and folders

Handle files and folders faster than ever by reverting to the time before Windows. For the confident, Far Manager works like the file-management tools of yesteryear

Question & Answer

Q.How do I store musician and other information about...

> Read the answer

Q.Why can't my browser find the website address I typed...

> Read the answer

Q.All updates have been downloaded, so why won't Windows...

> Read the answer

Best deals on the web

img

THREE E585 Mi-Fi Take it Away Mobile Broadband - 5GB allowance

£44.97- Buy it now

img

T-MOBILE 3G Pay As You Go iPad Micro SIM

£0.10- Buy it now

img

THREE Huawei E353u Take It Away Mobile Broadband - One Month Rolling Contract

£4.99- Buy it now

Great benefits for subscribers!

Poll

Which is your preferred web browser

Jargon Buster

Computing terms explained in plain English

Bios

Basic Input Output System. Essential software built into every PC that connects the vital components....

Great shopping deals from Computeractive