Sunteți pe pagina 1din 62

Unix Fundamentals

K. Chandra Sekhar Tata Consultancy Services

Unix Fundamentals

Unix Fundamentals

CLI - Command Line Interface

Unix Fundamentals

Unix Fundamentals
CLI - Command Line Interface GUI - Graphical User Interface (Gooey)

Unix Fundamentals

Unix Fundamentals
CLI - Command Line Interface GUI - Graphical User Interface (Gooey)

Unix is a text-based interface between you and your computer. It is an operating system, like DOS or the MacOS, but much more capable.
Unix Fundamentals

Unix Fundamentals

CLI - Command Line Interface


Unix
DOS

GUI - Graphical User Interface (Gooey)


X-Windows
Windows95 MacOS OS/2

Unix Fundamentals

Unix Fundamentals
Developed at Bell Laboratories in the 1970s. Derived from Multix operating system. Later changed to C-based core operating system. Portability of C caused Unixs fast spread. Multi-user, multi-tasking operating system. Network-ready operating system.

Unix Fundamentals

Logging on to Unix

You must identify yourself (log in) to a Unix system.

FreeBSD (scnc.k12.mi.us) (ttypX) login:

Enter your user ID, press [ENTER], type in the default password (it will not display), press [ENTER].

Unix Fundamentals

Getting Started with Unix


Last login: Mon Oct 2 20:32:09 from 313cc-pc-1.cl.ms Copyright (c) 1980, 1983, 1986, 1988, 1990, 1991, 1993, 1994 The Regents of the University of California. All rights reserved. FreeBSD 2.0.5-RELEASE (GENERIC) #0: Sat Jun 10 10:46:56 1995 Welcome to FreeBSD! You have new mail.

Once you login correctly, Unix runs some scripts and starts your shell, or your command interpreter.

Unix Fundamentals

The Unix Prompt


The prompt is displayed by your shell. Different shells and different systems have different prompts. Two common prompts are $ and #.

A prompt (plus a cursor) tells you that the system is ready for your commands. Your prompt can be changed.

Unix Fundamentals

Some Introductory Commands

Unix is case sensitive!

who who is logged on whoami who am I logged on as (short form) who am I who am I logged on as (long form) w what is everyone doing?
Unix Fundamentals

Getting Help

Check the manual pages!

man man - help on the man command man who - help with the who command man -k mail - checks all man pages for keyword mail
Unix Fundamentals

Changing your Password


passwd - change my password
Only one person at a time! Pick a combination of letters and numbers that cannot be associated with you. Use 6 to 8 characters. Vary (and later match) case. Avoid dictionary words.

Unix Fundamentals

Changing your Password


Password must be exactly duplicated. Do not write it down next to your user ID. Memorize it. Change it on a regular basis. Do not repeat passwords. Use different passwords for different systems.

Unix Fundamentals

The Unix Shell

The shell is your interface with the Unix system.


There are different kinds of shells:
sh

- Bourne Shell ksh - Korn Shell csh - C Shell tcsh - Extended C Shell
Unix Fundamentals

The Unix Kernel

The kernel is the core operating system.


There two basic varieties of Unix:
BSD

Unix 4.3 - popular with universities AT&T Unix System V - popular with businesses

There are many releases of each variety.

Unix Fundamentals

The Unix System Architecture


The shell allows you to use applications and commands to interface with the kernel. The kernel directly controls the hardware. You cannot talk directly with the kernel. You or your applications must use system calls to talk to the kernel.

Unix Fundamentals

The Unix System Architecture


Applications Shells
System

Vendor Tools

Libraries

Kernel
HARDWARE

Calls

Compilers Unix Commands


Unix Fundamentals

The Unix File System


The Unix File System can be looked at as an upside-down tree with the roots at the top and the trunk and branches at the bottom.

Unix Fundamentals

The Unix File System


/
In our example there are three directories in root.
/ is the root directory.

home

etc

tmp

vanhoose

henry

username

The home directory contains directories of all users on a system.

public

private

.tin
Each user can create and administer his/her own directories, subdirectories and files.

Unix Fundamentals

The Unix File System


Hierarchical File System. Directories can be embedded. In reality, everything in Unix is a file. Directories are just files with lists of files in them.

pwd - print (current) working directory


Unix Fundamentals

Finding Yourself or a File


The command pwd tells you where you are in the file hierarchy. It gives you the absolute path to your location. Absolute vs. relative paths:

An

Unix Fundamentals

absolute path identifies where you or a file is located in relation to the root directory. A relative path identifies where a file is located relative to your current working directory.

Absolute Path Names

An absolute path name always starts with a /.


It

means, from the root directory, this is where the file is. It is the most reliable way of identifying files.

/home/ /home/username/ /etc/passwd /bin/ls

Unix Fundamentals

Relative Path Names

A relative pathname starts from your current working directory.


It

means, from my current directory, this is where the file is. Can start with a directory or file name, . or .. . Is not as reliable, as your current working directory may change.

Unix Fundamentals

Identifying Files and Directories


/
vanhoose is my home directory. Its absolute path name is /home/vanhoose/. home / is the root directory.

etc

tmp
/home/vanhoose/ is also known as ~ or ~vanhoose.

vanhoose

henry

username

public

private

.tin

/home/henry/ is also known to me as ~henry.

/home/vanhoose/.tin/ can also be called ~/.tin. From ~henry it could also be ~vanhoose/.tin, or, using a relative path name, as ../vanhoose/.tin.
Unix Fundamentals

Pathname Examples
. - current directory
.. - parent directory (one directory up) .tin/tinrc - the tinrc file in the .tin subdirectory of the current directory /etc/passwd - the password file in the etc directory of the root directory
Unix Fundamentals

Pathname Examples
/home/henry/.cshrc - user henrys .cshrc file
../../etc/passwd - go up two directories, then find the password file in the etc directory

~henry/.login - user henrys .login file

Unix Fundamentals

Moving Through the Hierarchy


pwd ls print (current) working directory list files in directory (dir/w) -a list all files in directory -l print a long list of files (dir) -la print a long list of all files cd change directory

Unix Fundamentals

Changing Directories
cd cd cd cd cd cd cd change directory (home) .. go to parent directory / go to the root directory ~ go to my home directory ~user go to users home directory /etc go to the etc directory from root ../etc go to the etc directory in my parent directory

Unix Fundamentals

Some Common Directories


/bin /dev /etc /home /tmp /usr binary executable files special device files administrative files user home directories temporary files special user files or home directories

Unix Fundamentals

Users and Groups


There are many users and few groups. One user can belong to multiple groups, but has one primary (default) group. One special user: root (the system administrator). Group examples:

wheel

(priviledged users) staff (regular users)


Unix Fundamentals

Listing Files and Directories


1 3 1 2 drwxr-xr-x drwxr-xr-x -rw-r--r--rw-r--r-8 160 1 1 vanhoose root vanhoose vanhoose msu wheel msu msu 512 3072 159 1351 Oct Oct Oct Oct 3 2 2 2 14:12 13:43 15:21 15:21 ./ ../ .addressbook .addressbook.lu

ls -la show expanded list of all files


Unix Fundamentals

Listing Files and Directories


1 drwxr-xr-x 180 root wheel 512 2 -rw-r--r-1 vanhoose msu 1314 Oct 1 Oct 3 ../ file

. this (current working) directory .. the parent directory

Unix Fundamentals

Listing Files and Directories


BLOCK SIZE # DIRECTORIES GROUP FILE SIZE Oct 1 Oct 3 ../ file 1 drwxr-xr-x 180 root wheel 512 2 -rw-r--r-1 vanhoose msu 1314

FILE TYPE

PERMISSIONS OWNER

MODIFY DATE

FILE NAME

The block size is the number of blocks the file takes up on the file system medium. The minimum is one.

Unix Fundamentals

Listing Files and Directories


BLOCK SIZE # DIRECTORIES GROUP FILE SIZE Oct 1 Oct 3 ../ file 1 drwxr-xr-x 180 root wheel 512 2 -rw-r--r-1 vanhoose msu 1314

FILE TYPE

PERMISSIONS OWNER

MODIFY DATE

FILE NAME

The file type can be d for a directory, - for a regular file, l for a link, etc.

Unix Fundamentals

Listing Files and Directories


BLOCK SIZE # DIRECTORIES GROUP FILE SIZE Oct 1 Oct 3 ../ file 1 drwxr-xr-x 180 root wheel 512 2 -rw-r--r-1 vanhoose msu 1314

FILE TYPE

PERMISSIONS OWNER

MODIFY DATE

FILE NAME

The permission settings show who can access the file/directory and in what ways.

Unix Fundamentals

Listing Files and Directories


BLOCK SIZE # DIRECTORIES GROUP FILE SIZE Oct 1 Oct 3 ../ file 1 drwxr-xr-x 180 root wheel 512 2 -rw-r--r-1 vanhoose msu 1314

FILE TYPE

PERMISSIONS OWNER

MODIFY DATE

FILE NAME

The number of directories entry shows how many directories exist in that particular directory or file. Files have only one (..).

Unix Fundamentals

Listing Files and Directories


BLOCK SIZE # DIRECTORIES GROUP FILE SIZE Oct 1 Oct 3 ../ file 1 drwxr-xr-x 180 root wheel 512 2 -rw-r--r-1 vanhoose msu 1314

FILE TYPE

PERMISSIONS OWNER

MODIFY DATE

FILE NAME

The owner is usually the user that created the file/directory. He/she can control the permissions for that file/directory.

Unix Fundamentals

Listing Files and Directories


BLOCK SIZE # DIRECTORIES GROUP FILE SIZE Oct 1 Oct 3 ../ file 1 drwxr-xr-x 180 root wheel 512 2 -rw-r--r-1 vanhoose msu 1314

FILE TYPE

PERMISSIONS OWNER

MODIFY DATE

FILE NAME

The group identifies the people that have priority access to a file/directory, and is usually the owners default group.

Unix Fundamentals

Listing Files and Directories


BLOCK SIZE # DIRECTORIES GROUP FILE SIZE Oct 1 Oct 3 ../ file 1 drwxr-xr-x 180 root wheel 512 2 -rw-r--r-1 vanhoose msu 1314

FILE TYPE

PERMISSIONS OWNER

MODIFY DATE

FILE NAME

The file size is the actual size of the file/directory in bytes.

Unix Fundamentals

Listing Files and Directories


BLOCK SIZE # DIRECTORIES GROUP FILE SIZE Oct 1 Oct 3 ../ file 1 drwxr-xr-x 180 root wheel 512 2 -rw-r--r-1 vanhoose msu 1314

FILE TYPE

PERMISSIONS OWNER

MODIFY DATE

FILE NAME

The modify date shows the date that this file/directory was created or last modified.

Unix Fundamentals

Listing Files and Directories


BLOCK SIZE # DIRECTORIES GROUP FILE SIZE Oct 1 Oct 3 ../ file 1 drwxr-xr-x 180 root wheel 512 2 -rw-r--r-1 vanhoose msu 1314

FILE TYPE

PERMISSIONS OWNER

MODIFY DATE

FILE NAME

The file name is the identifier of this file/directory in the current directory.

Unix Fundamentals

Creating, Copying and Moving

Use an editor to create files.


vi pico emacs

mkdir make new directory (md) cp copy file or directory (-r) (copy) mv move or rename file or directory (-r)
Unix Fundamentals

Removing Files and Directories


rm remove file (del) rmdir remove directory (rd)

Be careful when removing items!

Unix Fundamentals

Unix Permissions

Permission Levels
User

(owner) (u) Group (wheel, staff, daemon, etc.) (g) World (guest, anonymous and all other users) (o)

Permission Settings
Read

(r) Write (w) Execute (x)


Unix Fundamentals

Permission Settings

If you can read a file, you can see all of its contents.
If you can write to a file, you can change its contents. If you can execute a file, you can run it as a script or program.

Unix Fundamentals

Permission Settings

If you can read a directory, you can see the files in it.
If you can write to a directory, you can add and remove files from it (regardless of file permissions).

If you can execute a directory, you can change (cd) to it.

Unix Fundamentals

Permission Settings
Computer people love octal (base 8) numbers. Permission settings use octal numbers.

=4 w = 2 x = 1 none = 0

Unix Fundamentals

Permission Settings

These numbers are additive.


rwx

= 7 (4 + 2 + 1) rx = 5 (4 + 1) r = 4 none = 0

Each permission level has an octal number that represents its access priviledges for a particular file.

Unix Fundamentals

Permission Settings

Access values for one particular file, then, can be represented by three octal numbers:
one

for the owner/user (u) one for the group (g) one for everyone else (o)

751, for example, means:


The

owner/user (u) can rwx (u=rwx) His/her group (g) can rx (g=rx) Anyone else (o) can x (o=x)
Unix Fundamentals

Changing Permissions
chmod chmod chmod chmod chmod chmod
755 . 541 . u=rw . u+x . o-w .

change mode (permissions) u=rwx, g=rx, o=rx u=rx, g=r, o=x u=6 (4 + 2)* add user execute permission** remove other write permission**

* u does not have x permissions ** other settings (go & ug resp.) remain unchanged
Unix Fundamentals

Listing Permissions
1 drwxr-xr-x 180 root wheel 512 2 -rw-r--r-1 vanhoose msu 1314 u g o Oct 1 Oct 3 ../ file

In the above ls -la extract, for file,


user has read/write permissions (u=rw); group has read-only permissions (g=r); and, others have read-only permissions (o=r).

Unix Fundamentals

Viewing Files

Must have read permissions...

cat - concatenate and print more - page file to screen pr - print file to screen od - octal dump file to screen ls | more - page dir. to screen
Unix Fundamentals

Your Home Directory


.addressbook - pine addresses .cshrc - shell script file .forward - e-mail forwarding file .login - login script file .logout - logout script file .newsrc - tin resource file .plan - finger resource file
Unix Fundamentals

Your Home Directory


.profile - finger resource file .pinerc - pine resource file .signature - e-mail and news file .tin/ - tin resource directory mail/ - e-mail folder directory News/ - saved news files web/ - your pulic web directory
Unix Fundamentals

The Virtual Terminal


You log on to Unix via a virtual terminal. Your terminal session is mediated by:

system-wide

scripts your shell and shell scripts your kernel your terminal emulation

Unix Fundamentals

Shell Scripts

There are several important script files:


/etc/csh.cshrc - system-wide shell script /etc/csh.login - system-wide login script /etc/csh.logout - system-wide logout script ~/.cshrc - user shell script ~/.login - user login script ~/.logout - user logout script

Unix Fundamentals

Terminal Emulation

Terminal emulation is negotiated between your client machine and the Unix server.
Your virtual terminal ID (e.g., ttyp1) and type (e.g., vt100) are negotiated when you first connect and login.

Unix Fundamentals

Terminal Emulation
who am i - identifies your terminal (a.k.a. teletype) ID. echo $TERM - identifies your login terminal type.

Unix Fundamentals

Special Control Keys


[CTRL]-c [CTRL]-d [CTRL]-g [CTRL]-h [CTRL]-l [CTRL]-u [CTRL]-w [CTRL]-z
Unix Fundamentals

interrupt halt or EOF bell backspace redraw screen kill line kill word suspend

The stty Command


stty - set terminal type options stty -a - list all terminal settings stty intr '^c' erase '^?' kill '^u'
interrupt

key is now [CTRL]-c erase key is now [CTRL]-? kill line key is now [CTRL]-u

Unix Fundamentals

Leaving Unix

To exit from Unix and/or your current shell, type exit or [CTRL]-d at the prompt. Make sure you always log completely out. Leaving yourself logged in is a serious security hole.

Unix Fundamentals

Congratulations!

You know know enough Unix to be dangerous!

Unix Fundamentals

S-ar putea să vă placă și