image: shell konsole
Using pipes and redirections in a shell in KDE's Konsole application
R E L A T E D   C O N T E N T
ADVERTISEMENT

Hands on: A word in your shell

The Linux command line is less frightening than you might think

Barry Shilliday, Personal Computer World 21 Sep 2007
ADVERTISEMENT

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

Like this story? Spread the news by clicking below:

Post this to Delicious del.icio.us    Post this to Digg Digg this    Post this to reddit reddit!

Permalink for this story
R E A D E R   C O M M E N T S
M A R K E T P L A C E
Get your free demo of Numara Track-It! 8 - the leading help desk solution for IT related issues.
Make presentations, review documents & share your entire desktop. 30-day free trial! (cc required).
Discover how remote support can fuel your IT business in ways you've never thought of before.
Apply ITIL best practices at your service desk while eliminating integration cost. Learn more here.
WAN based, automated, daily vulnerability assessments. Click here to try and request our whitepapers.
Have your product or service listed here >   
Sponsored links
F E A T U R E D   J O B S
Aylesbury, Buckinghamshire, United Kingdom | Grass Roots
Business Analyst - £35,000 - £50,000 + benefits - Aylesbury    Grass Roots are one of the Sunday Times Top 100 companies to work for (2007 and 2008). Established in 1980, we're part of the ... more >
London, United Kingdom | The Crown Estate
 EDM Administrator - London - £22,300 to £24,200pa The Crown Estate is a unique organisation that manages a vast and varied property portfolio, comprising commercial, agricultural and marine interests throughout Britain. We are looking for an ... more >
London, United Kingdom | City of London
ICT Project Officer - Guildhall, London EC2 18-month fixed-term contract Bring your project management expertise to one of the country's most prestigious institutions. The City of London is the local authority for the Square Mile, ... more >
Central London, United Kingdom | MI5 Security Service
Communications Centre Engineer - Competitive salaries + excellent benefits - Central London Getting the best out of technology is critical to helping us protect the UK. Join MI5 and use your skills and experience to ... more >
More job opportunities