Created on: November 1, 2001
Last Updated: June, 2003
Don't use any commands here until you have read the disclaimer
at the end*
Conventions for this document
Why
not use a GUI? Memorizing commands, are you crazy?
Beginnings
and Essentials
Quick
lesson on options and directories
How
do I view a .pdf file?
How
do close a program that has locked-up?
How
do I view (know) what computers are listed in a domain??
How
do I log into another computer from a shell terminal?
How
do I move files over the network (from a shell terminal)?
How
do I compress and uncompress files?
How
do I delete an entire directory and all directories
under it?
How
do I copy files from my Linux machine to a DOS formatted
floppy disk, so that my Windows machine can read it?
How
do I make a symbolic link?
How
can I see what resolutions and colors are available
to the X-windows Server (the GUI for linux)?
What's
in my PC?
How
can linux repair a hard drive?
Other
miscellaneous commands:
Mounting
a Samba share (Windows drive or folder) to Linux
Mounting
Samba shares at bootup
Mounting
Samba shares (connecting to a Windows network from
Linux).
To
look up your local settings for the network, view
the files
Is
there another way to format a 3.5" disk for Windows?
How
do I add a route?
Printer
commands
Useful
text based programs
Programming
and Network Conventions
*Disclaimer:
itlalics words are placeholders
and will vary from user to user. Don't copy literally.
"#"
represents the beginning of comments. Don't type
this as a command, but it's ok if you do. Bash (your
shell terminal) will just ignore it because it sees
"#" as a comment.
$
represents the command prompt and the beginning of
user input. Don't type this.
You may be thinking, why all this command line stuff
in Linux? In the early 90s, didn't all the operating
systems evolve to the point-and-click method with
GUI interfaces that left DOS command line stuff behind?
Well, yes there is a GUI (X-server) available for
all distributions of Linux, but to do anything useful
with configurations, installations, and to really
know your Linux OS (i.e. security, and performance
issues), you have to go to the command prompt. So
leave that mouse behind and stretch your hands for
some speed-typing, because you're in Linux now. Also,
memorize frequently used commands, and build a text
file for the obscure ones you have used. Eventually
you'll realize that for the gurus, the GUI (X-server)
is just used to pack even more Linux command prompt
windows onto one screen, and for the occasional (ha!)
web browsing.
1.Type these commands from any shell terminal
(open by clicking on "black box thingy"
on lower left of screen)
2.Use [tab] key to autocomplete commands
or files. If it doesn't autocomplete, hit tab twice
to see list of commands or file that match so far.
$
anycommand --help #Shows help menu
for any command. Good source of
#information for the command options
$man
anycommand # A text based Help
file. If the man pages are available for that command,
they are usually an even
#better source of information than "--help."
Man pages
# was started back in the days of Unix (prior 1991
before Linux was created) and have been
#loosely continued in Linux (man pages were required
for most Unix systems, but are optional in Linux).
$
ls #Lists
the files in directory
$
ls -al #Lists
all (the all comes from the "a" in the "-al"
option) the files with details (the details comes
from the "l" in the "-al" option).
# See the section Quick lesson for the meaning
of "." and ".."
$
pwd #Shows what
directory (a "directory" is Linux speech
for a "folder") you are currently working
in.
$
cd directory/ #Goes
into subdirectory called directory
$
cd .. #Backs
up one directory
$
cd / #Backs
up to the beginning (root directory)
$
cp /sourcedir/file.txt /targetdir/copyherewiththisname.txt
#copies the file file.txt
$
mv /file.txt /target.txt
#Moves the file file.txt. Also used for
renaming (it's the same to the OS so there is not
a separate command for "rename").
$
mv /sourcedir/*.txt ../ #Two
things here: 1. uses wildcard (*) to act on all
#files ending with .txt 2. moves these files back
#one directory
$
rm /file.txt
#Deletes (remove) file
$
rm /file.txt -f
#"f " means force.
$
rmdir /emptyjunkdir/
#deletes an empty directory
$
rmdir /notemtpyjunkdir/ -fR
#Forced. "R" means recursive, so it will
delete all
#subdirectories
$
rm . /* -Rf
#CAREFUL! This deletes everything in this
#directory, recursively. It's forced so you won't
be asked for
#confirmation
$
ls -al #Lists
all (the all comes from the "a" in the "-al"
option) the files with details (the details comes
from the "l" in the "-al" option).
This is usually how the options in Linux commands
work. The different options add up behind that little
minus sign ("-al"), and some commands or
options take argruments. For argruments, follow the
syntax given by the "--help" or man pages.
Look for examples.
Notice the two lines at the beginning, there's a "."
and a ".." that represent directories.
Every directory on the computer has these two in them
(except the root directory, /, it does not have ".."
) .
The "dot" directory is the current directory,
so if you type "rm ./*.txt" it will only
delete text files from the directory you are in.
However, if you left out the "." and typed
"rm /*.txt" you would have deleted any text
files from your main (root) directory. So be careful.
The "dot dot" directory is the directory
above it, so that's why you type ".." when
you want to go up a directory (i.e. type "cd
.."). Even more useful, say you wanted to create
a directory in the parent directory, move some files
there, and do it without having to move from the directory
you are in. Just type "mkdir ../newdirmadeeasy"
and then move some files to it (i.e. type "mv
fileOne fileTwo ../newdirmadeeasy/ ").
$
xpdf filename.pdf
# assumes the program XPDF is installed
How do I view what is being processed along with PIDs?
$
top #press
[ctrl-Z] to exit
Or
$
ps -ax
$ps
-ax | grep 'lockedprogram'
Let's
say for example Netscape has an opened window that
is hung up and won't close.
$ps
-ax | grep 'netsc' #Type the first
three or four letters for the program you want to
find
Find
the PID of the most likely process of Netscape (a
single program has multiple processes), and carefully
type that PID into the command:
$
kill -9 #### #Where ####
is the 4-digit number for the PID.
$
host -l lan.vbn #lists all
dns names assign to the domain vbn
If the ssh program (i.e. ssh server) is running on
the server computer, and a ssh client program is installed
on the client computer, you can use this. For Windows,
Putty is a good program that has ssh among other client
programs for connecting to Linux servers.
$
ssh youraccount@machine.lan.vbn
To
log out press [ctrl-D] or type
$
exit
$
scp youraccount@machine.lan.vbn://sourcedir/file
//destinationdir/ #downloads
$
scp //sourcedir/file youraccount@machine.vbni.com://destinationdir/
#uploads
An
example is to back-up your home directory. Be sure
you are in your home directory and type:
$
tar -zcvf ./backhometodaysdate.tgz ./*
#"-z" means z compression format
To
uncompress to the current directory (Precaution: uncompress
to a temporary directory):
$
tar -zxvf ./compressedfile.tgz
#notice the option change -c to -x
Caution:
Be sure you know what you are removing. This command
doesn't ask for confirmation when deleting.
$
rm -fR ./worthlessdirectory
For
Linux,
$
/sbin/mkfs -t ext2 /dev/fd0
For
windows,
$
/sbin/mkfs -t msdos /dev/fd0
A symbolic link is like a "Shortcut" in
Windows.
$
ln -s /sourcedir/file /targetdir/newlink
Don't
edit this file unless you know what you're doing.
cat
/etc/X11/XF86Config
To
find out details on most of your computer's part except
CDROM speed, video RAM, and monitor size, view the
following files:
/proc/pci
/proc/meminfo
/proc/cpuinfo
For
the size of the harddrive, type this command
$df
-h
For
the size of the current directory, type
$du
-h
$fsck
/dev/hda1 #replace
hda1 the with harddrive letter and number
#you want to check. Use command $df -h to find
#this harddrive information.
$
shutdown -r now
#restarts the computer
$
shutdown -h now
#shutsdown (halts) the
#computer
$
mkdir newdirectory
#makes directory
$
pwd
#prints what directory you are in
#(print working
directory)
$
less file
#views file
$
cat file
#views file
$
rpm -ivh
#installs package, verbosely
$
rpm -iq
#?
$
smbmount //server/dcregal -o username=dcregal
-or
-
$
mount -t smbfs //sambaserver/directory/
/wherever/ -o password=something
#When mounting with the commands above, the mount
will disappear when the computer is restarted. So
to have it mount at boot time, edit the /etc/fstab
file.
$vi
/etc/fstab
Add
the following line to the bottom of the /etc/fstab
file.
//sambaserver/directory/
/wherever/ smbfs password=something
0 0
From an email from Bill Jr., my manager at the time.
1.
Make sure that smbfs is installed on your computer.
A good indication
is
a 'man -k smbfs' and see if it returns anything.
If it doesn't the
odds
are significant that you need to find it and install
it.
2.
To connect to the network, do this.
$cat
/etc/passwd | grep "whateverYourUsernameIs"
note
what your userID and your groupID are.
3.
go to your home directory (as your non-root user).
$
mkdir network
$
cd network
$
mkdir sharename #(they will be listed
at the bottom of this mail by
username).
$
su - (or get root)
4.
edit your /etc/fstab
add
a line like this for every share to the end of your
fstab:
(all
on one line)
//lanserver/dcr
/home/dcr/network/dcr smbfs
username=dcr,password=****,uid=$UID,gid=$GID
0 0
(end
one line)
the
$UID is the UID you got out of the /etc/passwd file
the
$GID is the GID you got out of the /etc/passwd file
the
**** behind password is your password spelled out
in plain English.
5.
Example of shares
dcregal:
//lanserver/dcr
//lanserver/forms
//lanserver/technology
rbk:
//lanserver/rbk
//lanserver/forms
//lanserver/technology
mac:
//lanserver/mac
//lanserver/technology
-------
You
may want to hang onto this. This is how you can connect
to a windows network from linux.
Bill
Jr.
$
/sbin/ifconfig
#your network configuration for
#your hardware
$/etc/hosts
$/etc/resolve.conf
#shows your IP addresses
$netstat
-nat
#shows status of the your computer's
# network connections
$netstat
-a
$netstat
-at
You
should format your disk in Windows, then mount it
in Linux using the following instructions.
First,
as root type:
mkdir
/foo
Then
with the floppy in the drive, type:
mount
-t vfat /dev/fd0 /foo
To
copy files, use the command:
cp
[filename] /foo
To
unmount the floppy so you can eject it, type:
umount
/foo
$route
add net 202.87.240.0 202.87.242.23 1 #static;
will be there until manually
# removed. Administrator has to know the topology
of the network at boot time #and that topology
must not change between boots.
$routed
#dynamic (Uses daemons). Standard UNIX.
$gated
#dynamic (Uses daemons). More features.
$iptables
#Better way to make a firewall
sftp
[file][folder]
#secure file transfer protocol
/etc/init.d/lpd
--help #this
will give you the options
/etc/init.d/lpd-ppd
--help #this will
give you the options
pdq
#shows status
xpdq
#gui program
to configure pdq when in xserver
lpq
#Shows the documents in the print queue
$
bc # BC is
a text based calculator.
Careful
of the rounding (e.g. Type "1/2" and press
Enter. It will return "0.").
Exponents
examples:
Ex. 1
2^4 [Enter]
Should return 16.
Ex. 2
4^1/2
Should return 2.
$lynx
www.somewebsite.com #
lynx is text based web-browser that will display most
sites.
#This is the best way to surf when you do not have
X-server.
Naming Conventions at an Internet company
Conventions are important
when working with computers. Write up the standards
and conventions followed and let every programmer
and network personnel know. Even if it is just you
working on the computers, you should be consistent
so your work will be more organized, thus easier to
find your way around, and the code in each program
you write will look the same (you can read you own
code months later). Short term it takes more time
(setting up the conventions), but once it is set-up
and followed, long term it will save hours because
programmers can read the code of another easier.
Network
fmlast.subdomain.copany
Ex:
dcregal.lan.vbn
IP numbers
.255
for gateways
Databases are named with all
capital letters.
Ex:
DATABASE
Tables contained within a database
are named first letter capitalized.
Ex:
UpperUpper
PHP variables and Cookies
are named with "stud cap" format.
Ex:
lowerUpper
HTML, all attributes are lowercase
except SELECTED and CHECKED follow example below
<INPUT
type="lower" SELECTED>
<
CHECKED>
Although I have never damaged
my computer using these commands, use the commands
here at your own risk. Used improperly, some
commands can crash programs (kill -9) or erase entire
directories (rm -rf /bin/laden). I am not responsible
for any headaches, lost or corrupted data, security
holes, damaged or locked-up computers resulting from
using these.