Sie sind auf Seite 1von 12

UNIX/Linux NOTES Page 1

UNIX/Linux Notes Professor: Michael P. Harris


v.20120902
UNIX is a multi-user, multi-tasking operating system originally developed at AT&T
Bell Laboratories. It provides utilities/programs for editing text, sending email,
preparing tables, performing calculations, Internet access, and many other specialized
functions that require separate application programs in other operating systems. One
of the key identifying features of UNIX/Linux is the standardized directory and file
structure the fiesystem.

Typical UNIX/Linux (root) /


Directory structure:

bin boot etc dev lib home lost+found mnt root sbin sys tmp usr sys

default
mike teri shea fd0 hda1 sda bin lib sbin share X
(Users home directories) (mounted volumes) (installed apps)

The most important versions of UNIX are releases that started at AT&T, the latest being
System V Release 4. Other important UNIX versions have come from the University of
California at Berkeley; called BSD. Microsofts Xenix, (before MSDOS) was an early
popular microcomputer implementation of UNIX based on AT&T release System V.
Major versions of UNIX include: SunOS, Solaris, SCO UNIX, AIX, HP/UX, and ULTRIX.

GNU Linux is currently the leading popular Open Source implementation of a UNIX
clone standard operating system. POSIX is the validation standard, set for UNIX-like
operating systems. Starting with Windows 2000; Windows XP, Vista and Windows 7 -all
have POSIX compliant kernels. Popular Linux OS distributions include: GNU, Ubuntu,
Fedora, Debian, Redhat, Knoppix, Puppy, DSL, Gentu, Cygwin, and TinyCore.

Since it started more than 50 years ago, UNIX has grown and changed in a different way
from most operating systems. Many early UNIX users were computer and scientific
professionals; more than a few of them extended UNIX by adding tools and functionality
to do what they needed. UNIX was also used to develop a lot of the powerful networking
systems that connect the world, such as the Internet. So, whereas most operating
systems were typically developed and controlled by one corporation, UNIX has been
developed through a collective effort. This has meant more versions than corporate
standard operating systems like MSDOS & Windows, but it has also helped to make UNIX
and Linux the flexible and incredibly powerful operating systems that they are today.

UNIX and its derivatives were not designed as "user-friendly" operating systems, in fact,
UNIX has, in the past, earned its label of "user-hostile." Most modern versions of UNIX
can also work with windowing system GUIs (Graphical User Interfaces) which allow each
user to have more than one "terminal" on a single display. The X Window System (called
X for short) is the most common UNIX window system. The appearance of X Windows
may vary between systems due to different window managers. Some of the most
common window managers are: mwm (Motif Window Manager), CDE (Common Desktop
Environment) and the new Linux windows shells: Gnome, KDE, LXDE, Unity, fluxbox,
flwm, FLTK, gtk2, iceWM, xfce and others.
UNIX/Linux NOTES Page 2

Getting Started

UNIX/Linux can be overwhelming at first with its barrage of details. To get started
though, all you need to do is master just a few details:

o How to Log in and out of your system.


o Understand the Shell and how to control the system with control characters.
o Learn the important UNIX/Linux specific directories and files (the filesystem).
o Manage UNIX/Linux files and directories, including listing, creating, copying,
printing and removing files, and moving in and out of directories.
o Work efficiently using UNIX/Linux redirection, pipes, filters, and multi-tasking.

Logging In

Before you can start using UNIX/Linux and its facilities, the Super User (root system
administrator), has to set up a user account for you with your login name, password,
and home directory. At many sites, there will be a whole network of UNIX/Linux
computers so you may also have to know the hostname of the computer that has your
account as well. When you login at your terminal you should see a message from the
UNIX/Linux OS that looks something like:

login:

Logging in is the process of making yourself known to the UNIX/Linux computer and
getting into your account. On remote systems you will need to run a remote login
program like telnet, ssh, rxvt, or rlogin. In this case your login session might look
similar to the following: (what you type is in bold)

ssh mercury.delmar.edu

Sun Solaris OS
mercury.delmar.edu: Solaris UNIX version 10.01.10

login: mpharris
Password: ********
Last login: Sat Sep 1 14:34 CST 2012, from mercury.delmar.edu

motd: The "crisis" of Today is the "joke" of Tomorrow

REMEMBER !!!
We will be shutting down at 4:30pm for system backups.

Wed Sep 5 12:24:48 CST 2012

[mpharris@mercury] ~ $_
UNIX/Linux NOTES Page 3

The UNIX/Linux Shell

Once you've logged into a UNIX computer, you're working with a program called the
shell. The shell interprets the commands you enter, runs the programs you've ask for,
and generally coordinates what happens between you and the UNIX/Linux operating
system. There are four shells in common use: the Bourne shell, Korn shell, Bash and C
shells. For the novice the differences are slight however some to run some software or
execute some program (especially shell scripts) you will need to know which shell you
are using (ask your system administrator). The only immediate difference you will see is
that the Bourne, Korn, and Bash shells prompt you with $_ while the C shell most often
uses %_ as the prompt. Certain keyboard commands (keystrokes) are interpreted by the
shell, these are commonly called control characters. The basic control characters are:

Ctrl-C or [DEL] Interrupt character (interrupts or cancel a command)


Ctrl-D Returns you to UNIX command level. Used to signal end of
input. ** Also logs you off of most UNIX systems
Ctrl-H or [BACKSPACE] Erase character to left of cursor
Ctrl-Q Restart output after paused by Ctrl-S
Ctrl-S Pauses output to the screen
Ctrl-U Erase the whole input line so you can start over

UNIX/Linux vs. MSDOS


The UNIX/Linux operating system has been around much longer than MSDOS. While
MSDOS owes much of its original heritage to a single-user microcomputer operating
system named CP/M, MSDOS evolved gaining more and more UNIX/Linux like capability.
MSDOS is not case sensitive meaning that commands can be typed in either upper or
lower case and MSDOS treats them all as if they were typed in UPPER CASE. UNIX/Linux
is case sensitive meaning that there is a difference between a command typed in upper
or lower case. The UNIX/Linux standard is that commands are typed in lower case. A
brief comparison of MSDOS and UNIX/Linux command equivalents follows:

CD pwd
CD DIRNAME cd dirname
CHKDSK fsck
COPY FILE1 FILE2 cp file1 file2
COPY FILE1 + FILE2 FILE3 cat file1 file2 >file3
COPY FILENAME PRN pr filename | lpr
DIR ls -hal
DIR /W ls -C
DIR /P ls -hal | more
DEL FILENAME rm filename
MD DIRNAME mkdir dirname
REN FILE1 FILE2 mv file1 file2
RD DIRNAME rmdir dirname
TYPE FILENAME cat filename
UNIX/Linux NOTES Page 4

File Access and Permissions

An important point to always remember is that in UNIX/Linux everything is a file. The


textbook definition of UNIX usually goes something like this...

UNIX - a multi-user/multi-tasking interactive operating system developed by AT&T.


UNIX has a directory structure that is tree-like with files containing all the information
that is part of the system.

Most people familiar with microcomputers and MSDOS are familiar with the tree-like
directory structure with directories, sub-directories and pathnames. But in UNIX/Linux
the directory structure and file system is the heart of the system. UNIX/Linux is also
device independent --therefore no duplication of commands is necessary for different
devices such as the screen, printer, or disk drives.

For example, UNIX/Linux always keeps the files in its directory structure in sorted order,
therefore to rename a file, is really moving that file within the directory structure. To
copy that file to another directory, to the screen, or to a floppy disk drive is the same
command because UNIX/Linux commands are device independent, everything is a file,
the destination directory, the screen, the auxiliary storage device are all files to UNIX.
This concept may take a little getting used to before all that is means sets in.

To log into a UNIX system your terminal must be described to the system. In the
directory /dev the system device files (files that contain the hardware interfacing
information UNIX/Linux needs) are contained. In addition, your terminal type is stored
in /etc/ttytype, your terminal speed in /etc/ttys, and your terminal setup and
capabilities data in /etc/termcap. The advantage of this system is obvious, if you
change your terminal or enhance its capabilities, your just edit the system files. In
addition you can have multiple definitions and settings for multiple different users.

Most UNIX/Linux executable commands (utilities) are kept in the /bin, /sbin, and
/usr/bin directories with miscellaneous system data files kept in the /etc directory.
UNIX/Linux commands are usually short and terse and most always in lower case. UNIX
filenames may include A-Z, a-z, 0-9, . and _. After UNIX/Linux boots from the kernel
code stored in the /boot or /sys directory, startup files in the /etc/init.d and
/etc/profile.d directories are executed. The /etc/profile global user login
configuration file and each users private ~/.profile login configuration file are
executed. These are the equivalent to the MSDOS CONFIG.SYS and AUTOEXEC.BAT files.
The system default setup information is stored in files in the /etc/default directory.

When users log into a UNIX/Linux system, their access is controlled by password and
access information stored in the /etc/passwd and /etc/group files. Once logged
in users are met by the users login message-of-the-day stored in the /etc/motd file
and then the global /etc/profile followed by the users personal startup and setup
commands are executed from their own private .profile file stored in their
/home/username login home directory.
UNIX/Linux NOTES Page 5

Once logged into a UNIX/Linux system, file access is controlled by the standard
UNIX/Linux permissions: r w x . The permission settings are for Read, Write (change),
eXecute, and permission denied (). The permissions are grouped into a sets of three;
rwxrwxrwx where the first three are the permissions for the user/owner of the file, the
second three are the permissions for members of the group assigned to the file and the
last three permissions are for all others who may wish access to the file. The command
chown is used to change the user/owner of the file. The command chgrp will change
the group assigned to the file. And the command chmod (for change access mode) will
change the file permissions.

As an example, assume the ls command (list directory) gave you the following
permission settings for the file /etc/motd... is rwxr-x--x
The first indicates this is a normal file. The next nine permission settings
would indicate that the owner (usually root) has Read, Write, and eXecute permissions
to the file. Those who have the assigned group access permissions can Read and
eXecute the file, all others may only eXecute the file.

When changing the access mode permissions to your files with the chmod command, you
have the options of typing: a, u, g, and o (for All, User/owner, Group, and Others) the
syntax is:
chmod -options filename
where options can include:
(1) a, u, g, o (2) +, -, or = and (3) r, w, x in any combination.

For example: chmod g+rx myfile would add Read and eXecute to the group portion of
the permission settings.

Alternate Input / Output, Piping, and Redirection

The Unix/Linux commands for redirecting Input and Output are:

> redirect output < redirect input


>> redirect output append << redirect input (here)
| pipe (output into input) tee split output into two streams

For example: who | sort > wholist

would execute the who command (generate a list of who is currently logged on to the
system) and pipe the output into the input of the sort command (alphabetize) and
then the sorted list would be redirected/written to the file wholist.

And with... banner < wholist >> register

the contents of the file wholist is fed into the command banner (which generates
large bannerized letters) and add this output to the end of the file register.
UNIX/Linux NOTES Page 6

UNIX/Linux Directory Guide


Typical UNIX/Linux (root) /
Directory structure:

bin boot etc dev lib home lost+found mnt root sbin sys tmp usr sys

default
mike teri shea fd0 hda1 sda bin lib sbin share X
(Users home directories) (mounted volumes) (installed apps)

/ UNIX/Linux root directory

/bin, /usr/bin UNIX/Linux binaries (commands/utilities)

/boot UNIX/Linux file system boot loader programs

/etc System configuration data files

/etc/default System default setup files

/dev Peripheral device control (driver) files

/home Users personal directories (contains user login directories)

/lib, /usr/lib Libraries for the 'C' compiler

/lost+found Depository for misplaced files

/mnt Directory containing empty directories to mount file systems

/proc System processes control files

/root The Super User (root) login directory

/sbin, /usr/sbin Administration binaries (commands) files

/sys Code for UNIX kernel (operating system)

/tmp Temporary files (may be auto deleted)

/usr/share Shared user files and installed application packages

/usr/share/man Online manuals for commands and files

/var/spool Print spooler master directory


UNIX/Linux NOTES Page 7

UNIX/Linux File Guide


. Name of current directory

.. Name of current directory's parent

~/.profile Set up environment at login (user personal startup file)

/etc/bashrc Bash restart cold (e.g. cold start configuration file)

/etc/dircolors Configuration file for the dircolors utility (command)

/etc/fstab Log/table of mounted filesystems

/etc/group Designate user group 'names'

/etc/init.d/* Directory of system initialization and startup files

/etc/motd Message Of The Day -login message for users

/etc/passwd Defined system users and access information

/etc/printcap Define standard printer setup information and capabilities

/etc/profile User set up environment at login (global startup file)

/profile.d/*.sh Directory of user/application shell script startup files (*.sh)

/etc/shells List of available login shells (ex. sh, bash, ksh, )

/etc/termcap Define standard terminal setup information and capabilities

Sample UNIX/Linux /home directory with subdirectories:


/

home

adam betty edward mark

demo1 memo etc letter util fax pgms news bin fax make
demo2
mm1 let1 fax1 jan mod1.c
mm2 let2 fax2 feb mod2.c
let3 mar

All users have a personal .profile or .bash_profile in /home/username/.profile


UNIX/Linux NOTES Page 8

Unix/Linux Commands: Prof. Michael P. Harris, CCNA, CCAI


(a working command set) ITSC 1358 Unix/Linux System Admin.

[, [[ Alias for the test boolean expression command. [[ is an enhanced test.


(( Enhanced form of the let Integer math expression command.
adduser, useradd Used by root to add user to system. Usage: adduser userid
alias, unalias Assign name to specified command list. e.g. create a macro command
at Execute a shell script at specified time. Usage: at [-f] file time
atq, atrm atq shows, and atrm removes, pending jobs queued by at.
awk, gawk, nawk Search for and process patterns in a file. A shell scripting language.
banner Print banner to standard output. Usage: banner [option] characters
bash Bourne Again SHell. This is the default shell in most Linux installations.
busybox Multi-call command library acts like the command name used to call it.
bzip, bzip2 Compress files with an algorithm different from gzip. See also: lzma
bunzip, bunzip2 Uncompress files compressed with bzip. See also: gzip
cc, c++ Invoke the C and C++ program compilers. See also: gcc, g++
cal Display a 12-month or a one-month calendar. Usage: cal [month] year
cat Concatenate/combine stdin to stdout. Read or display files.
cd Change working Directory. Usage: cd path, cd, cd ~, cd .., cd
cfdisk Similar to fdisk, but menu-driven, create/edit partitions. See: fsck
chmod Set permissions (access modes) for files or directories. See also: umask
chgrp Change the group associated with a file. Usage: chgrp [-R] group files
chown Change the user/ownership of a file. Usage: chown [-R] userid files
chsh Change default shell. See also: sh, bash, ksh, csh, tcsh, zsh
clear Clear screen command. (tput clear)
cmp Compares two text files for differences. See also: diff, diff3, uniq
comm Compare sorted text files. See also: sort, diff, diff3, uniq
compress Compress (uncompress) files to the older .Z file format. See: gzip, zcat
cp Copy one or more files. Usage: cp [-r][-p] source target[directory]
crontab Schedule command(s) to run at regularly specified times. See also: at
csh The C shell. See also: bash, ksh, sh, csh, tcsh, bsh, ash, and zsh
cut Select characters or TABed fields from files/lines of input. See: paste
date Display or set date and time. Not related to time. Usage: date [date]
df Display disk free space and disk capacity on physical devices. See also: du
diff Display differences between two files. See also: diff3, uniq
UNIX/Linux NOTES Page 9

diff3 Compare three files and reports on differences. See also: uniq
du Display information on disk usage and file sizes. ex. du / bh | less
echo Display text/arguments to standard output. ex. echo $PATH, echo ~
emacs A very powerful screen oriented text editor. See also: vi, vim, nano
env, printenv Display, or set a new value to, the environmental setting variables.
eval Scan and evaluate the command line. See also: let, expr, test
ex An interactive command-based editor. See also: vim, vim, sed
exec System call which creates a subshell to execute a binary or a script.
exit exit (terminate) a command-line shell. Also to logout of a shell.
expand Convert tabs in files to spaces and write to standard output.
export Place the value of a variable in the set environment (make it global).
expr Evaluate an expression and displays the result. See: let, eval, test
false Null command that returns an unsuccessful exit status. See also: true
fc View, edit, execute commands from the command history. See: history
fdisk Utility used to partition hard drives. See: cfdisk Usage: fdisk device
file Display the classification of a file(s) based on the type of data within.
find Find files matching a large variety of search criteria. ex. find . type d
finger Display information about a specified userid or userids. See also: pinky
fmt Simple text formatting utility. Make lines the same length. See also: pr
fold Break lines of text files so they are no wider than a given length. See: fmt
free Display used/free system memory along with other useful information.
fsck File System Check and Repair. Filesystem diagnostics.
ftp File Transfer (Protocol) over the network. See also: tftp, scp, wget
gcc, g++ Invoke the GNU C or C++ compiler. See also: cc, c++
grep, fgrep, egrep Find a string or pattern within a file(s). Usage: grep pattern [files]
groups Show which groups you are a member of. See also: id, whoami
grub GNU GRand Unified Bootloader. Boot multiple OSs. See also: lilo
gzip, gunzip Utility used to compress or uncompress files. (.gz, .tar.gz, or .tgz)
halt Shut down system as root, without reboot, immediately. See: shutdown
hash Remember the location of commands in the search path.
head Display the first part (10 lines default) of a file. See also: tail
history View and manipulate the shell command history list. See also: fc
host Look up host names using a domain server. See also: hostname, uname
hostname Display/set the hostname (computername). $HOSTNAME /etc/HOSTNAME
UNIX/Linux NOTES Page 10

id Display your userid and groupid. See also: logname, groups, whoami
inetd Daemon which starts other daemons on demand. See: /etc/inetd.conf
ifconfig Display information on network interfaces that are currently active.
info Display system information. This is the GNU hypertext reader. See: man
init Master process, runs at bootup, executes commands in: /etc/inittab
jobs Lists current running jobs/programs. See also: ps, pstree, top
kill Send a signal to terminate a job or process. ex. kill 9 pid
ksh Korn SHell. See also: bash, sh, ksh, csh, tcsh, and zsh
ldd List/locate the shared libraries on which a given executable depends.
less Improved more command. Display text files, many options. See: more
let Evaluate a integer numeric expression. See also: (( )), eval, test
lilo LInux LOader, install a boot loader on a device boot sector. See: grub
ln, ln s Create a link to a file. Create hard links and/or s symbolic links.
locate Find files that that match a pattern; easier syntax than find. (updatedb)
login Login to the Unix/Linux operating system. See also: ssh, logout
logname Consult /etc/utmp for user's login name. See also: who, id, hostname
logout Execute logout as individual user and bring up the login: prompt. ^D
lpr Send file to be printed, used with pr. See also: lpq, lprm, /var/spool
lpq Printer queue, show print jobs that are waiting to be printed.
lprm Cancel a print job from a print queue.
ls List directory contents. ls hal, ls FAC, ls color, ls FRAC
make Keep a set of programs current, works by executing the script makefile.
makewhatis Create database used by apropose and whatis. /usr/share/man/whatis
man, help Display information from online the Unix reference manual. See: whatis
mc Midnight Commander file manager and visual shell. Also: mcedit, mcview
mkdir Make (create) a directory. See also: cd, rmdir, rm rd, mv
mkfs Make (create) a File System format a device or partition. See: dd
mkswap Create a Linux swap space on a specified hard disk partition. See: swapon
more List file contents, stopping after each full screen. Q exits. See: less
mount, umount Mount a partition as a directory in the filesystem. See: /etc/fstab
mv Move (rename) files and directories. See also: cp, cpio, dd
nice Set the runtime priority of a program. Usage: nice program_name
od Octal Dump display contents of a file in octal/hex. See: hd, hexdump
passwd Change your login password. See: /etc/passwd
UNIX/Linux NOTES Page 11

paste Join corresponding lines from files. See also: cut, split, join
pathchk Determine the validity and portability of filenames. See also: cygcheck
perl Practical Extraction & Report Language. Scripting language. See: python
ping Check if an Internet computer is responding (online). See: traceroute
pr Paginate files for printing; used with lpr. See also: fold, fmt
ps Displays processes status. Usage: ps -a See also: top, jobs, top, kill
pstree Display processes in the form of a parent/child tree structure. See: ps
pwd Print absolute path of the Working (current) Directory. $PWD, $OLDPWD
python Interpreted, interactive, object-oriented scripting language. See: perl
read Read a line from standard input into the variable $REPLY. See: echo
rm Remove files or [-r] directories. Usage: rm [-r][-rd] filepath
rmdir Remove empty directories. See also: rm r
rmuser Remove user account from the filesystem. See also: userdel, adduser
route Show the routing table entries. Usage: route [-n]
rpm Invoke the Redhat Package Manager in command line mode. See: yum
rxvt A terminal program, like xterm, with less features and uses less memory.
sed Edit a file stream (redirect). Also a tool for processing text files.
set, setenv Set or display values of shell variables. See also: env, export, declare
sh The standard Bourne SHell. See also: bash, ksh, csh, tcsh, and zsh
shutdown Reboot/shutdown system as root. Usage: shutdown [-h] [-r] minutes
sleep Create a process that sleeps for specified interval. See also: wait
sort Sort and/or merge files. See also: uniq, diff, cut, paste, join, split
source Run a shell script in the current shell/environment. Alias: . (dot)
split Split a file into specified number of segments. See also: csplit, cut
ssh Secure remote login SHell. See also: telnet, rlogin, rsh, xterm
startx Front-end to xinit (xterm), start X-clients/X-server window managers.
su Simulate User -login as another user, including root (Super User).
sudo Super User DO, allow users root permission to run tasks. /etc/sudoers
swapon, swapoff Enable or disable swap disk (file) usage. See also: mkswap
symlinks Provide a list of, and information about, symbolic links. See: ln -s
sync Write memory buffers to physical devices for safe removal. See: rsync
tail Display the last part (default 10 lines) of a file. See also: head, tac
tar Tape ARchive, file compression/archiving utility. tar [xcvf] file.tar
tcsh Extended version of the C-shell, csh. See also: bash, ksh, sh, and csh
UNIX/Linux NOTES Page 12

tee Copy standard input to standard output and to one or more files. Also |
telnet Remote login over the network. See also: ssh, rsh, rlogin, xterm
test Evaluate a boolean expression or compares arguments. Alias: [ and [[
tftp User interface to TFTP (trivial FTP) protocol. See also: ftp, scp, wget
time Display run times for current shell programs and processes. See: uptime
top Dynamically display process status. See also: ps, pstree, jobs, kill
touch Create an empty file or update access and modification times of a file.
tr TRanslation utility, replace specified characters in a text file.
true A null command that returns a successful exit status. See: false
tty Show information that represents your terminal and terminal pathname.
umask Establish the file-creation permissions mask. Usage: umask xyz
umount Finish writing to a device and unmount it from the active filesystem.
uname Displays information about the UNIX OS system. Usage: uname [-a]
uniq Display lines of a file that are unique. See also: diff, cmp, comm
unzip Uncompress files compressed with zip, compatible with DOS PKzip.
updatedb Script used to build/update the database used by locate.
uptime Show the system up time, number of users, and average load. See: time
userdel Remove user account (as root). The user's home directory is not deleted.
users Prints list of users on the system. See also: who, groups /etc/passwd
vdir Variant of the ls command. Defaults to printing a long listing.
vi Standard screen oriented VIsual editor. See: vim, view, nano, mcedit
view vi/vim in read-only mode. See also: less, mcview
vim Vi IMproved, vi editor. See also: vi, view, nano, and mcedit
wait Wait for a background process to terminate. See also: sleep
wc Word Count, display number of lines, words and/or characters in a file.
wget File transfer utility using HTTP, FTP, and other Internet protocols.
whatis Display a one-line summary about a specified command. See also: man
whereis Find utilities/files from standard locations. See: makewhatis, locate
which Find utilities/commands using the search path. See: locate, whereis
who Display information about currently logged in users. See also: users, id
whoami, who am i Display information about the userid that is currently logged in. See: id
xterm Start an X-Window terminal session. See also: rxvt
zcat Read to stdout files that have been compressed with gzip or compress.
zip, unzip Zip compress/uncompress utility compatible with DOS PKzip. See: gzip