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

Most Popular Reviews

Latest Articles

Resources

PCW Evaluation Team

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.

Ratchada Dunn

Sharp PN-40TC1 Huddle Board

The Huddle Board’s built in program; Sharp Touch Viewing software allows us to easily manipulate and edit our documents (jpegs and PDFs) all at the same time on the dashboard.

George Khoury

Sharp PN-40TC1 Huddle Board

The biggest perks for me would be that it comes with easy to use and comprehensive programs that make the collaboration process a whole lot more intuitive and organic

David Coyle

Brother PocketJet PJ-773 A4 Portable Thermal Printer

I rate the printer as a 5 out of 5 stars as it has been able to fit seamlessly into my busy and mobile lifestyle.

Kurt Hegetschweiler

Brother PocketJet PJ-773 A4 Portable Thermal Printer

It’s perfect for mobile workers. Just take it out — it’s small enough to sit anywhere — turn it on, load a sheet of paper, and start printing.

Matthew Stivala

HP OfficeJet 250 Mobile Printer

The HP OfficeJet 250 Mobile Printer is a great device that fits perfectly into my fast paced and mobile lifestyle. My first impression of the printer itself was how incredibly compact and sleek the device was.

Featured Content

Latest Jobs

Don’t have an account? Sign up here

Don't have an account? Sign up now

Forgot password?