Basic Linux
Basic Linux
LinuxUsageBasics
IntroductoryTerms
When you learn about a new operating system, you should also
learn new terminology. This section defines a few basic terms you
should learn.
Man page and Info page: Man (short for manual) and Info pages
give detailed information about a command or _le (man pages tend
to be brief and provide less explanation than Info pages). For
example, to read the man page for the su command, type man su at
a shell prompt (or type info su for the info page). To close man or
Info pages, press [q].
Panel: A desktop toolbar, located across the top and bottom of your
desktop. The panel contains the Applications menu and shortcut
icons to start commonly used programs.
RPM: RPM stands for RPM Package Manager and is how Red Hat
builds and delivers its software files. An RPM is a software package
file you can install on your Red Hat Enterprise Linux computer.
Shell prompt: A command line interface between the user and the
operating system (Figure 1-13). The shell interprets commands
entered by the user and passes them on to the operating system.
LoggingIn
The next step to using your Red Hat Enterprise Linux system is to
log in. When you log in, you are introducing yourself to the system
(also called authentication). If you type the wrong user name or
Password, you will not be allowed access to your system.
Unlike some other operating systems, your Red Hat Enterprise Linux
system uses accounts to manage privileges, maintain security, and
more. Not all accounts are created equal: some accounts have fewer
rights to access files or services than others.
GraphicalLogin
When your system has booted, a graphical login screen is displayed.
Again, unless you have chosen to give your machine its own
hostname, which is primarily used in a network setting, your
machine will probably be called localhost.
To log in as root from the graphical login screen, type root at the
login prompt, press [Enter], type the root password that you chose
during installation at the password prompt, and press [Enter]. To log
in as a normal user, type your username at the login prompt, press
[Enter], type your password that you selected when creating the
user at the password prompt, and press [Enter].
GraphicalInterface
When you installed Red Hat Enterprise Linux you had the
opportunity to install a graphical environment. Once you start the X
Window System, you will find a graphical interface known as a
desktop. Unless you specified otherwise, Red Hat Enterprise Linux
installs GNOME as the default desktop.
LoggingOut
Graphical Logout
If you are not using the X Window System and you logged in at the
console, type exit or [Ctrl]-[D] to log out of the console session.
Never turn your computer off without shutting down first, as you
may lose unsaved data or damage your system.
halt
System halted.
Manual Pages
Using man
For example, to access the man page for the ls command, type the
following:
man ls
Just like other commands, man has its own man page. Type man
man at the shell prompt for more information.
Usingthe GraphicalDesktop
Red Hat Enterprise Linux includes a powerful graphical desktop
environment where you can easily access your applications, files,
and system resources.
UsingNautilus
Your first view of the graphical desktop looks something like
Microsoft windows . The desktop offers the following tools,
represented as desktop icons: Computer, User's Home, and
Trash. Each of these tools is an application of the Nautilus file
manager.
Usingthe Computericon
Double-clicking the Computer icon takes you to a list of all of the
devices on your system. A device is anything connected to your
computer to which data is sent or from which it is received. (You
have probably heard of a 'device driver' before (this is a piece of
software that allows a device to talk to your computer.) Most
modern systems have the following devices: a floppy drive, a CD-
ROM drive, and at least one hard drive. Other devices may be listed
depending on the makeup of your system.
Removable Media
Double-click either the Floppy icon or the CD-ROM icon to mount
the drive with Nautilus and open a new window with the drive's
contents. You can also right-click on the drive and then
select Mount Volume from the menu.
Disk
This references the hard drive. If you are using Linux, your hard
drive is already mounted, and may not be accessible from this
window. If you have other hard drives available on your system
(possibly used for other operating systems), they may be mountable
here.
File system
Double-click on the File system icon and Nautilus opens a window
that shows the entire file system, starting from the / directory. This
is a quick way to reach such useful folders as /tmp/ and /usr/bin/. If
you are not logged in as root, some folders will be unavailable. This
is to prevent accidental damage to your system.
Network
Double-click the Network icon to bring up a list of all systems on
your network. Linux systems are listed individually. Systems running
other operating systems are grouped under an icon
that reflects this. (For example, Windows systems on your network
appear under a Windows Network icon.) You are only able to
browse those machines you have permission to access.
On the top panel are two menus, the Applications menu and the
Actions menu. The Applications menu expands into a large set of
menus that allow you to access the applications on your system.
The Actions menu expands into a list of actions you can perform on
your session.
The ApplicationsMenu
The categories of the Applications menu are self-explanatory. For
example, the Games sub-menu holds games like Same GNOME;
the Sound and Video sub-menu holds CD players, volume
controls, and the Helix media player. For these directories, a few
moments spent browsing the contents is sufficient to familiarize
yourself with your system. A few sub-menus are worth additional
explanation:
Preferences
Preferences contains applications that allow you to customize your
system. Most of the applications in this sub-menu do not require
root privileges to access.
SystemSettings
System Settings contains higher-level configuration tools. Most of
the applications in this submenu require root privileges to access.
You should use caution when using these applications.
Date & Time: This tool allows you to set the date, time, and
timezone for your system.
Printing: The Printer Configuration Tool allows you to add
a new printer to your system, whether it is connected to your
computer or is available on a network.
System Tools
The ActionsMenu
The Actions menu contains tasks you will most likely execute on a
daily basis. These include: Lock screen, Log Out, and Search for
Files....
Log Out
This action opens the Log Out dialog window, which
terminates your GNOME session.
Usingthe Desktop
o Click OK.
AddingFile Links
To place a link to a file or directory on the desktop:
3. Drag and drop this new icon to the desktop. If you were to
drag and drop the actual file or directory, you would move
it from its current location to the desktop.
Usingthe Panel
The long gray bars across the top and bottom of the screen are the
Panels.
The top Panel contains both the Applications and Actions menus.
It also contains application launchers, the notification area, and the
time and date.
Configuringthe Panel
You can hide the panel automatically or manually, place it on any
edge of your desktop, change its size and color, and change the way
it behaves. To alter the default panel settings, right-click in an
unused area of the panel and select Properties. If you choose to
hide the panel, it does not appear on the desktop until you move
your mouse pointer over the panel area
Customizingyour GNOMEsession
There are several ways to display your images. The Tiled option
displays multiple instances of your image across the desktop, which
is useful if you use a small image or if you use a tile (or pattern)
image from /usr/share/backgrounds/tiles/ (or from your own image
collection). The Centered option places your image in the center of
the desktop, leaving the default background colors to fill in any
remaining desktop space. To fill the desktop with an image without
tiling it, use the Scaled or Stretched options.
2. Press [Ctrl]-[Alt]-[1].
Sound
The Sound preference tool allows you to set sounds to accompany
events. For example, your system can play a certain sound every
time you login. When you first open this tool, you should see a
series of tabs across the top of the window. Under the General tab,
check that the Enable sound server startup box is checked.
Click on the Sound Events tab, to display a list of actions that can
be accompanied by a sound. To change or add a sound to an event,
click on the description of the event, then click on the Browse... button.
Choose a sound located in the file system, and then click Open. Sound
files installed with Red Hat Enterprise Linux are located in
/usr/share/sounds/. You may also choose a sound file from your
home directory. Any file with a .wav extension can be used for an
event sound. To listen to a sound that has been selected, click the
Play button.
Screensaver
Double-click the Screensaver icon to launch the Screensaver
Preferences tool. The list on the left displays the available
screensavers. Nearly all screensavers can be customized by clicking
on the Settings... button. To see if this is the screensaver you would like
to use, click on the Previewbutton. When you have seen enough, click
the mouse anywhere on the screen and you will return to
Screensaver Preferences. When you are finished, close the
window to save your changes and exit.
RemovableStorage
Launch the Removable Storage tool from the Applications =>
Preferences sub-menu. The application opens a list of options for
the way your system handles removable storage media such as
floppy diskettes and CD-ROMs. One default option is auto-mounting.
Auto-mount means that the data on your removable media is
automatically available a few moments after you insert it; manual
mounting is not necessary
Path
root directory
The root directory is the top-most directory of the _le system. All
other _les and directories exist in this directory or one of its sub-
directories. Do not confuse the root directory, /, with root's
home directory, /root/.
Managing Files
If you are new to Linux, file names may look strange to you. Linux
file names may include extensions you haven't seen before, may
have multiple extensions, or may not have any at all. File names
may begin with a "." or may have other symbols in their names,
including spaces.
File Types
.tar a file archived with tar (short for tape archive), also known as
a tar file
File Formats
.jpg a JPEG image file (short for Joint Photographic Experts Group)
SystemFiles
UsingFile Roller
Red Hat Enterprise Linux includes a graphical utility called File
Roller. File Roller can compress, decompress, and archive files in
common Unix and Linux formats. It has a simple interface and
extensive help documentation. To start File Roller, select Archive
Manager from the Applications (the main menu on the panel) =>
System Tools sub-menu. File Roller is also integrated into the
desktop environment and Nautilus.
bzip2 filename
The file is compressed and saved as filename.bz2.
bunzip2 filename.bz2
You can use bzip2 to compress multiple files and directories at the
same time by listing them with a space between each one:
The above command compresses file1, file2, file3, and the contents
of the /usr/work/school/ directory (assuming this directory exists)
and places them in a file named filename.bz2.
gzip filename
gunzip filename.gz
You can use gzip to compress multiple files and directories at the
same time by listing them with a space between each one:
The above command compresses file1, file2, file3, and the contents
of the /usr/work/school/ directory (assuming this directory exists)
and places them in a file named filename.gz.
unzip filename.zip
You can use zip to compress multiple files and directories at the
same time by listing them with a space between each one:
The above command compresses file1, file2, file3, and the contents
of the /usr/work/school/ directory (assuming this directory exists)
and places them in a file named filename.zip.
-f when used with the -c option, use the filename specified for the
creation of the tar file; when used with the -x option, unarchive the
specified file
You can tar multiple files and directories at the same time by listing
them with a space between each one:
The above command places all the files in the work and the school
subdirectories of /home/mine in a new file called filename.tar in the
current directory.
This command does not remove the tar file, but it places copies of
its unarchived contents in the current working directory, preserving
any directory structure that the archive file used.
Managing Directories
In manyways, directoriesare treatedlike files. Theycan be created,deleted, movedand
copiedfromNautilusor froma shell prompt, usingcommandssimilar to thosefor files.
CreatingDirectories
Shell PromptBasics
Why Use a Shell Prompt
Graphical environments for Linux have come a long way in the past
few years. You can be perfectly productive in the X Window System
and only have to open a shell prompt to complete a few tasks.
However, many Red Hat Enterprise Linux functions can be
completed faster from the shell prompt than from a graphical user
interface (GUI). In less time than it takes to open a _le manager,
locate a directory, and then create, delete, or modify _les from a
GUI, a task can be finished with just a few commands at a shell
prompt.
Shell PromptTerms
Below are a few terms to know before beginning the discussion of
the shell prompt.
command line
shell prompt
The shell prompt is the marker on the screen that shows where the
command line should be placed. The following is an example of a
shell prompt:
[[email protected] username]$
Shell
terminal window
The terminal window is the window that contains the shell prompt,
command line, and output from the shell.
The shell prompt within a terminal window looks something like this:
[[email protected] username]$
There are any number of symbols that can be used to indicate the
end of the shell prompt, and you can customize what your prompt
looks like. However, there are two symbols that you will see more
often than any others, "$" and "#". The first symbol, "$", is the last
character in the prompt when you are logged in as a normal user.
The shell prompt for a normal user looks something like this:
[[email protected] username]$
The second symbol, "#", is the last character in the prompt when
you are logged in as root. This is true whether you logged in as root
from the initial screen or if you executed the su - command to
become root. The shell prompt for root looks something like this:
[[email protected] root]#
This slight difference can help remind you what privileges you
currently have.
Structure of shell prompt commands
In general, a command run from the shell prompt will have the
following format:
ls -la
1) Enter the command alone at a shell prompt and press [Enter]. For
example, entering cp alone returns a brief description of the
command and its usage. Other commands, such as cat, require no
arguments or _les to run as normal. To quit such a command, press
[Ctrl]-[D]. If that does not work, press [Ctrl]-[C].
Navigate through the man page using the directional keys on your
keyboard. The [Space] bar moves you down a page, [B] moves you
up a page. To quit, press [Q]. If the man page for a command is
either unavailable or does not provide enough information, the info
system may provide additional information.
The shell assumes that the first word entered at the prompt is a
command. The possible completions it offers are the names of
commands or applications. This can be helpful if you are not sure of
the exact spelling of a command or if you are searching for a certain
command. It can also serve to help a new user become familiar with
the available commands.
For example:
2. The shell asks if you want to see all 379 possibilities. This means
that there are 379 commands that start with the letter "g".
Searching through this list would take too much time.
Command History
Commands that you only typed partially and did not follow with
[Enter] are not saved into your command history file. To clear your
command history,
type history -c.
By default, Red Hat Enterprise Linux stores 1000 commands. Each
terminal window or shell prompt stores a separate set of commands.
If you gain root privileges by using the command su -, the history
file (and thus the commands) you access are root's, not the user's.
Wildcards
Wildcards are place holders used to allow users to search for or use
multiple files with similar names.
Useful Keystrokes
The terminal window begins to look crowded very quickly. You can
always exit from the terminal window and open a new one, but
there is a quicker and easier way to remove the contents displayed
in the terminal.
To clear the terminal, enter the command clear at the shell prompt.
The clear command clears the terminal, leaving only a new shell
prompt at the top of the window.
You can also clear the screen using the keystroke [Ctrl]-[L].
Determining Your Current Directory with pwd
/home/user
Enter the command ls -a. Now you an view the hidden "dot" files.
Viewing all the files using the ls -a command can give you plenty of
detail, but you can view still more information by using multiple
options.
To see the size of a file or directory, when it was created, and so on,
add the long option (-l) to the ls -a command. This command shows
the file creation date, its size, ownership, permissions, and more.
ls -al /etc
The following is a brief list of options commonly used with ls.
Remember, you can view the full list by reading the ls man page
(man ls).
Copyingfiles with cp
To create a copy of an existing file, use the cp command.
While cp does have options, they are not used as often as those of
other commands. To view these options, read the man page by
entering man cp at a shell prompt.
To copy files within the current directory specify the new name then
command line is.
cp original_file new_file
This command creates a new file, named new_file, with the same
content as the original file.
cp original_file /dir1/dir2/
cp original_file /dir1/dir2/new_file
cp /dir1/dir2/filename
Movingfiles with mv
To move a file or directory from one location to another, use the
command mv.
mv filename /dir1/
This command would remove filename from the current working
directory and place it in /dir1/.
mv /tmp/filename
The above command moves the file filename from the /tmp/
directory into your current working directory.
Renamingfiles with mv
To rename a file or directory, use the mv command.
To rename a file with mv, the third word on the command line must
end in the new filename.
mv original_name new_name
Deletefiles with rm
To delete a file using rm enter the following at a shell prompt
rm filename
The second word can also be a path, but must end in a file.
rm ../../filename
There are many options to rm. To view them all, enter man rm at
the shell prompt.
The rmdir command will only delete directories that are empty. If
you are concerned about accidentally deleting a directory that is not
empty, use this command.
rmdir directory/
If you want to delete a directory and all of its contents, use the
command rm -rf. Note that if you enter rm -rf, the shell will not ask if
you are sure before permanently deleting the directory.
rm -rf /dir1/
The above command deletes /dir1/ and every file and sub-directory
that exists inside.
LeavingyourCurrentWorkingDirectory
To change directories from your current working directory, use the
command cd.
cd /tmp/
The cd has many useful options. You can see all of these
options by entering man cd at the shell prompt. The most
commonly used options are listed below.
The headCommand
The head command displays the beginning of a file. The format
of the head command is:
head <filename>
By default, you can only read the first ten lines of a file. You can
change the number of lines displayed by specifying a number
option.
tail -f /var/log/messages
The moreCommand
The more command is a "pager" utility used to view text in the
terminal window one page or screen at a time. The [Space] bar
moves forward one page and [Q] quits.
ViewingFileswith less
The format of the less command is:
less <filename>
The main difference between more and less is that less allows
backward and single-line movement using the same navigation
as man pages: press the [Space] bar to go down one page, the
[B] to go back one page, the directional (or "arrow") keys to
move one line at a time, and [Q] to quit.
To search the output of a text file using less, press [/] and enter
the keyword to search for within the file.
/stuff
The above command would search through the file for all
instances of "stuff" and highlight them in the text.
Using cat alone echoes on the screen any text you enter. It will
continue to do so until you exit with the [Ctrl]-[D] keystroke.
Entering the cat command followed by a file name displays the
entire contents of the file on the screen. If the file is long, the
contents scroll off the screen.
The grepCommand
The grep command is useful for finding specific character strings
in a file. For example, to find every reference made to "pattern"
in the file <filename>, enter:
Each line in the file that includes the pattern "pattern" is located
and displayed on the screen/
Pipesand Pagers
we saw that using cat to view a large file causes the contents to
scroll off the screen. Using a pipe, we can control that behavior.
A pipe is the ( | ) symbol. It is used to connect the standard
output of one command to the standard input of another
command. Essentially, it allows a user to string commands
together. Pagers are commands (such as less) that display text
in the terminal window.
Using cat, the pipe (|), and less together displays the file one
page at a time. You can then use the up and down arrow keys to
move backward and forward through the pages
cat <filename> | less
The above command opens the file named <filename> using the
cat command, but does not allow it to scroll off the screen.
Using the pipe with a pager is also useful when examining large
directories with ls. For example, view the /etc/ directory with the
ls command.
ls -al /etc/
Notice that the contents scroll past too quickly to view. To get a
closer look at the output of the ls command, pipe it through less.
Now you can view the contents of /etc/ one screen at a time.
Remember that you can navigate forward and backward through
the screens and even search for specific text using the [/] key.
The above displays all files and directories in /etc/ that start with
the letter "a" one screen at a time.
UsingRedirection
Redirection means changing where standard input comes from
or where the standard output goes.
To redirect standard output, use the > symbol. Placing > after
the cat command (or after any utility that writes to standard
output) redirects its output to the file name following the symbol.
Remember that the cat command echoes the text you enter on
the screen. Those echoes are the standard output of the
command. To redirect this output to a file, type the following at a
shell prompt and press Enter: cat > foo.txt. Enter a few more
lines of text, and use the [Ctrl]-[D] key combination to quit cat.
The
To
RedirectingStandardInput
You can also performthe sametype of redirectionwith standardinput.
Whenyou use the redirect standardinput symbol<, you are telling the shell that you
want a file to be read as input for a command.
contentsof a
file
Changes cd cd cd /directory/directory
directories pathname pathnam
with a e
specified
path
(absolute
path)
Changes cd.. cd .. cd ..
directories
with a
relativepath
Notes:
a. Gedit is a graphical text editor; other editors you can use in
place of Gedit include nano and vi.
b. The more pager can also be used to page through a file one
screen at a time.
c. The mv command can both move a file and, if you want to
rename a file in the same directory, "move" that file to the
same directory with a new name.
SystemDirectories
This is a list of the primary Red Hat Enterprise Linux system
directories. Each directory is described briefly.
FILESYSTEMLAYOUT
KeyboardShortcuts
Here are a few keyboard shortcuts you can use to perform common
tasks quickly
• [Ctrl] + [d] = logout of (and close) shell prompt. Use this quick
shortcut instead of typing exit or logout.
• [Ctrl] + [l] = clears the terminal. This shortcut does the same
thing as typing clear at a command line.
LocatingFilesandDirectories
Find
Locate
locate pattern
which
which command
whereis
whereis command
whatis
The format of the whatis is:
whatis command
Compatibilitywith otherformats
OpenOffice.org is compatible with most common document
formats, including:
• StarWriter
• MS Works
• WordPerfect
OpenOffice.org Writer
A word processor is like a text editor but has several additional
features that allow you to format, design, and print your
documents without the need to memorize complex formatting
tags or codes. OpenOffice.org Writer is a powerful word
processor that features WYSIWYG formatting - what you see in
the OpenOffice.org Writer window is what you get if you print
or share the document.
Overviewof OpenOffice.orgWriter
Writing documents using OpenOffice.org is similar to other
word processing applications you may have used before. To start
OpenOffice.org Writer, you can either start it from the
Applications by selecting Applications => Office =>
OpenOffice.org Writer, or start it from a shell prompt by
entering oowriter.
To save a file:
5. Select the format for your file from the File type drop
down menu.
To print a document:
4. You may print from this screen the same way as from
the main screen.
To format a page:
To undo changes:
OpenOffice.org Calc
To save a spreadsheet:
5. Select the format for your file from the File type drop
down menu.
To print a spreadsheet:
1. Click on the printer icon or go to File => Print or press
[Ctrl]-[P].
2. Enter the function: start with an "=" sign and enter the
name of the function.
4. Select the function you would like to use from the pane
on the left. You select by double-clicking on the name
of the function.
To create a chart:
vi
vi is a shell prompt text editor. This means that like less,
opening an instance of vi does not open a GUI window.
Instead, the contents of the file being edited appear in the
current terminal window. Because vi works without a GUI, it
can be used to edit text files even when X is not working.
Key Action
[i] With a file open, press[i] to enter Insert mode.This modeallowsyou to movethe
cursor and to deleteand add text anywherein the file.
[Esc] Pressingthe [Esc] key at any time takesyou out of Insert modeand into Normal
mode.
[w] [w] writes your changesto the file. Enter Normalmode,press[Shift]-[:], [w], and
finally press[Enter].
[q] [q] quits vi. Enter Normalmode,press[Shift]-[:], [q], and finally press[Enter]. To
saveyour changesbeforeexiting, enter :wq. To quit without savingyour changes,
enter :q!.