Any administrative task can be done from the console in Linux. In many cases, using the console is faster than using a graphical program and may provide additional functionality. Furthermore, any console task can be placed into a script, and thus automated. To really take control of your Linux environment, you will want to learn how to do things from the console. The information here is a guide to get you started at the Linux console if you have a DOS/Windows background.
If your system boots into text mode (a common configuration for servers to conserve overhead for services), then you are already at a console when you execute a text login. On a typical Linux system, you can get to additional consoles by pressing Ctrl + Alt + (F1 - F6). Each console is a completely different session on the system and can be accessed as different users at the same time.
This multi-console behavior is different from the multiple-desktop in Windows. In Linux, each console can be controlled by a completely different user. For example, you can be logged as root on console 1, and logged in as joeuser on console 2. Both consoles run different programs in their own user space. In the same vein, different users can be logged into a Windows system remotely. In this instance, Linux provides capabilities more like a mainframe than a simple server or workstation.
If you are in a graphical mode, then you can open a terminal to get access to a console screen. The terminal will usually have a button on your desktop's task bar, or you can find it under System Tools in the Program menu. You can also open a terminal from the context menu (right click on the desktop).
There are many potential commands available from the console. Some of these tools are only truly useful when writing scripts. Here are some of the first ones that you'll probably need. Remember that all commands and options are case sensitive. -R is different from -r, and will probably do different things. Console commands are almost always lowercase.
Moving around in directories uses the familiar
cd command. The main trick is to remember that in
Linux the forward-slash (/) is used where you are accustomed to using the
back-slash (\). The back-slash is still used, but it specifies that a command
should be continued on the next line. This is sometimes done for
readability when typing in a particularly long command.
Listing files in a directory can be done with the
ls command. There are several switches you can use to
alter the look of the listing:
|Shows a long listing, including files size, date and time, and attributes|
|Sorts files by time|
|Sorts files by size|
|Combined with one of the sorting switches, reverses the
|Human readable. Uses friendly k, M, and G indicators to show file size rather than listing them in bytes.|
|Shows all the files in a directory, even the hidden ones|
Copy files with the
cp command. The command
works essentially the same as the DOS
command. Essential switches:
|Copies files recursively; required if you are copying an entire directory|
|Forces the copy and overwrites existing files without asking|
|Links files instead of copying; see below|
Move files and rename files with the
mv command. It works
essentially the same as the DOS
except that it will move entire directory structures as well as files.
View files with the
cat command. This is the
equivalent of the DOS
type command. It will
dump the contents of a file to another file, to the screen, or to another
cat is short for concatenate, and can
be used to sequence several files together into a larger file.
View information one page at a time with the
more command. It works essentially the same as the
less to view a text file with the ability
to scroll up and down through the document and search for text patterns.
Some might say that
vi stands for "virtually
impossible." It is a text editor that has a long tradition in the Unix
vi is not really intuitive, but it is available in almost any
Unix-like environment. There is a built-in tutorial for the version
installed in Linux, and once you get used to it, you can do some truly
incredible things in a few keystrokes. Truly, no editor has managed to replace
for editing password and configuration files.
View documentation for a command with the
command. Man is short for manual. Documentation tends to be thorough. To
learn more about
info is like
man except it provides
hyperlinked text to make browsing documentation easier.
One critical difference between DOS/Windows and Linux is that the command shell is a layer separated from the operating system. The shell environment affects the features you have, such as editable command lines and scrolling histories. The shell also determines the syntax required to do functions in scripts. In DOS/Windows, there was only one option for scripting, the lowly .BAT file. It did a lot, but required a good deal of creativity on the part of the script writer to do more than basic tasks. In Linux, scripts can contain loops and do more than basic conditional statements, including many things that you expect from a programming language. If you were good at writing .BAT files, shell scripts are going to let you shine.
The default shell is a parameter in each user account. The typical
default shell in Linux is /bin/bash, though others are available. The
man documentation for each shell is actually
very good and goes into detail about shells and how they work. Rather
than try to paraphrase that information here, select a shell from the list
below and look at its man page.
The bash shell is a free version of the Bourne shell, the first Unix shell, and includes many additional features. Bash has editable command lines, a scrollable command history, and tab completion to help avoid typing long file names.
The C shell uses a "C-like" syntax and has borrowed many features from the Bourne shell, but uses a different set of internal shell commands.
The Korn shell uses the same syntax as the Bourne shell and has included the user-friendly features of the C shell.
is used in many installation scripts and should probably be installed on
the system even if it's not your primary shell.
The TC shell is an enhanced version of the C shell and is 100% compatible with it.
The Z shell is an enhanced version of the Korn shell with many features found in the bash shell.
One compelling feature in the Linux file system is the file link. A link is a reference to a file, so that you can let files be seen in multiple locations of the file system. However, in Linux, a link can be treated as the original file. A link can be executed, edited, and accessed without having to do anything unusual. As far as other applications on the system are concerned, a link is the original file. When you make edits to a file through the link, you are editing the original. A link is not a copy. There are two kinds of links: a hard link and a symbolic link.
A hard link can only reference files in the same file system. It provides a reference to the file's physical index (also called an inode) in the file's system. Hard links do not break when you move the original file around because they all point to the file's physical data rather than its location in the file structure. A hard-linked file does not require the user to have access rights to the original file and does not show the location of the original, so it has some security advantages. If you delete a file that has been hard linked, the file remains until all references have been deleted as well.
A symbolic link is a pointer to a file's location in the file system. Symbolic links can span file systems and can even point to files in a remote file system. A symbolic link shows the location of the original file and requires a user to have access rights to the original file's location in order to use the link. If the original file is deleted, all of the symbolic links become broken. They will point to a non-existent location in the file system.
Both types of links can be made with the command
<source> <target>. By default
ln will make a hard link. The
-s switch will make a symbolic link.
# Create a hard link from MyFile in the current
# directory to /YourDir/MyFile
ln MyFile /YourDir
# Create a symbolic (soft) link from MyFile in
# the current directory to /YourDir/YourFile
ln -s MyFile /YourDir/Yourfile
In the above examples, MyFile, /YourDir/MyFile, and /YourDir/Yourfile are all treated as the same file.
Learning to work from the console is a necessary skill for Linux
administration. There are tools to avoid the console, but you will always
be more limited by what you can do through a tool. Accessing a console is
easy, and accessing command documentation is easy too with the
- Check out the other parts in the Windows-to-Linux roadmap series (developerWorks, November 2003).
- Get started with the vi editor by following the tutorial "vi intro -- the cheat sheet method" (developerWorks, ).
- "Technical FAQ for Linux users" (developerWorks, July 2001) offers another perspective on making the change
from Windows to Linux.
good is a Linux client?" chronicles one man's experience in changing
his work environment over from Windows to Linux. The companion article, a
glossary for Windows users" is also useful as a stand-alone reference.
- You can browse many man pages online at the
GNU Manuals Online page.
- The From
DOS/Windows to Linux HOWTO outlines some good quick-start information
for people with a DOS or Windows background.
- AllCommands.com is an unusual
site which helps to reference and cross-reference commands from various operating systems.
- The tutorial "LPI certification 101 exam prep, Part 1: Linux fundamentals" covers bash, standard Linux commands, and more.
- Learn more about shell scripting in the article series "Bash by
example" (developerWorks, ).
- Although written for AIX users, the System
User's Guide: Operating System and Devices - Shells reference and
book sections including AIX
Commands Reference - man Command cover a great deal of information
that also applies to Linux.
- For getting started with IBM software on Linux, there's no better resource than the Speed-start your Linux app page. You'll find installation tips and links to resources for DB2, Lotus Domino, WebSphere Application Server, WebSphere Studio, and more. You can also sign up to receive a Linux Software Evaluation Kit, containing trial software and training resources.
- Find more resources for Linux developers in the developerWorks Linux zone.
Chris Walden is an e-business Architect for IBM Developer Relations Technical Consulting in Austin, Texas, providing education, enablement, and consulting to IBM Business Partners. He is the official Linux fanatic on his hallway and does his best to spread the good news to all who will hear it. In addition to his architect duties, he manages the area's all-Linux infrastructure servers, which include file, print, and other application services in a mixed-platform user environment. Chris has ten years of experience in the computer industry ranging from field support to Web application development and consulting.