***********************************************
BY TRAVIS WHITTON(whitton@atlantic.net)
***********************************************
GETTING AROUND:
To get around in Linux you need to know some basic commands:
ls - equivalent to dos dir
ls -l - formats output into a column and shows file rights
mv file1 file2 - renames file1 to file2, also used to move files.
cd - used to change directories
cd .. - change up a directory
pwd - show where you are
more filename - almost same as type filename in dos
pico - a nice comparably user friendly editor
vi - a nice less friendly editor
man - linux help files i.e., man ls (would bring up help on ls command)
MORE COMMANDS:
ps - list the programs that are running
kill -9 process id - quit an active program
grep "text string" filename - search a file for a string of
text
find / -name filename - find a file starting at / directory
updatedb - update the database for the locate command
locate filename - find a file(very fast!)
chmod permissions filename - set file permissions( e.g. chmod 755 data.txt
)
startx - start x windows
pppstats - self explanatory
uname -r - tells what kernel version you're using
usernet (from X) - manage network connections
man pagenumber manfile name - get some more help
info topic name - even more help
pwconv - enable shadow passwords
dmesg | more - show boot up messages
mke2fs - format a partition with the ext2 file system
fdisk - a fun game, don't play it too often :)
printenv - lists all environment variables including path.
FROM DOS:
fdisk /mbr - reset the boot record (more on this later)
HOWTO FORMAT YOUR FLOPPIES:
fdformat /dev/fd0H1440
mkfs -t ext2 -m 0 /devfd0H1440 1440
HOWTO TAR AND GZIP NEW ARCHIVES:
Say we have 3 files which are all part of a project we are working on.
Their file names could be file1.cxx file2.cxx and file3.cxx. If we wanted
to store them all under a single file name, we should create a tar archive
file like this:
tar -cvf archive.tar file1.cxx file2.cxx file3.cxx
This will create a file called archive.tar, which contains file1.cxx, file2.cxx...
The -c instructs the tar program to CREATE an archive. The files placed in the
archive will be left unmodified. Next, we want to compress our archive to preserve
disk space. To do this we
should use gzip. An example of this operation would be:
gzip archive
We should now have a file named archive.gz that is substantially smaller
than
the original 3 files combined. To extract the files use:
tar -zxvf archive.gz
The -z tells tar to gunzip the file the -x stands for extract the -v stands
for verbose and the -f preceeds the file name.
HOWTO FIND OUT YOUR IP ADDRESS:
This one is easy! Just type ifconfig at the prompt.
HOWTO FIND OUT HOW MUCH DISK SPACE YOU HAVE:
Type df.
SWITCHING CONSOLES:
To switch from one console to another try: alt-F1, alt-F2
etc...
To switch out of X-windows ctrl-alt-F1
To switch back alt-F5.
SYMBOLIC LINKING:
A symbolic link is equivilent to a Win 95 shortcut. Say we wanted to make
a file called dosdir in the / directory point to the ls command in the /bin
directory. All we would have to
do would be:
ln -s /bin/ls /dosdir
MOUNTING DRIVES:
In Linux there is no C:\. Everything is treated like a file, so there is
a much more
flexible way of dealing with drives. The C drive in dos is usually called hda1
in linux.
In order to access it we must perform an operation called mounting. First, we
must have a directory that we want to mount to.The most common directory to
mount the C: drive to is /dosc. Make the /dosc dir like this:
mkdir /dos
Mkdir stands for make directory. Once the directory is made, we can mount
hda1 to the dosc
directory. Hda1 resides in the /dev directory (along with all other devices).
All we need
to do to mount it is.
mount /dev/hda1 /dosc
Then we can:
cd /dosc
ls -l
There are all your files! Once your done, don't forget to unmount:
umount /dosc
You can mount any storage device connected to your computer as long as it's
configured
for Linux. Here are some typical device names Cdrom=/dev/hdab Floppy Disk=/dev/fd0
Zip Drive=/dev/sda4(dos partition) /dev/sda1(linux partition)
SHUTTING DOWN:
It's just as important to shutdown Linux properly as it is for Windoze.
To safely shutdown
Linux, use the shutdown command:
shutdown -h now
This will call system halt, so you can turn off the computer.
shutdown -r now
This will restart the computer.
The now keyword after the shutdown command can be set to any time interval as
long as it's an
integer.
FILE/RESOURCE MANAGEMENT:
A useful file manager is the norton commander clone, midnight commander.
Type mc to start it.
Type top to get some good system info. Also, df will display drive
capacity along with all
mounted drives. To get the low down on all your resources check out /proc.
SETTING UP AN ALIAS:
You can change commands in Linux to have additional meanings by setting up an
alias.
For example, I like my directory listings to be in color, so I made an alias
so that the list command always displays color. To do this you need to edit
your .bashrc file in the root directory. First change directories to
/root or your home directory if you don't have root.
Next, type:
pico .bashrc
Add the line:
alias ls='ls --color=auto'
This tells the ls command to always display color. You can modify
any command to always include tags in this manner.
Note: If you aren't using bash as your shell then you will have to edit
a different file.
For more info on what shell you're using type printenv.
USING THE GCC AND G++ COMPILERS:
Linux includes powerful GNU compilers to make binaries from your c/c++ source
code. Using them
is easy. First, write a sample program in pico and name it
hello.c i.e.,
#include<stdio.h>
int main()
{
printf("Hello World!");
return 0;
}
Next type:
gcc hello.c
This will create a file called a.out. If you want it to be named something
else, do this:
gcc -o hello hello.c
This will create a file named hello from the hello.c source code. If you're
working with
c++ code use the g++ compiler as so:
g++ -o hello hello.cxx
Make sure you name your source file .cxx instead of .c. Emacs is another
powerful editor
that will work well in many languages i.e., c, c++, perl. To start emacs type
emacs.
If you type emacs when in Xwindows and have Xemacs installed then it will start
Xemacs.
HELP! A.OUT WON'T EXECUTE:
This is probably because your path does not include :.: to execute a.out
you need to type
./a.out to let Linux know you wan't it to execute in the current directory.
:.: isn't in the default path for security purposes. This is true any file that
isn't
in your default path. To see your path type printenv. Anytime you're
not in a directory
listed in the path, you'll have to use the ./ in front of the filename you want
to
execute. You can modify your path to include more directories; however, it isn't
recommended to add :.:. To add a new directory to your path, use the
export command
like so:
export PATH="$PATH:/your/new/path"
You can export any environment variable this way.
You can also unset an environment variable once it's set with the unset
command:
unset PATH
More on environment variables later.
CHANGING A USER'S PASSWORD AS ROOT:
All you have to do to do this is: passwd username
you'll be prompted for the new password for that account. To change root's/regular
user's password, as root/regular user type:
passwd
You'll be prompted to enter the old and new password. Pick a good password,
e.g., something
that's not in the dictionary. Something like K4s~@31 is great. Make sure your
password is
at least 6 characters, mixed case, and contains at least one symbol. This makes
it much
harder for a password cracker to crack your password.
USING CAT TO SEND THINGS PLACES:
The cat(concatanate) command is more useful than it initially seems. For
example, if you want to play a wav or au file you can cat it directly into the
sound card. This works because the cat
command simply sends a file byte by byte to whatever location the pipe is pointing
to.
To play the file sample.au we would:
cat sample.au > /dev/audio
Assuming your sound card is configured correctly this should work fine. Cat's
true purpose
is to concatanate two files together. This is done in the same manner except
we use
two > instead of one. Two > tells linux that it should append instead
of overwriting. To write
the contents of a text file named chapter1 to the end of chapter2 we would:
cat chapter1 >> chapter2
PUSHD AND POPD:
You can use the pushd and popd commands to get around quickly. Pushd sets a
directory
then you can use popd to jump to whatever directory you set with pushd.
Consider the following example:
pushd /usr/local
cd /etc (now your not at /usr/local anymore duh...)
popd
Now you're back in /usr/local
USING DIFF AND PATCH:
Two very useful commands are diff and patch. Diff displays the differences
between two files
and works as so:
diff file1 file2
Where file1 is the name of the first file and file2 is the name of the second.
It then displays output describing what needs to be done to make file1 equal
file2.
Here is a quick example:
echo "hello" > hello
echo "hello world" > world
diff hello world
This would yield:
1c1
< hello
---
> hello world
Now you're probably saying "what the hell is the use of all this?" Well,
the use is that
you can use diff to make a patch file, which can be VERY useful. Here's how:
diff hello world > hellopatch
This places the output of the diff command into a file called hellopatch, which
we can
now use to patch the hello file to make it equal to world. All we have to do
now is
patch it like so:
patch -n hello < hellopatch
This will display
patching file `hello'
And now to test it:
cat hello
hello world
If you still don't see the use, consider the following scenario.
You write a huge program in (insert your language here) and distribute the source
to tons of people. Later on you find a bug in the code which requires only a
few lines of code added. You can either make everyone download the entire fixed
source code all over again, or you can do
the right thing and put out a patch that can be downloaded in seconds and applied
to the
already existing source code. This saves everyone time, and everybody loves
running a tiny patchand watching the magic happen.
PRINTING:
To send something to a printer
Use the command:
lpr -P printername documentname
To check the queue status. And use:
Use:
lpq
To remove all jobs from the queue (*note this can take a second or two)
lprm -
USING ECHO FOR QUICK TEXT FILES:
Another command that can be very useful is the echo command. Combined with
the > operator
echo can write a quick text file without even opening an editor. Heres how:
echo "This quick memo will go into a file named memo" > memo
It's that easy! To add another line to the end of memo:
echo "This will be the last line in memo" >> memo
Ethernet:
This is a very sparse example of how I got my ethernet card working in RedHat.
If you use modules, edit the /etc/conf.modules file and add the
appropriate module for your card. E.g.
alias eth0 ne2k-pci
edit the /etc/rc.d/rc.local file and add your routing info E.g.
route add -net 192.168.0.0 netmask 255.255.255.0 eth0
route add default ppp0
Restart the computer and look in /var/log/messages to see if your card
loaded
and check for error messages. Type ifconfig to check and see if your
ip got assigned.
QUICK/USEFUL X GUI PROGS:
To get into the X-Windows control panel type:
control-panel
For the network configurator e.g. to setup ppp try:
netcfg
And to get into the graphical redhat package manager user:
glint
USING YOUR IOMEGA ZIP DRIVE:
Connect your zip drive properly and start the computer. If you did it right
and have kernel version 2.0.36, you shouldsee something like the following upon
bootup:
VFS: Mounted root (ext2 filesystem) readonly.
Adding Swap: 102528k swap-space (priority -1)
ppa: Version 1.42
ppa: Probing port 03bc
ppa: Probing port 0378
ppa: SPP port present
ppa: EPP 1.9 with hardware direction protocol
ppa: Found device at ID 6, Attempting to use EPP 32 bit
ppa: Communication established with ID 6 using EPP 32 bit
ppa: Probing port 0278
ppa: SPP port present
scsi0 : Iomega parport ZIP drive
scsi : 1 host.
Vendor: IOMEGA Model: ZIP 100 Rev: D.09
Type: Direct-Access ANSI SCSI revision: 02
Detected scsi removable disk sda at scsi0, channel 0, id 6, lun 0
SCSI device sda: hdwr sector= 512 bytes. Sectors= 196608 [96 MB] [0.1GB]
sda: Write Protect is off
sda: sda4
lp2 at 0x0278, (polling)
If the zip disk is formatted with a dos partition, you should mount it like
so:
mount /dev/sda4 -t vfat /zip
If it is formatted as a linux partition :) (good choice) you need to do
this:
mount -t ext2 /dev/sda1 /zip
If you want to format it like a linux partition do this:
fdisk /dev/sda
and delete any existing partitions (with the d command). Then create a new
partition
with the n command, make it primary partition number 1, use w to write the partition
table to disk, and quit with q.
Format the partition:
mke2fs /dev/sda1
How do I say the word Linux:
This is debatable; however, included with most distributions is an audio sample
that
plays to make sure your sound card is working. The sample is some guy doing
a parody
of how Linus himself says it, and it sound something like "leenux".
People will argue
over this however, and it's really a matter of personal preference.
//-------------------------------------------------------------//
//-----This document will be updated often. Always reload-----//
//-----Email questions/comments to whitton@atlantic.net-------//
//------------------------------------------------------------//