Using the shell in Linux

Last month in this column, I introduced some of the tools available for graphical file management, which can go a long way to easing the transition from another operating system. This month I will discuss the Linux command line, or shell, and demonstrate how it can be used just as effectively as any GUI application.

The most common shell used in Linux systems is Bash, or the Bourne Again Shell. The purpose of a shell is "to interface the user's applications with "the kernel (core of the Linux operating system). The Linux shell, being a functional system configuration and development environment, works independently of the X Window System.

CONSOLE OR TERMINAL? There are two ways in which a user can access the Linux shell: in console mode or through a terminal emulation program. Console mode is simply your monitor's blank screen, with a shell prompt that can be accessed by pressing -- while in the X Window System. Your X Windows System display will then switch temporarily to console mode (it will continue to run in the background) where you can log in and begin using the shell. -- will switch to another console, and so on, until you press -- to return to the X display.

Alternatively, you can use the shell while in X with the aid of a terminal, which will allow you to perform the same tasks as if you were logged in at the console. Common terminals, or terminal emulation programs, for Linux and UNIX systems are xterm and rxvt. The KDE and GNOME desktop environments have their own terminals called Konsole and GNOME Terminal, respectively.

SHELL COMMANDS For anyone familiar with a DOS command line, learning the Linux shell shouldn't be difficult. The first thing you will see when logged in at a shell is the prompt. Many Linux systems use the dollar sign ($) as the default prompt for a user and the hash (#) character for the root (administrator) account. Executing a command simply involves typing it at the prompt and pressing . Try this with the pwd, or print working directory, command:$ pwd/home/jsmithThe output "/home/jsmith" indicates that the user jsmith is currently working in their home directory. Changing to another directory is as simple as using the cd command:$ cd /homeThis will make your current directory /home. Executing cd on its own will return you to your home directory by default. One of the most-commonly used commands is ls, which lists the contents of a directory:$ ls
$If nothing comes up then you have not yet created anything in your home directory. You can get more information about files by running ls with a flag:$ ls -l /etcThis will give a long format description of all files in /etc. The output will be more than 100 lines long. To see it, you can hold down -, or a useful feature of the Linux shell called piping, by entering:$ ls -l /etc | lessHere, the | (or pipe) sends the output of the ls -l to the program called less. Less is a text viewer which allows you to navigate slowly through a file using the keyboard arrows. A similar way of adding text to a file is with a text editor:$ pico helloThis will open up an editor window where you can do all standard text editor procedures. There are also other text editors, such as vi and emacs. Once you've created a file, you might like to delete it with the rm (remove) command:$ rm helloThis removes the file hello. NOTE: unlike other operating systems, if you delete a file under Linux, it's gone permanently. You could have also copied the hello file to another file, with:$ cp hello hello2You might be wondering why the files do not have extensions on the end like .txt. This is simply a matter of choice. You can rename hello2 to hello2.txt with mv (move):$ mv hello2 hello2.txtTo help with organisation, you will want to be able to make directories in which to put files:$ mkdir testUsing ls, you can see test exists in your home directory. You can remove it with rm:$ rm -rf testNow you can make a directory in which to store your Linux information:$ mkdir tuxYou can copy all the files that you have made into it:$ cp hello hello2.txt tux/The commands demonstrated here are only a starting point for what is achievable with the Linux shell. With some practice, you will find that using the shell is very intuitive. It is also necessary for a fuller understanding of Linux.

Join the newsletter!

Error: Please check your email address.
Rocket to Success - Your 10 Tips for Smarter ERP System Selection
Keep up with the latest tech news, reviews and previews by subscribing to the Good Gear Guide newsletter.

Rodney Gedda

PC World
Show Comments

Brand Post

Most Popular Reviews

Latest Articles


PCW Evaluation Team

Andrew Teoh

Brother MFC-L9570CDW Multifunction Printer

Touch screen visibility and operation was great and easy to navigate. Each menu and sub-menu was in an understandable order and category

Louise Coady

Brother MFC-L9570CDW Multifunction Printer

The printer was convenient, produced clear and vibrant images and was very easy to use

Edwina Hargreaves

WD My Cloud Home

I would recommend this device for families and small businesses who want one safe place to store all their important digital content and a way to easily share it with friends, family, business partners, or customers.

Walid Mikhael

Brother QL-820NWB Professional Label Printer

It’s easy to set up, it’s compact and quiet when printing and to top if off, the print quality is excellent. This is hands down the best printer I’ve used for printing labels.

Ben Ramsden

Sharp PN-40TC1 Huddle Board

Brainstorming, innovation, problem solving, and negotiation have all become much more productive and valuable if people can easily collaborate in real time with minimal friction.

Sarah Ieroianni

Brother QL-820NWB Professional Label Printer

The print quality also does not disappoint, it’s clear, bold, doesn’t smudge and the text is perfectly sized.

Featured Content

Product Launch Showcase

Latest Jobs

Don’t have an account? Sign up here

Don't have an account? Sign up now

Forgot password?