|
A Beginner's Guide to Linux (or rather, Linux for DOS junkies)
by Ed Hagihara
First of all, a kudos to a friend:
I had a
love-hate relationship with Linux for about 7-8 years until I met a very nice
Assistant Director of IT at a company I used to work at.
Once I started working there, I finally had someone that I could bounce
off enough questions that would truly enable me to get going on this. Many,
many, many thanks to Mike Wing at McMullen Argus for the insight to get the ball
rolling - I hope this document can help someone in the community the way Mike's
helped me.
I'm also very grateful to the community - If it wasn't for Linux, I'd just be
waaaay more clueless about other flavors of Unix. Learning Linux really
gave me the ability to assimilate what's going on with other unices
(like Solaris and HP-UX) more easily.
- Some notes (mostly for people that have
some understanding of DOS):
Making the transference from Windows to Linux can be confusing, and I went through a
tremendous amount of frustration with my learning curve in Linux.
I do remember where some of my key hangups were in learning this, so I'm
documenting some of the concepts in the hopes that you this helpful.
Please note that this document is NOT going to
contain a comprehensive list of commands. Yes, I know that there are
probably more efficient/better ways of doing things, but I'm going to cover the
stuff I used to get me to maneuver around the system.
This is some basic stuff to keep in mind:
- Directories are represented by forward slashes ( / ) not
backslashes ( \ ).
- Unlike DOS and Windows (and to some extent, Macintosh unless you're using
the UFS filesystem under OS X), files and directories are case-sensitive.
This means that you can have files named stuff, STUFF, sTuFf, STuFF,
etc., and they will all be considered completely different files by the OS
because the letters are upper and lower case in different places.
-
When you do a cd (change directory), make sure to add a space between
cd and the directory. Example:
cd /etc
cd ..
Back in the DOS days, I'd be lazy and not do this which created a LOT of
typos for me when entering commands in Linux.
- Partitioning - Partitioning can become a religious debate, which
I'll avoid - this just what I usually do. At the minimum,
I'll set up at least 100MB for /boot, whatever else for /, and save about
250-300MB for swap. It's also probably a really good idea to also
allocate a separate partition (maybe about 500-700MB depending on how much you
expect to log) for /var (usually for log files) in the event that your log
files don't go crazy and fill up / if there's a problem. If I want to set
it up as a file server, I'll also set up a separate partition for data files
usually under the Red Hat default of /home (again so / doesn't get overrun
with user files -or- you can always set up quotas).
- Other commands – here are some commonly used commands. Please
note that the usage for sourcefile destinationfile also implies
/directoryname/sourcefile /directoryname/destinationfile:
-
Copy a file - To copy a file, issue the command:
cp sourcefile destinationfile
if you want to make it so that it will copy subdirectories as well, you
can use
cp –r source destination
Note that the ‘–r’ stands for recursive.
Remove a file - to remove a file, issue the command:
rm filename
if you want to remove a directory and all subdirectories with it, you can use
rm –rf directoryname
Again, the ‘–r’ means recursive (drill down through the directories), and
the ‘f’ means to force the delete without prompting.
-
Create/remove a directory - to create a directory, use:
mkdir directoryname
If you want to remove an empty directory, you can use:
rmdir directoryname
-
Rename/move a file - whether you want to rename or move a file, the command
is the same: mv. To move or rename a file, use the syntax:
mv sourcefile destinationfile
-
Symlinks – a symlink is also known as a symbolic link. If you’re coming
from the windows world, this would be called a shortcut. From the mac
world, this would be called an alias. It’s basically a symbolic
representation of the original file, which would be elsewhere in the
filesystem. This is usually created by issuing the command:
ln –s sourcefile destinationfile
- How do I edit a file?
vi is the most prevalent text editor in Linux. There's another one
called emacs, but for the purposes of this topic, I'll just stick with vi.
Anyhow, this program drove me freaking nuts - the first time I ever got into
this program (before the internet), it took me about 30 minutes of plowing
through random books to figure out how to get out of it. Now I find myself
issuing vi commands whenever I'm in DOS EDIT (grrrr....). Here's some notes on
vi:
Much like the DOS editor EDIT, you can create a new file by issuing a command
like: vi newfile which will start up vi and create a new file.
Likewise if you want to edit a existing file, you can issue a command
like: vi /etc/hosts.
Now, unlike EDIT, you can't just start a new file and begin typing -
you start off in what's called the command mode. To start typing you have to
press the letter i to insert new text. THEN
you can start typing. After you're finished typing, press the
esc key to get into command mode then you can issue a :wq
to write the file and quit the program. Here are some basic commands to
help you get going:
esc - takes you to command mode
i - insert
a - append
x - delete a letter
dd - deletes a line
:w - writes the file
:q - quits the editor
:wq - write and quit the editor
:wq! - if the file's read-only, force writing and quit the editor
/ - search for text. Example: /whatever searches for the word
"whatever" in the document.
- How do I find a file?
By issuing the command:
find / -name filename
Now, the slash in the command represents the root directory.
If you know the file that you're looking for is in /usr, you could just
as easily issue:
find /usr -name filename
- Where the $%#& is my cdrom drive? My floppy drive? I want my
drive letters!
This one took me a while to figure out the concept behind this. Unlike DOS, Linux
(and Unix) doesn't have drive letters, per se. They use what's called a
"mount point", and basically, the cdrom or floppy can be put anywhere
in the directory structure. By default, Red Hat usually puts them under
/mnt/cdrom and /mnt/floppy but theoretically, you could put it
anywhere in the directory tree if you want. Typically, it's not like dos
or windows where you can just stick in the floppy or cd and have it automatically
appear. This is actually a two step process - after putting in the cd or floppy,
issue the command:
mount /dev/cdrom (mounts the device called cdrom) or
mount /dev/floppy (for the floppy, of course).
then you can go into the /mnt/cdrom or /mnt/floppy directory and view
whatever files are on the cd. When you're done, issue the command:
umount /dev/cdrom -or- umount /dev/floppy (be careful of the
spelling of umount - why this wasn't called unmount
is beyond me, but oh well...)
and optionally:
eject cdrom
Incidentally, yes, I have seen Red Hat 8.0 automatically mount cds in gui mode,
so whether or not this’ll work may depend on your particular distribution.
- What is a runlevel?
- The closest thing I can equate this to in Windows terms is that it’s
sort of a profile (group) of services that loads. The most common
runlevels in Linux for booting up are runlevel 3 (command line mode) or
runlevel 5 (in gui mode).
Other runlevels (which I won’t cover here except briefly) include:
runlevel 0 (shutdown procedures)
runlevel 1 (single user mode, usually run for recovery purposes),
runlevel 2 (essentially the same as runlevel 3 without networking features)
runlevel 4 (currently unused), and
runlevel 6 (reboot).
You can kick off a particular runlevel by issuing an init command.
So for instance if you want to reboot your system, you can use the command:
init 6
which will reboot your box. Or if you’re in a gui mode and want to switch
to command line mode, you can kick open a terminal window and type in 'init 3'.
Yes, I know that there are other commands that will do the same thing.
To reboot your system, you can type: reboot –or- shutdown –r
now. To shut down your system completely, you can also use:
shutdown –h now.
-
Okay, now back to the groups of services that I was talking about.
You’ll find in /etc/rc.d that there are some other directories that are named
rc1.d, rc2.d, rc3.d, etc. These directories are analogous to the
runlevels that I mentioned above. So if you want to change the way things
are loaded in runlevel 3, you’d go into the rc3.d directory.
You’ll notice that you have some files that begin with a ‘K’ like K09isdn
K20nfs, etc., and some that begin with an ‘S’ like S60lpd, S80sendmail, etc.
The bottom line is that each one of these is a service. Files that begin
with a ‘K’ are services that are disabled, and services that begin with an ‘S’
are enabled. For instance, if you want to disable sendmail, you’d
basically rename the sendmail program:
mv S80sendmail K80sendmail
...and reboot for the change to take effect. Likewise, to re-enable
sendmail:
mv K80sendmail S80sendmail
...and so forth. Also, please note that the files in there are symbolic
links to executables located in /etc/rc.d/init.d.
If I happen to think of any other stuff to add here, I will. In the
meantime, if you have any ideas or suggestions to make this better, please feel
free to drop me a note at: ehagihara [at] hotmail.com.
|
|
|
|
©
2002-2003 - Edward Hagihara and Ms. Phitt, Web Site Development by
Ms. Phitt
|