Getting started with *nix


This is a quick and by no means comprehensive reference for handy little tid bits you can use in red hat linux, and various other unices.  For more information on any command, dont forget to use 'man' and 'info' pages.

Quick Command Reference:


DOS/WINDOWS and Linux Compared
DOS Command
Linux Command
Purpose
CD
cd
Change directory
DIR
ls
List the contents of a directory
CD
pwd
shows your full location in the filesystem
MOVE
mv
Move files
COPY
cp
Copy files
DEL
rm
Remove files
DELTREE
rm -r
Recursive delete, wipe directory and its contents, use rmdir for empty dir
REN
mv, rename
Rename files
EDIT
pico/vim/vi/nano
Edits files with simple text editor
TYPE
less or more or cat
View files


User Management and Permission Commands
Command
Function
Basic Syntax
su
Login as another user account
su -[user]
adduser
Add a user account(only availble to root)
adduser <account name>
passwd
Change a user's password
passwd <account>
chmod
Change permissions for files and folders
chmod <permissions> <target>
chown
Change ownership of files and folders
chown <user>:<group> <target>


Process Management
Command
Function
ps
Display processes currently running
ps aux
More informative ps display
top
Automatically refreshing list of running processes
kill <process id>
kill a processs with teh specified process id
kill -9 <process id> kill a stubborn process


Installing Software (redhat and mandrake packages only)
Command
Function
rpm -ivh <pakcage file>
Install a new package
rpm -uvh <package file>
Upgrade a package
rpm -e <installed package>
uninstall a package
rpm -q <package>
Find out if a particular package is installed
rpm -q --requires <package file>
Find out a packages dependencies
rpm -qlp <package>
Lists all the files stored within a package
rpm -qix <package>
read a description of the installed package
rpm -qixp <package file>
read a description of an uninstalled package
rpm -v <installed package>
verify an installed package

Commands for Common tasks
Command
Function
Syntax
locate
Locates a specific file
locate <file name>
ln
Creates a link to another file
ln -s <target> <link name>
xhost
Add/Remove X access to your dislpay
xhost +[host name]
du
Shows disk usage of a file or directory
du <directory>
df
Shows free disk space on mounted filesystems
df
tar
Create and extracts the contents of .tar and .tar.gz files
tar -zxvf <filename.tar.gz>
Extracts archive
tar -cxvf <source> <filename.tar.gz>
creates archive
tail
shows the bottem lines of a text file.  Generally used with log fils to show the most recent data
tail <options> <filename>
reboot
Reboots the machine
reboot
shutdown
Shuts down the machine
shutdown <options> <time>


Popular Configuration files
Application or Service
Configuration file
Description
Initiate Changes
Samba
/etc/samba/smb.conf
<redhat>
/etc/smb.conf
<mandrake>
Configures winows file and print sharing using the SMB protocol.  SAmba allwos linux and windows machines to share files, pirnters, accounf information and more.
Service samba restart
LILO
/etc/lilo.conf
The linux loader.  LILO is a samll program that launches when you start yoru machine, and allows your to choose between different operating systems, as well as different linux kernels
lilo
Filesystems
/etc/fstab
Teh filesystem table stores teh details of all your automatically mounted filesystems, as well as default optoins for temporary filesystems.
No action needed unless non-Linux filesystem permissions have been modified, when a user should log out and back in again
Modules
/etc/modules.conf
Specifids which modules to laod at boot time
reboot
X
/etc/X11/X86Config
Specifies your grahics card and montor, display size, display resolution and colour depth.
Log out and restart X
Default runlevel
/etc/inittab
There are six different runlevels on linux.  Each runlevel changes teh services that are running.  For example, runlevel 5 has a GUI login, runlevel 3 is console based, and runlevel 1 only a small set of servies, and is used fro troubleshooting.  Edit the initdefault line to specify which runlevel to boot into.
Changes will be seen on reboot.


Bash Scripting:

built in shell variables:

$*
All of the script arguments starting from first
$#
The number of positional parameters
$-
current option flags
$$
Process ID of the Shell
$!
Process ID of the most recently executed background process
$0
Name of the shell
$_
The absolute filename of the shell script
$1,$2..$9
First, second through ninth arguments passed to the script

to see script executing line by line, try bash -x <scriptname>

Built in tests:

String Tests

[-n] STRING
the length of STRING is non-zero
[-z] STRING
the length of STRING is zero
STRING1 = STRING2
The strings are identical
STRING1 != STRING2
the Strings are not identical


Numerical Tests

NUM1 -eq NUM2
NUM1 is equal to NUM2
NUM1 -ge NUM2
NUM1 is greater or equal to NUM2
NUM1 -gt NUM2
NUM1 is greater than NUM2
NUM1 -le NUM2
NUM1 is less than NUM2
NUM1 -ne NUM2
NUM1 is not equal to NUM2


File Tests

FILE1 -nt FILE2
FILE1 is newer (modification date) than FILE2
FILE1 -ot FILE2
FILE1 is older than FILE2
-e FILE
FILE exists
-d FILE
FILE exists and is a directory
-f FILE
FILE exists adn is a regular file
Try man test for more tests


User Environment:


You can do nifty things with your dot files, for example, if you want to change your prompt, you can modify the PS1 variable in your .bashrc (if using bash that is) file.  Some control characters are as follows:

Control Characters:

\a
A bell character
\d
The date: 'Weekday Month Date'
\e
An escape character
\h
The hostname, upto the first .
\H
The hostname
\n
The newline
\r
A carriage return
\s
The name of the shell
\t
the time in 24-hour HH:MM:SS format
\T
The time in 12-hour HH:MM:SS format
\@
The time in 12-hour am/pm format
\u
Username
\v
Bash Version
\V
Bash release number
\w
Current work directory
\W
BAsename of the current work directory
\!
History number of the current command
\#
Command number of the current command
\$
# for uid=0, else $
\\
A backslash
\[
Begin an escape sequence
\]
End an escape sequence

Colour Escape Sequences

Black
\[\033[0;30m\]
Red
\[\033[0;31m\]
Green
\[\033[0;32m\]
Brown
\[\033[0;33m\]
Blue
\[\033[0;34m\]
Purple
\[\033[0;35m\]
Cyan
\[\033[0;36m\]
Light Grey
\[\033[0;37m\]
Grey
\[\033[1;30m\]
Light Red
\[\033[1;31m\]
Light green
\[\033[1;32m\]
Light yellow
\[\033[1;33m\]
Light Blue
\[\033[1;34m\]
Light Purple
\[\033[1;35m\]
Light Cyan
\[\033[1;36m\]
White
\[\033[1;37m\]
Terminal Default
\[\033[0;0m\]
You can toggle the behaviour of the shell by setting and unsetting various shell options using the shopt command.  To see what options are set for you, type 'shopt'.  One handy non-default option is 'cdspell', you can enable it using: shopt -s cdspell

To see what other options do, look at man bash, and use '/' to search for each option you see outputed from shopt.


Extracted from the APC pocket book for linux (3rd edition + advanced) with my added comments.