Learning Red Hat Linux in 24 Minutes

By: -=LRK=-  
Web Site: www.subdiv.net
Date: Pre-2005


Introduction - I needed to build an Email Server at work and (surprise surprise) all the documentation I could find on the subject royally sucks. I went to the book store and bought a book called "Learning Red Hat Linux in 24 Hours". After reading through it, I realized that even though it went very slow and very clear, it seemed to go a little too slow, and a little too clear. All I wanted was the nuts and bolts. I compiled what I learned, and wrote this article"Learning Red Hat Linux in 24 Minutes". While the rest is an excellent read, this is all I really needed to get started.

Disclaimer - This article contains direct quotes from the book, in the order that they appeared. This article (Like my Windows XP article) is for my own personal reference. An online notebook if you will. Since I own the book, I can post my notes. If you are not me, legally you may not read this. However, if this topic interests you, I highly recommend the book.

Installation
Installing Linux is either easy, or hard. If it was easy, please keep on reading. If you had a glitch during installation, I am the last person to help you. Glitches, I have found, are caused mainly by new hardware that the installer does not understand. For example, Red Hat 9 does not like my new Asus nVidia2 board, nor does it like my GeForce 4 card. However, my old 533 Celeron on a Abit board with a 3dFX Voodoo 3 video card worked like a charm. If you are skilled pro, issues like this are easily worked around. However, you are reading this article, and that makes it a major ordeal. I am going to skip a whole Red Hat or Lindows installation section on here, because it really is that easy. Lindows asked me only for a password for God's sake. If only Windows did the same thing.

The Console
The console, in a nutshell, sucks. If you are not willing to read through these commands, and understand the basics, forget about Linux completely. Even with the graphical interface, you need to learn this stuff. No two ways about it.

Switching Between Consoles
By default, when you install and boot Red Hat Linux, seven virtual consoles are configured and active. Normally, however, you see only the seventh-it is the one on which the X Window System (which represents your Linux desktop) is running. Consoles one through six are not running graphical applications, but are instead configured to allow you to log in and perform command-line work at them.

To display a specific console in Linux, hold down the left Ctrl and Alt keys simultaneously with one hand, and with your other hand, press Fl through F7, depending on the console you'd like to view. Fl will display console one; F2, console two; and so forth. At the moment, the first six consoles should all be identical. Holding down Ctrl and Alt and pressing F7 displays console seven, your desktop.

Logging In at a Virtual Console
To log in, enter your username and press Enter. For this hour, you should enter the name of the user account you created when you installed Red Hat Linux, rather than root; When the Password: prompt appears, type your password and press Enter.

Workstation20 login: you
Password:
[you@workstation20 you]$

The Shell's Role: Command Interpreter
The most common shell by far is the default shell, bash, which stands
playfully for the Bourne-Again SHell, so named because it is a re-creation (with new
features) of the old Bourne Shell, sh, from Unix.

Working with the Filesystem
Windows allows filesystem components to contain other filesystem components and file
folders to contain other file folders. This capability creates a structure that commonly is
referred to as a tree. At the base of the tree-in this case the C: drive itself - you can imagine a kind of root.

One Tree, One Root: The Linux File System
Linux and Unix filesystems, on the other hand, don't function like the one in Windows.
Any Linux computer has only one filesystem. The most basic location within the filesystem
is not a drive letter like C: or D:, but is rather the root of the filesystem, referenced
with a forward slash (/).


This is a Windows Tree, where each drive is it's own piece of the whole.

This is a Unix tree, where there is a Root Directory (Think of it as your C: drive out in the open) and all your other drives and partitions and CD-Roms and Floppies and everything are listed right there inside your main C: drive. In case you were wondering, yes, it's very confusing, and I don't much care for it. Especially when trying to figure out how much drive space is available.

The ls command is used to display the contents of a directory in Linux filesystem. Enter the ls command now, supplying the slash (for the root directory) as an argument:

[you@workstation20 you]$ ls /
bin dev home lib misc opt root tmp var
boot etc initrd lost+found mnt proc sbin usr


The output of the is command is color-coded Directories appear in blue.

The ls command begins with a forward slash (/) and then contains one or several words separated by additional slashes.

[you@workstation20 you]$ ls /usr/X11R6
bin include LessTif lib libexec man share


You can create an empty text file in Linux using the touch command and giving the filename you want as an argument.

[you@workstation20 you]$ touch empty.txt

To ask the shell just what your current working directory is, use the pwd (print working directory) command:

[you@workstation20 you]$ pwd
/home/you

To create a directory, use the mkdir command:

[you@workstation20 you]$ mkdir emptyfiles

Files can be moved using the my command:

[you@workstation20 you]$ my empty.txt emptyfiles

The command to remove files is rm; the command to remove directories is rmdir.
The rm command does this when you supply the - r (recursive) and - f (force) options, commonly shortened to - rf.

[you@workstation20 you]$ rm -rf somedirectory

The df command will list available space on all your disk drives. Use -h to round the numbers:

[you@workstation20 you]$ df -h

The /bin directory contains executable files.

[you@workstation20 you]$ ls /bin

Files listed in green are executable files and the cyan files are called symbolic links, notice /bin, contains many
of the commands you've been using.

The cyan files are symbolic links. A symbolic link allows a given file to appear in many places or under many names at once. Just think of it as an alias or a shortcut. It enables the command to take on several identities whether the user typed in the name of the original command to use it or the name of the symbolic link.

[you@workstation20 you]$ mkdir green
[you@workstation20 you]$ touch green/color.txt
[you@workstation20 you]$ ls green
color.txt


Now use the file linking command, ln, to create a symbolic link called blue that points to the green directory.

[you@workstation20 you]$ ln -s green blue
[you@workstation20 you]$ ls
blue green


List the files in each directory, both the original green directory and the symbolic link, blue.

[you@workstation20 you]$ ls green
color.txt

[you@workstation20 you]$ ls blue
color.txt


You can also create symbolic links that point to symbolic links:

[you@workstation20 you]$ ln -s blue yellow

Understanding Permissions
Every file and directory in a Linux system is governed by a set of security-related properties. In Linux there is no such thing as a file or directory with out an owner.

Use the -l or long listing option, which will cause is to display a great deal of extra information:

[you@workstation20 home]$ ls -l /

drwxr-xr-x 2 root root 4096 08-03 04:04 bin
drwxr-xr-x 3 root root 4096 08-03 04:01 boot
drwxr-xr-x 1 root root 118784 08-03 21:30 dev
drwxr-xr-x 5 root root 4096 08-03 21:30 etc
drwxr-xr-x 3 root root 4096 08-03 04:14 home
drwxr-x--- 3 root root 4096 08-03 18:03 root
drwxr-xr-x 2 root root 8192 08-03 04:11 sbin
drwxrwxrwt 8 root root 4096 08-04 04:23 tmp
drwxr-xr-x 1 root root 4096 08-03 03:54 usr
drwxr-xr-x 1 root root 4096 08-03 04:03 var


o The permissions (a string of characters that will be enumerated later in this hour) of the file or directory
o The number of hard links to the file or directory
o The owning user of the file or directory
o The owning group of the file or directory
o The size of the file or directory on the disk in bytes
o Creation date and time if the file or directory was created within the last six months, or creation year and date if the file or directory was created before that
o The name of the file or directory


Positions 2-4 of this code, dictate what the owning user can do to it.

Position Possible Values
2 r = permission to read/list granted.
- = permission to read/list denied.
3 w = permission to write/create/delete granted.
- = permission to write/create/delete denied.
4 x = permission to execute/visit granted.
- = permission to execute/visit denied.
   

The characters in positions 5-7 uses the same meanings, but for members of the owning group. The characters in positions 8-10 have the same meanings, but they apply to all other users.

Symbolic links, grant permission for everything to everyone. Symbolic links use the permissions of the file that it points to, rather than its own permissions. File permissions can be changed with the chmod command.

The permcode is composed of three parts:
u (for owning user)
g (for owning group)
o (for "other")

a plus, minus, or equal sign, depending on whether permissions are to be added removed or execute assigned.
r (for adding/removing/assigning read permission)
w (for adding/removing/assigning write permission)
x (for adding/removing/assigning execute permission)

[you@workstation20 you]$ chmod o-r illustration.txt

A member of the group would have both read and write access
To prevent this:

[you@workstation20 you]$ chmod g-rw illustration.txt

To give full read and write access to everyone:

[you@workstation20 you]$ chmod ugo+rw illustration.txt

To Log out:

[you@workstation20 you]$ logout

To pause after each page:

[you@workstation20 you]$ ls -l | more

Press the spacebar to continue to the next page.

If the destination file already exists when using mv or cp, it is replaced by the new file.

How to rename friday.txt to saturday.txt:

[you@workstation20 you]$ mv friday.txt saturday.txt

Text Editing
There are two major editors commonly used to create text files. The first is small, called vi; the second is a large, data processor called emacs.

[you@workstation20 you]$ vi myvifile.txt

When working in vi you see the line of tilde (-) characters down the left side. When you first start vi, you are in a mode not designed to allow text entry. You are looking at the command mode. You can save your file, move your cursor around, delete phrases or lines of text, and so on. The insert mode is the only mode in which you can directly enter text. To begin inserting text in the vi file press the i key. Notice that the word INSERT appears at the bottom. There is no word wrap in vi. If you fill the entire screen full of text without ever pressing Enter, the file you save will be stored as one long line of text. This can have unexpected consequences when printing, emailing, or even when editing text files. When you finish entering text, press the Esc key to exit the insert mode and return to command mode. Red Hat Linux uses an enhanced version of vi called vim.

[you@workstation20 you]$ emacs myemacsfile.txt

It is easy to insert text into the emacs editor; just type. You'll find that the arrow keys, Backspace and Delete keys, Page Up and Page Down keys, and Home and End keys all behave as you expect them to. emacs does not automatically word wrap When you press F10, your display is split in two, and the lower half of your display fills with options that can be activated with a single keypress To save the file press f to open the file menu and then S when the file menu appears to save it. emacs displays a message in the small area at the bottom. For most users, the F10 menu and simpler editing style makes emacs the editor of choice over vi. Beeping emacs editor printing cryptic error messages
hold down Ctrl and press g This is the emacs abort keystroke.

While you can use the command find, for large searches locate command more efficient:

[you@workstation20 you]$ locate ' *.jpg'
or if too many come back:
[you@workstation20 you]$ locate '*.jpg' | more

Locate is rebuilt once daily when the system runs the updatedb command. This means that the data displayed by locate might at times not be current with respect to the work you've done in the last few hours. However, it also enables locate to find large numbers of files across the entire disk rapidly.

Save the output of commands like find and locate by redirecting their output to a file. Use the greater than (>) symbol, followed by the name of the destination file.

[you@workstation20 you]$ locate '*.jpg' > myjpegs.txt

The grep command's sole purpose is to search text files for words or patterns that you supply.

[you@workstation20 you]$ grep ball myjpegs.txt

You can also use grep to help you find files that contain a certain word. Suppose you needed to find out which files contained the word Unix. When you use grep -l, you perform a search that is case-sensitive .Using grep with the -l (list files) option, you can get results quickly and easily:

[you@workstation20 you]$ grep -1 Unix
mynewvifile.txt
myvifile.txt

You can use pipes, which are created with the vertical bar ( I ), to cause the shell to use the output of one command as the input or data set for another command.

[you@workstation20 you]$ locate '*.gif' '*.jpg' '*.tif' '*.png' | grep ball
/usr/lib/openoffice/share/gallery/bullets/bluball.gif
/usr/lib/openoffice/share/gallery/bullets/darkball.gif
/usr/lib/openoffice/share/gallery/bullets/golfball.gif

The output of the locate command was sent directly to grep, which searched the data it received for the word ball.

Command substitution allows the output of one command to be used as a set of command-line arguments for
another command.

You can use the Ctrl+Z keystroke to suspend work on an open application so you can open another application.

[you@workstation20 you]$ vi myvifile.txt

You can suspend the vi process by pressing Ctrl+Z:

[1]+ Stopped
vim myvifile.txt

[you@workstation20 you]$

Note the number 1 in brackets; this is the job number of the interrupted vi process.

[you@workstation20 you]$ emacs

You can suspend the emacs process in the same way you suspended the vi process earlier-by pressing Ctrl+Z:

[2]+ Stopped
emacs
[you@workstation20 you]$


To see a list of your current jobs at any time, enter the jobs command:

[you@workstation20 you]$ jobs
[1]- Stopped
vim myvifile.txt
[2]+ Stopped
emacs


To return to your editing work in vi, you can use the fg command, passing the percent sign ( %) and the correct job number as arguments:

[you@workstation20 you]$ fg %1

Commands that do not require user intervention to finish can be run as background tasks. You can use the bg command to run jobs in the background.

[you@workstation20 you]$ locate '*' > fileslist.txt


Press Ctrl+Z

[3]+ Stopped
locate '*' >fileslist.txt


.The command is now suspended; unless it is at some point resumed, it will never finish. To resume it in the background, use the bg (background) command:

[ you@workstation20 you]$ bg %3
[3]+ locate '*' > fileslist.txt &


The command is now running in the background; in the meantime, you are free to return by using the fg command.

[you@workstation20 you]$ jobs
[1]- Stopped
vim myvifile.txt
[2]+ Stopped
emacs
[ 3]
Running
locate '*' >fileslist.txt &


The kill command can be used with a job number to forcibly terminate a job that you don't want any longer:

[you@workstation20 you]$ kill %2
[2]+ Stopped
emacs
[1]- Stopped
vim myvifile.txt
[2]+ Terminated
emacs

Rather than using Ctrl+Z and then the bg command, if you want to start a job that can run in the background from the beginning, simply follow it on the command line with an ampersand.

[ you@workstation20 you]$ locate '*' > fileslist.txt &

Manual pages are brief, yet complete, online documents that describe how to use a specific command or system facility.
The man command and supplying the name of the manual page you want to read, type man. Another documentation system called info.

[you@workstation20 you]$ info

Though the info system might seem clumsy to navigate at first, it contains a wealth of information, often in greater depth than can be found in the man pages. Sometimes you'll find that you're looking for a particular topic in the /usr/share/doc tree, without any real ideas about which command or application documentation should be consulted. At times like this, you can use the find and grep commands you learned along with a new command called xarqs. The xargs command enables you to use very large lists of output from one command as arguments to a second command

In the following example, you use find to list all the files in /usr/share/doc and then g rep to search each of these files for a specific string, supplying the -l option to specify that grep should print the names of files that contain the word. Let's assume that you want to find documentation about tape drives; you might search the entire /usr/share/doc tree for the word tapes:

[you@workstation20 zip-2.31$ find /usr/share/doc | xargs grep -l tapes

You have now generated a list of all of the files in the /usr/share/doc directory tree that contain the word tapes. The echo command takes anything you supply as an argument and "echoes" it by printing it to standard output.

[you@workstation20 you]$ echo "Hello, how are you?"
Hello, how are you?


The expr command provides a way of evaluating arithmetic expressions from the command line.

[you@workstation20 you]$ expr 3 + 4
7


A always remember to enclose the asterisk in quotes when using expr:

[you@workstation20 you]$ expr 3 '*' 36
1 08


Sometimes it is useful to be able to display only the first few lines or only the last few lines of a text file. The head and tail commands can be used to accomplish this.

[ you@workstation20 you]$ head -4 myfile.txt
This is line 1 in a file called myfile.txt that is 16 lines long.
This is line 2 in a file called myfile.txt that is 16 lines long.
This is line 3 in a file called myfile.txt that is 16 lines long.
This is line 4 in a file called myfile.txt that is 16 lines long.
[ you@workstation20 you]$ tail -2 myfile.txt
This is line 15 in a file called myfile.txt that is 16 lines long.
This is line 16 in a file called myfile.txt that is 16 lines long.


The PATH variable contains a Iist of all the directories that are known to hold commands.

[you@workstation20 you]$ echo $PATH
/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/home/you/bin


In this case, the shell searches for commands in /usr/local/bin, /bin, /usr/bin, /us r/X11R6/bin, and /home/you/bin, in that order. To see where the shell eventually finds any given command, you can use the which command:

[you@workstation20 you]$ which emacs
/usr/bin/emacs


If you add to the PATH variable, you can cause the shell to search in more places:

[you@workstation20 you]$ PATH="/usr/sbin:$PATH"
[you@workstation20 you]$ echo $PATH
/usr/sbin:/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/home/you/bin


If you found this article helpful, you can find plenty more back on the main page.
https://subdiv.net