contrl-d -exit
or logoff
The proper way to shut down in linux:
1. Become root
2. sync (data in memory sent to disk)
3. reboot then enter
cp
-to copy file
cp <file to be copied> <destination>
Example:
cp /etc/passwd /mnt/floppy/password.txt
cp <path/filename> <destination path/filename>
>First part of cp or copy command is the directory where the file
is:
Examples: /etc /mnt/floppy /mnt/cdrom
cp linux~.txt (name on floppy-can't use tilde ~ with
linux-so you need to change name) /home/ck/lcomm.txt
This copies text file to this subdirectory and changes the name-same
content.
File condensation and
manipulation:
gzip
-zipped files gunzip -to unzip
tar -tarred files, compressed files
Examples: mfm1.3.tar.Z freedom_desktop.tar.gz youngcpp.tar
to unzip a gzipped file (* .tar) or (* .gz) gunzip (filename) gunzip motif.Z
to untar a tarred file (* .tar) tar-xvf titan(filename)
to both unzip and untar tar -zxvf titan(filename)
ln -link, soft link
or hard link
ln [options] source [dest]
ln [options] source directory
hard links made by default if no option, switch
ln -s -soft link, does not come into play on boot up
>Generally speaking, use only soft link only because if hard link fails to
work on boot, then the computer may not boot up.
>To create a soft link to automatically boot up a program
Example: To have myslq daemon to automatically run at boot up
cd /etc/init.d
ln -s /etc/init.d/mysqld /etc/rc.d/rc3.d/S81mysqld
ln -s source target destination and program to start.
Use capital S to start automatically. Use
any number but must be different from other numbers in other scripts
ls
-list
switches of ls:
ls -l -long names Gives description so you can tell directories from
files and other information
ls -a -show me all files including hidden files shows dot files which
start with period
mount
-mount a drive This command generally only needed in older
versions of linux
Examples:
mount /dev/fa0 mnt/floppy
To mount floppy
>Become root and type
mount /mnt/floppy
>To see contents of floppy: ls /mnt/floppy
mv -move, rename (use with great caution,
dangerous command)
Change file name with mv and move file -powerful command-be careful
Examples:
mv <old filename> <new filename>
mv <path/filename> <newpath/filename>
mv removes a file or moves it from one directory to
another
mv -i oldname newname
mv -I filename directory [/newname]
cat
Use command cat only for viewing short files.
Very useful for this purpose.
cat /etc/hosts
more less
(These are 2 separate commands and
very useful ones for viewing text)
>Use commands to see longer text files in an orderly way: that is,
you see one section at a time, then you can go to the next session when
viewing text on the command line.
>Use the spacebar to go to next section when you view the text
file. To end, type q
more <filename> more linuxtext (To view contents of file,
linuxtext)
less <filename> less linuxtext
(To view contents of file, linuxtext)
rm -(remove a filename, file)
rm <filename> Will ask you for confirmation
And switches:
rm -f Will force delete-won't ask
rm-r delete all subdirectories and files -powerful command be careful
rm -fr - " " -will not ask for confirmation
* means everything like DOS
Example: rm -f *
rm -i asks you to confirm
that you want to delete each file
rm -i <filename> rm -fr remove, forcible recourse
rpm
-package for installing programs.
>This command applies to Red Hat distribution.
Installing-uninstalling RPM-s are are proprietary (only used with Red Hat or
related linux distribution like Fedora) RPM stands for Red Hat Package
Manager.
1. Download using Mozilla web browser or Netscape or ftp. In Netscape,
hold down shift key when downloading rpm.
2. Install rpm install /rpm -i- You can save time by typing only 1st 2
letters of name of rpm-then hit tab key.
3. To uninstall use rpm -e <name of file>
>How can I install an rpm off of a FTP server?
RPM supports the use of ftp on the command line to update packages. Keep in
mind you must have a network connection of some kind for this to work. :-)
Format: rpm (options) (pathname)
Example:
rpm -uvh ftp ://ftp .redhat.com/pub/redhat/redhat-4.0/updates/i386/ghostscript-3.33-3.i386.rpm
>In general, normal usage of the rpm command can be summarized as follows:
---Installation/Upgrading/Removal
To install a package: rpm -ivh <filename>
Example: rpm -ivh somepackage.1.1-4.i386.rpm
To upgrade a package: rpm -Uvh <filename>
Example: rpm -uvh somepackage.1.1-5.i386.rpm
To remove a package: rpm -e <packagename>
Example: rpm -ivh somepackage
>Also, for upgrading or installing some packages you may need to use
additional flags to force the install to happen. It is only recommended to
use these if you know why these flags were needed.
--force -will overwrite files that are owned by other packages.
--nodeps -will install even if the package needs packages that were
not installed.
---Querying
>To see if a package is installed:
Example: rpm -q <packagename>
Example: rpm -q <somepackage>
>To get info on an installed package:
Example: rpm -qi <packagename>
rpm -qi somepackage
>To list which files belong to a package:
Example: rpm -ql <packagename>
Example: rpm -ql somepackage
To see what package a file belongs to: rpm -qf <path-to-filename>
ex: rpm -qf /usr/bin/some_executable
>One can usually join various query commands together, so
rpm -qil
-will give information and list all the files in the
package.
>To look in a rpm filename that isn't install example, you tag on the p to
the query line.
Example: rpm -qilp
somepackage.1.1-4.i386.rpm
-will list the
information and the files contained in somepackage.
--Verification
>To see what files on the system may have changed from their initial
settings you can use RPM, to check up on them.
Example: rpm -Va
-will give you a list of all files that
have changed in one form or another since the package it is associated was
install ed. This can be a lot of files (and a lot may be changed due to post
installation work). To just see what packages have changed so that you can
verify them more individually, you can do the following:
rpm -Va | awk ''{print $2}'' | xargs rpm -qf | sort -u &> /tmp/file1
Then look in the file /tmp/file1 for which packages have had changes from
them.
shell
-terminal which has functionalities communication terminal to communicate
with a computer
>The command interpreter used to pass commands to an operating system; so
called because it is the part of the operating system that interfaces with
the outside world.
.bashrc is the main shell configuration file for a user (there are
other shells of course)
cat .bashrc command to see file
cat bashrc | more to see file one screen at time
cat bashrc | less to scroll
man (topic) ex: man
gzip -manual, to go to manual To access help files in both unix and linux
Miscellaneous and Summaries of
Commands:
bin
-(bin stands for binary and binary files are all executable programs)
>Ways to look at directory contents:
1. go to directory with cd >then ls
2. ls /directory
Example: ls /mnt ls-l /mnt ls -al lists
hidden, long filenames
^ up arrow-goes to previous screen
clear -clear screen
# Use this symbol if you want to comment
this out. For your information not for linux to read
>To create directories -Go to where you want the directory to be - or type
path: /mnt/floppy/gofaq.txt use:
mkdir (make directory)
Contrl-d -go back to other available user
man -show manual, help files ex: man gzip
pico -A simple, nice editor Use pico -w to
help prevent mistakes in editing.
pine
- popular email client for command line
(text only) Very easy to use.
gzip gunzip zipped files
.tar tar -xvf tar zxvf
tarred (a
certain file format) files
startx
-start in graphic mode.
Important command to remember if you like to switch between runlevels-Go
from text only to graphical
|
(pipe) = The pipe command is a very
important command to redirect standard output from one process to another
Example: dir | more (Take the
dir command which shows files in a directory and pipe to more to view in an
orderly fashion.)
root-every
directory can have a root -can mean root directory -or the root is superuser.
The Unix, linux superuser account (with user name "root" and user ID 0) that
overrides all other file permissions. The term avatar is also used. By
extension, the privileged system-maintenance login on any operating system.
su
(enter)-to become super user or change
to different user
Cntrl-d -to go back to ck user
cd (and space) will take you back to home directory
cd .. Takes you back to prior directory
Cntrl-d -to go back
ifconfig -shows interface
configuration for network
Commands To
view and analyze Network:
lo -loopback-virtual
interface Needed for local machine
etho-o -physical
card(network card), hardware address given, recognized in BUS
The inet address is the IP address of
card
broadcast address represents a
subnet of network addresses
ls
-to list
ls -l - to list in long form, this
command with switch -l shows permissions for files and directories.
>In linux, someone owns a file and is the only one who has
permission to use the file except for root that has permission to change any
file:
Example: drwxr-xr -x 2 root root bin -d
(defines a directory; by group of 3:directory-then
permission-user- bin is name of directory
>Linux names for devices:
cuu -comports
cui
-com interfaces
fd
-floppy drives
tape
-tapes drive
hd -hard drive
Users:
>If you want to see what users exist, here is the command: more /etc/passwd
This will display the file which contains info about all the users.
>If you want to add user nick, here's what you do:
adduser nick (must be root to
add user)
passwd
nick -to give password to nick
>User profile is in the
hidden file .bashrc
.bashrc -user specified alias and function
/home/user/.bashrc
PATH=
First have to put path you already have. Note: You have to log out
and back in to take effect
Searching and Finding:
where is -searches anywhere on the
computer
which -searches only in your
defined path
find
-keyword search from where
to search
Example: find / -name -file -number -size
-pattern mysql -print -file
Example: find path expression
Example: file /etc/init.d/mysqul like
right mous click an go to properties
What is your current path? echo $ PATH
put
(To
add a path) -use command line or file
Other more advanced linux commands:
>To see other machines using
mount command
mount 192.168.1.30:/texts
>Samba -Samba is a software suite that
enable linux machines to communicate with Windows machines. The location is
in /etc
/etc/samba/smb.conf
>mysql
(the database of linux)
to start the mysql -database
Example: /etc/init.d/mysquld start
>Modules in linux are similar to device drivers in Windows:
Commands involving modules:
lsmod -list modules
modinfo -d (to find information
about particular modules)
insmod (to load a
module)
To see partions: fdisk -l
>Tap up arrow to bring up previous commands
>Tap down arrow to bring forward commands
>Text Editors:
vi
- vi is a complex
editor (major learning curve needed so only experts need try)
pico -Pico is easier editor
Always usecommand pico with switch -w
Example: pico-w linux text
- so there won't be wordwrap which could create mistakes
>Commands Listed by Function:
File manipulation commands:
cat -Concatenate and display a file, for
viewing short text file only
chmod -Change the permissions mode of a file
warning: dangerous command
chown - Change the owner and/or group of a
file warning: dangerous command
diff - Display differences between pairs of
text files
grep - Search a file for a specific text
string. Important command used to filter a search
mv
Move or rename a file
-
warning: dangerous command
rm - Remove a file warning:
dangerous command
Display commands
date - Print the date and time
finger - Display information about a user
head - Display the first few lines of a file
less - Browse a text file
ls - List the contents of a directory
man - Display a reference manual page
Example: type: man copy to
understand copy command To advance each section, use spacebar; to quit, type
q
more - Display a text file
pwd - Display the working directory pathname
tail - Display the end of a file
who - Display who is on the system
Process commands:
exit
- Terminate a process
kill - Terminate or send a signal to a process
passwd - Create or change a password
ps - Display the status of a process
Example: ps -ef | grep sendmail -to see if sendmail is running
ps -aux -show all processes running
Internet commands:
telnet
(Connect
to a remote system using the Telnet protocol, dangerously open)
ssh (secure shell -secure remote access,
much safer)
>Email: Don't use mail
command-this
communicates directly with mail daemon
mail -checks mail mail <email address> send mail
-v (switch for verbose) to see what's here
Can use pico to view body of email
pine is a good, simple email
program
daemon is a continuously running
program like Windows programs that run in the background.
cntrl -l check mail with Pine mail program
>
This symbol is a directing command
> TAB
Use tab key to complete command
Use arrow keys:
^ Use up arrow to bring up previous command
v
Use down arrow to go down in history of
commands
history -to see history of commands-you can scroll through with up and down
arrows
Use
Cntl-alt-backspace
to get out of GUI quickly
Network commands:
>Use these commands to see your network setup:
ifconfig-a shows network setup but be
careful since ifconfig is also used to configure network setup
To see network files to determine how network is setup or
for network troubleshooting:
cat /etc/sysconfig/network
cat /etc/hosts
netstat
(To see status of network)
ssh (secure shell)
Used like telnet but more secure. You exchange keys.
ssh is NOT like FTP, It is NOT like
telnet.
It is "Secure Shell"
telnet
is does NOT run as a daemon. This is
why you will not find a PID to kill.
>Here are the steps to disable Telnet which you should disable unless you
want uninvited guests:
1. Edit the file; /etc/inetd.conf. Comment out (#) the line
containing the word "telnet". Save the file
2. Reboot
More Miscellaneous Notes:
>You can change from one shell to another.
Try Ctrl-F1, F2, F3, etc
You should be able to switch shells.
>You first do ps -aux | grep sendmail
Then you note down the PID number, which is in the first column
Then you do kill PID#
After you create a user, you have to type:
passwd
<username>
cat /var/log/messages | more -to see text of
file messages
dmesg | less
-to look at boot record, good for troubleshooting
Note: To find more linux information:
Linux CD has "how to" files as documents
http://www.linux.org
-has "how to" files