+ All Categories
Home > Documents > Intro to Unix-1-2014 - Indiana University...

Intro to Unix-1-2014 - Indiana University...

Date post: 08-Sep-2018
Category:
Upload: hoangdung
View: 221 times
Download: 0 times
Share this document with a friend
188
Getting started with the Unix Operating System Unix Introduction
Transcript
Page 1: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Getting started with the Unix Operating System

Unix Introduction

Page 2: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

What is an Operating System?

Page 3: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

A computer Operating System, or

“OS”

Page 4: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

What is a computer operating system?

Page 5: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Where?

Page 6: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Insulation from hardware

Allocation of resources

Utility Functions (often blurring the line between OS and applications)

What does an OS provide?

Page 7: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

There are numerous past, present, and future storage technologies

Each of these requires unique procedures for getting data to and from the device.

But, it is unreasonable to expect each application to understand each device.

The problem

Page 8: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

The OS provides simple "abstract devices” for storage:

Random access (disks, solid state)

Sequential access (tapes)

Applications talk to the abstract devices, the OS translates and talks to the actual devices. The OS provides a layer of insulation from these details.

The solution

Page 9: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Insulation roles of the OS extends to most aspects of computer hardware, including

User interface devices

Network and communications

Memory

Expansion busses

Beyond storage

Page 10: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

OS is necessarily closely tied to particular hardware.

OS used to always be supplied by the hardware vendor.

OS-Hardware pairing

Page 11: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Insulation from hardware

Allocation of resources

Utility

What does an OS provide?

Page 12: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

The disk abstraction represents a disk as quantity of storage.

An application is insulated from the hardware details of exactly how the data are stored.

An application can read or write from any location in that quantity of storage.

About that “disk” abstraction…

Page 13: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

The disk abstraction provides no structure for data stored in the disk.

If multiple applications want to use the same disk, they must agree on a way to structure data.

The disk abstraction is a like file cabinet without file folders.

The problem

Page 14: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

An OS provides higher level abstractions than just devices. For data storage:

File — a named container for data

Directory — a named container for files

The solution

Page 15: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

An application manages data inside a file however it likes.

Things an application can do with a file:

create, open, seek, read, write, close, rename, remove.

The OS manages the storage of files on the disk for all applications.

Files and directories

Page 16: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

The OS arbitrates application access to all system resources.

CPUs

Memory

Input and output devices

Beyond storage

Page 17: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Insulation from hardware

Allocation of resources

Utility

What does an OS provide?

Page 18: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Insulation from hardware and allocation of resources are core OS features, but alone don’t make for a useful system. This does not provide for a user interface.

Practicality leads real-world OS's beyond the core functions.

The boundary between operating systems and applications is open to interpretation.

Gray areas at the edge

Page 19: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Insulation from hardware

Allocation of resources

Utility

What does an OS provide?

Page 20: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Layers of softwareOS and other software are often depicted as functional layers.

Software in one layer can only use services provided by the immediately lower layer.

Graphic from The Design of the Unix operating System by Maurice J. Bach, Prentice-Hall, 1986

Page 21: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Introduction to Unix

Page 22: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Logging In

• Unix is a multi-user operating system. If you want to use its resources, you must first identify yourself to the system by logging in. This is called authentication.

Page 23: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Logging In

! The server we will be using for most of this class is accessible through the network by the name of iris. We use the full DNS name to distinguish it from any other server that may be named "iris". More on DNS later.

iris.ils.indiana.edu

Page 24: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Logging In

• You can login to a Unix system from any location in the world using any client that supports the network protocol "ssh". The secure shell (ssh) is a protocol that is used to create a secure channel over an insecure network.

• Invoking the ssh command will knock on a particular server door which in turn will prompt for a username and password. Once you successfully authenticate you have access to the system resources via this secure channel.

Page 25: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Logging In Practice• We will now use ssh to connect to our host, iris.

• Every modern operating system (Mac/Linux/Windows) has the capability of running a ssh client. Linux and Mac OS X are just different distributions of Unix and therefore have native support for this type of connectivity. Windows users can download one of the many free ssh clients. For OSX/Linux users, just launch the "Terminal" application and use the ssh command.

Page 26: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Logging In Practice

• In a Windows environment, launch your ssh client and enter the DNS name of our server: iris.ils.indiana.edu

• In an OS X or Linux environment, once you launch the terminal application type the command line below.

$ ssh [email protected]

Page 27: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Kerberos Authentication

• You will be asked for your kerberos password, which should be the same password you used to log in at this lab.

• Kerberos is used campus-wide as a secure way to authenticate across an insecure network. You and the computer you connect to prove that you are who you say you are without actually sending passwords across the network.

Page 28: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Logging In

• Once successfully logged in, a Unix system typically tells you when you logged in last and from where, shows you any implemented disk quota, gives you some arbitrary text written by the system administrator, provides you with a command shell prompt, and then waits for your commands.

Page 29: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Logging In• Example: Last login: Mon Aug 4 15:20:54 2008 from chionofuji.ils.indiana.edu

Disk quotas for stevecox (uid 2238):

Filesystem usage quota limit timeleft files quota limit timeleft|-----------------------------------------------------------------| | This system is for the use of authorized users only. | | Individuals using this computer system without authority, or in | | excess of their authority, are subject to having all of their | | activities on this system monitored and recorded by system | | personnel. | | | | In the course of monitoring individuals improperly using this | | system, or in the course of system maintenance, the activities | | of authorized users may also be monitored. | | | | Anyone using this system expressly consents to such monitoring | | and is advised that if such monitoring reveals possible | | evidence of criminal activity, system personnel may provide the | | evidence of such monitoring to law enforcement officials. | | | |SLIS computing accounts expire: | |See: http://www.slis.indiana.edu/technology/help/ for details | |-----------------------------------------------------------------| stevecox@iris:~ $

Page 30: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Logging In• You are left with a prompt at the bottom of

your login screen.

• A command prompt generally ends with either a dollar sign ($) or a percent sign (%). There are two main types of command shells; those based on a Bourne shell (i.e. sh and bash) and those based on a C shell (i.e. csh and tcsh).

Page 31: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Logging In• To keep you straight on which you are using,

the two shells traditionally use different prompts:

$ for Bourne shells

% for C shells.

• Your account on iris uses a Bourne shell derivative (bash to be specific).

Page 32: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Installing your Practice Directory

• During this module you will be using a practice directory structure complete with practice files and directories.

• You will now install this into your home directory on iris.

Page 33: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Getting your Practice Directory• Make sure you are logged into iris and type

these commands:

$ cd (press return)

$ tar -xvf /tmp/Unix_class.tar

• You will see a list of filenames and directories scroll by. You will learn more about the command you just used on your last day of this module.

Page 34: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Unix Commands

• Now you are logged into the system, but you need to know how to talk to the system or issue your commands.

Page 35: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Unix Commands

• There are a number of commands which you need to know in order to tell the system to do various things (show you directories, move files, copy files, search for files, etc.).

Page 36: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Unix Commands

• Unix commands generally have three parts or syntactic elements:

command_name

Example:

$ ls

• Tells the system to show you a list of files

Page 37: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Unix Commands

• Unix Commands generally have three parts:

command_name [options]

Example:

$ ls -l

• List files, in “long format” form (gives more information about the files)

Page 38: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Unix Commands

command_name [options]

Note: In some texts and web links, options can also be referred to as “flags”.

Page 39: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Unix Commands

• Unix Commands generally have three parts:

command_name [options][operands]

Example:

$ ls -l Unix_class

• List files, in “long format” form, in the directory called ‘Unix_class’

Page 40: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Unix Commands

• Unix Commands generally have three parts:

command_name [options][operands]

Note: In some texts and web links, operands can also be referred to as “arguments”

Page 41: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Unix Commands

• Not all commands will need all three parts. In fact, some will only need the command_name. However, others may require two [operands]

Page 42: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Unix Commands

Important to Remember:

• Unix is case-sensitive; old.files is different from Old.Files.

• The spaces between the command_name, the [option] and the [operand] are VERY important.

Page 43: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

who - Practice

• One simple Unix command is used to find out who is currently logged in. At the shell prompt (the $), type who.

$ who

Page 44: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

who - Practice• Example Output

$ who

herring pts/12 Jun 17 15:36 (herring.slis.indiana.edu)

mnapier pts/4 Jun 14 21:29 (12-222-70-96.client.insightbb.com)

mnapier pts/8 Jun 17 07:39 (dmitrii.slis.indiana.edu)

jfieber pts/5 Jun 17 15:56 (d-1-1.dhcp-149-159.indiana.edu)

htripath pts/3 Jun 17 11:10 (lair4.slis.indiana.edu)

mnapier pts/9 Jun 16 09:00 (12-222-70-96.client.insightbb.com)

stevecox pts/10 Jun 17 16:51 (wireless-73-28.wireless.indiana.edu)

stevecox pts/13 Jun 17 16:34 (chionofuji.slis.indiana.edu)

$

Page 45: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Unix Directories

Page 46: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Directories

• The information stored in the Unix system is hierarchical.

• Like the “folders” on a Mac or Windows operating system, Unix works with “directories.”

Page 47: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Directories

• A directory can contain either files or more directories (often called subdirectories). There are a number of common Unix directories found on most systems.

Page 48: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Directories

Page 49: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Directories

• All files and directories on the system reside under the root directory, the [ / ]. Where other directories have real names, the name of the directory at the very top of the Unix OS is the forward slash (/).

Page 50: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Directories

• The ‘home’ directory is your personal subdirectory under /home. It is where you will store all of your personal data.

Example: /home/jsmith

Page 51: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Directories

The ‘working’ or ‘current’ directory is whatever directory you are in at the moment.

Page 52: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Basic Unix CommandsA Few Commands and

Concepts To Get Us Started

Page 53: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

pwd - ‘print working directory’

• Typing pwd will display a list of directories separated by a forward slash (/). This is a pathname. The first slash refers to the root directory, then each subdirectory is listed, and the last item is the name of the directory you are currently in (your working directory).

$ pwd /home/jsmith

Page 54: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

pwd - Practice

• What is the pathname of your current directory?

Example: /home/stevecox

Page 55: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

ls - ‘list’

• The command_name ls alone will list the names of the files in the current (or working) directory.

$ ls Unix_class

Page 56: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

ls - ‘list’

• ls [operand] will list the names of the files in the specific directory asked for.

$ ls /home ajkurtz htripath klabarre cdulude jfieber mbswan herring katy stevecox

Page 57: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

ls - PracticeHow many files and subdirectories are in your current directory?

How many files and subdirectories are in /home/userid/Unix_class ?

$ ls

(Unix_class) & (misc. files)

$ ls /home/userid/Unix_class

5 (Shakespeare, Wildcards, dir1, dir2, equine)

Page 58: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

cd - ‘change directory’

• When you use the command, ls, you are just looking at the directories, you have not actually ‘moved’ (you stay at the same working directory).

• The command, cd, will let you move your current directory to a new location.

Page 59: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

cd - ‘change directory’

• The command_name cd alone will always move you to your personal home directory (on /home).

$ cd

Page 60: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

cd - ‘change directory’

• If you supply an operand to the change directory command, it will move you (your current directory) to the specified directory.

$ cd Unix_class

Page 61: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

cd - ‘change directory’

• Note: Getting around a hierarchical filesystem is very important to grasp.

• If the directory you wish to move to is a subdirectory of your current directory, then you only need to type a pathname starting from where you are.

$ cd Unix_class/dir2/cats

This is called a relative pathname.

Page 62: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

cd - ‘change directory’• But, if the directory you wish to move to is

not a subdirectory of your current directory, then you need to type a pathname starting from the root (/).

$ cd /var/adm/log

This is called an absolute pathname. Some texts will refer to this as a “full” pathname.

The meaning is the same.

Page 63: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Pathnames - Example

grp_project

kadams

dir1 dir2

UNIX_class

jsmith stevecox

home bin

log

adm

var

/If you are in jsmith,

Page 64: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Pathnames - Example

grp_project

kadams

dir1 dir2

UNIX_class

jsmith stevecox

home bin

log

adm

var

/If you are in jsmith,and you want to go to dir1

Page 65: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Pathnames - Example

grp_project

kadams

dir1 dir2

UNIX_class

jsmith stevecox

home bin

log

adm

var

/

You only need a relative pathname, because dir1 is ‘under’ you.

Page 66: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Pathnames - Example

grp_project

kadams

dir1 dir2

UNIX_class

jsmith stevecox

home bin

log

adm

var

/

$ cd Unix_class/dir1

Page 67: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Pathnames - Example

grp_project

kadams

dir1 dir2

UNIX_class

jsmith stevecox

home bin

log

adm

var

/If you are in jsmith,

Page 68: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Pathnames - Example

grp_project

kadams

dir1 dir2

UNIX_class

jsmith stevecox

home bin

log

adm

var

/If you are in jsmith,and you want to go to log

Page 69: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Pathnames - Example

grp_project

kadams

dir1 dir2

UNIX_class

jsmith stevecox

home bin

log

adm

var

/

You need an absolute pathname, because log is not ‘under’ you.

Page 70: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Pathnames - Example

grp_project

kadams

dir1 dir2

UNIX_class

jsmith stevecox

home bin

log

adm

var

/

$ cd /var/adm/log

Page 71: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Pathnames - Example

grp_project

kadams

dir1 dir2

UNIX_class

jsmith stevecox

home bin

log

adm

var

/

If you are in Unix_class and you need to access grp_project, how would you get there?

Page 72: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Pathnames - Example

grp_project

kadams

dir1 dir2

UNIX_class

jsmith stevecox

home bin

log

adm

var

/

$ cd /home/kadams/grp_project

Page 73: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

grp_project

kadams

dir1 dir2

UNIX_class

jsmith stevecox

home bin

log

adm

var

/

But, if you are in home and you need to access grp_project, how would you get there?

Pathnames - Example

Page 74: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

grp_project

kadams

dir1 dir2

UNIX_class

jsmith stevecox

home bin

log

adm

var

/

$ cd kadams/grp_project

Pathnames - Example

Page 75: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

cd - Practice• Change your current directory to this directory:

/home/userid/Unix_class/dir2

Now go back to your home directory.

Page 76: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

References to your home directory

• When you login, Unix always knows where your home directory is.

• There are a few ways to return to the top of your home directory

/home/userid

Page 77: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

References to your home directory

~ (tilde) symbol represents your home directory so:

$ cd ~

will always return you to your home.

$ cd ~userid

This will lookup the information for another user and find their home directory location and take you there if you are allowed.

Page 78: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

.. - ‘parent directory’

• As we mentioned earlier, the information stored in the Unix system is hierarchical.

• At any time, the directory which is right above you (closer to the root directory) is often called the ‘parent’ directory.

• .. is an [operand] which “signifies” the parent directory of your current directory. It will be used in place of an operand.

Page 79: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

.. - ‘parent directory’

bin etc home sbin

bin

bin man

local

man

share

usr var

/

• The parent directory of ‘man’ is ‘local,’ and the parent directory of ‘local’ is ‘usr.’

Page 80: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

.. - ‘parent directory’

• Typing cd .. will move your working directory up one level, into the parent directory of where you were.

$ cd ..

Page 81: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

.. - ‘parent directory’

• What is the pathname of your home directory?

• What is the pathname of the parent directory of your home directory?

/home/userid

/home

Page 82: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

.. - ‘parent directory’

• Typing ls .. lists everything else in your parent directory – files and directories parallel with your working directory.

$ ls ..

Page 83: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Example

sbaker

mail docs temp

jsmith stevecox

home

Page 84: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Example

Suppose ‘jsmith’ is your current directory.

sbaker

mail docs temp

jsmith stevecox

home

Page 85: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Example

$ pwd

/home/jsmith

sbaker

mail docs temp

jsmith stevecox

home

Page 86: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Example

$ ls

mail docs temp

sbaker

mail docs temp

jsmith stevecox

home

Page 87: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Example

$ ls

mail docs temp

sbaker

mail docs temp

jsmith stevecox

home

Page 88: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Example

$ ls

mail docs temp

sbaker

mail docs temp

jsmith stevecox

home

Page 89: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Example

$ ls

mail docs temp

sbaker

mail docs temp

jsmith stevecox

home

Page 90: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Example

$ ls

mail docs temp

sbaker

mail docs temp

jsmith stevecox

home

Page 91: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Example

$ ls ..

sbaker jsmith stevecox

sbaker

mail docs temp

jsmith stevecox

home

Page 92: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Example

$ ls ..

sbaker

mail docs temp

jsmith stevecox

home

sbaker jsmith stevecox

Page 93: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Example

$ ls ..

sbaker

mail docs temp

jsmith stevecox

home

sbaker jsmith stevecox

Page 94: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Example

$ ls ..

sbaker

mail docs temp

jsmith stevecox

home

sbaker jsmith stevecox

Page 95: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Example

$ ls ..

sbaker

mail docs temp

jsmith stevecox

home

sbaker jsmith stevecox

Page 96: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Example

$ cd ..

sbaker

mail docs temp

jsmith stevecox

home

Page 97: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Example

$ cd ..

Moves your current directory to /home.

sbaker

mail docs temp

jsmith stevecox

home

Page 98: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

.. - ‘parent directory’

• You can also use ‘..’ to move ‘up, over, and down’ to a new directory somewhere else.

• Otherwise you would have to use an absolute pathname.

Page 99: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

.. Example

grp_project

kadams

dir1 dir2

UNIX_class

jsmith stevecox

home bin

log

adm

var

/If you are in jsmith,

Page 100: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

.. Example

grp_project

kadams

dir1 dir2

UNIX_class

jsmith stevecox

home bin

log

adm

var

/

If you are in jsmith,and you want to go to dir1

Page 101: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

.. Example

grp_project

kadams

dir1 dir2

UNIX_class

jsmith stevecox

home bin

log

adm

var

/

$ cd ..

At this point, you have moved up to home

Page 102: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

.. Example

grp_project

kadams

dir1 dir2

UNIX_class

jsmith stevecox

home bin

log

adm

var

/

$ cd ../kadams

Now you have moved down to kadams

Page 103: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

.. Example

grp_project

kadams

dir1 dir2

UNIX_class

jsmith stevecox

home bin

log

adm

var

/

$ cd ../kadams/grp_projectAnd now you are in grp_project

Page 104: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

.. Example

grp_project

kadams

dir1 dir2

UNIX_class

jsmith stevecox

home bin

log

adm

var

/Now that you are in grp_project, you can move to stevecox

Page 105: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

.. Example

grp_project

kadams

dir1 dir2

UNIX_class

jsmith stevecox

home bin

log

adm

var

/

$ cd ../../stevecoxNow that you are in grp_project, you can move to stevecox

Page 106: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

man - ‘manual’

• Can’t remember what a command does?

• You can type:

$ man command_name

• This will give you Unix’s complete online manual.

Page 107: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

man - ‘manual’

• Don’t just rely on the manual though. This would be a very time-consuming way of using Unix, and also the manual can be pretty difficult to understand.

• Note: use the space bar to move forward a page, and the ‘b’ key to move back a page

Page 108: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

• A manual page will usually include:

• Title: the page # and the name of the system that the command is part of

• Name: usually the command and a brief description

• Synopsis: how to type the command, and an example of every option available.

man - ‘manual’

Page 109: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

• Description: a few paragraphs (or pages) about the command and its options

• See Also: lists names of related manual pages, if any

• Warnings and Bugs: if any are known

• Files: a list of the files this command uses (for specific commands - like mail)

man - ‘manual’

Page 110: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

man - PracticeBrowse through the man page for the cd

command. $ man cd Now browse through the man page for the pwd

command. $ man pwd

Notice how much larger the manual is for cd (which is a more complex command).

You can type ‘q’ to leave man

Page 111: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

• If you forget how man is laid out, you can always type: $ man man

man - ‘manual’

Page 112: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Review

• pwd - tells you where you currently are

• ls - list the files & subdirectories of your current directory

• cd - changes your current directory

• man - displays the manual pages

• .. - signifies the parent directory of your current directory. It is NOT a command, it is an operand (argument).

Page 113: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Combining Commands

• If you don’t remember the name of the directory you want to move to, then use ls to see all the names of your working directory, then cd to the correct one.

Page 114: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Practice

• What is the absolute pathname to cats? (in dir2)

/home/userid/Unix_class/dir2/cats

Page 115: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Practice

eight $ ls Unix_class/Shakespeare

How many files are in the Shakespeare directory?

Page 116: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Practice

• What option is needed to list the files in a directory, including those that are normally not listed (begins with a . )?

Page 117: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Practice

• $ man ls

-a Lists all entries, including those that begin with a dot (.), which are normally not listed.

Page 118: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Unix Shells

Our Interactive Interface

Page 119: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Shells

• The shell is how you interact with the Unix system.

• This is the means in which you give the system commands.

Page 120: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

• You can customize your environment, enter and reenter commands and provide shortcuts to save on typing.

• The shell can also be a flexible scripting language allowing you to create executable programs for you and others to use.

Shells

Page 121: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

•While there are several different shells to choose from, the bash shell is an excellent choice for interactive and non-interactive use. It is the default shell here at SLIS.

•This is a public domain shell written by the Free Software Foundation under their GNU initiative.

Bash Shell

Page 122: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Bash shell feature:

• Command Line Completion

A very nice feature of modern shells is command line completion. You type part of your command line and then hit the tab key and the shell will try and complete the command line for you. You will use this most often with operands.

Command Line Completion

Page 123: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

While in your home directory, move to your Unix_class directory.

•Instead of typing:

$ cd Unix_class

•You could type:

$ cd U (tab)

The shell’s command line completion takes over.

Command Completion Practice

Page 124: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

• For this to work as the example shows you could not have another directory name starting with “U”.

• Command line completion only works if there is only one possible match to the letters or numbers that you enter before you hit the tab key.

Command Line Completion

Page 125: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

•Remember, Unix is case sensitive so if you were to type:

$ cd u (tab)

it would not find your directory using command line completion

Command Line Completion

Page 126: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Session History

• Another nice shell feature that you will use frequently is session history.

• This lets you easily recall your frequently used command lines and use them again.

Page 127: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Session History Practice

• Press your (up) arrow one time • Your last command line should appear at your prompt.

• If you would like to use that command line again, just hit enter.

Page 128: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

• Do not hit return on a command line if you do not intend to complete the action.

• You can backspace/delete over the command line OR type Ctrl+U (^U).

• You can continue to use your up arrow or down arrow until you find the command line that you would like to reuse and then press enter.

Session History Practice

Page 129: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Session History

Use Session History for:

• Reviewing the command lines you’ve used during your session

• Using previous command lines again, rather than retyping them

• Modifying complex command lines

Page 130: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Metacharacters[ ] < > { } ( ) ‘ “ *

? | / \ ̂ ! # $ % @ & ~ ;

Page 131: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

MetacharactersA metacharacter is a single character that is used in place of another character or set of characters.

To the shell, they represent something other than the character or symbol that they are.

Therefore, you cannot use metacharacters in the name of a file or a directory.

Page 132: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Metacharacters [ ] brackets < > angle brackets { } braces ( ) parentheses ' single quotes " double quotes * asterisks ? question marks | pipe symbols / \ slashes

^ carets ! exclamations # pound signs $ dollar signs % percent signs @ at signs & ampersands ; semi-colons ` accent marks ~ tildes

Page 133: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Metacharacters

Other keys also have specific meaning to Unix:

Pressing <return>Pressing <tab>

Page 134: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Naming Files & Directories

When naming a file or directory, you cannot use any metacharacters or spaces.

However, you can use periods (.) and underscores (_).

In fact, if you start a file with a period (.) it will be a ‘hidden’ file which does not show with ls (you must use ls -a).

Page 135: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Manipulating Files and Directories

Making Renaming Copying Removing

Moving

Page 136: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Making A New Directory

You can create a new directory with the mkdir command.

$ mkdir new_directory_name

Page 137: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Making A New Directory

You should start by typing pwd to make sure you are in the right place (you will create a subdirectory in whatever directory you are in).

Then you should type ls to check and make sure your new directory will not conflict with an already existing name.

Page 138: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Making A New Directory

Then enter the command line:

$ mkdir new_directory_name

to add your directory.

Then you should type ls to check and make sure your new directory will not conflict with an already existing name.

Page 139: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Making A New Directory

Make a new directory in Unix_class called dir3

$ cd Unix_class $ pwd $ ls $ mkdir dir3 $ ls

Practice:

Page 140: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Copying a File or Directory

You can copy an existing file or directory with the cp command.

$ cp existingfile newfile

$ cp -r existingdir newdir

• The -r is necessary when copying a directory; we will talk more about these types of options later.

Page 141: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Copying a File or Directory

When copying, moving, renaming, etc., the source will always come first, and the destination second.

Or, they are sometimes referred to as:

$ cp source destination

$ cp -r source destination

Page 142: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Copying a File or Directory

Go to the directory where the file is located:

$ cd pathname

Verify the file is there (and the spelling):

$ ls

Copy the file to a new name:

$ cp existingfile newfile

Page 143: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Copying a File or Directory

Also remember to list your directory (ls) first, to verify that your new file name does not already exist – if it does then your new copy will simply overwrite it!

Page 144: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Copying a File or Directory

Copy the file final.paper (in dir2) and name the new file “gerbils.”

Practice:

$ cd dir2 (or Unix_class/dir2) $ ls $ cp final.paper gerbils $ ls

Page 145: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Moving a File or Directory

You can move a file or directory with mv. Unlike cp, after using mv you will still only have one copy of the file or directory.

$ mv filename newpathname

$ mv directoryname newpathname

Page 146: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Moving a File or Directory

You can move a file or directory with mv. Unlike cp, after using mv you will still only have one copy of the file or directory.

$ mv source destination

$ mv source destination

Page 147: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Moving a File or Directory

For example, if you typed:

$ mv equine dir2

You would be moving the file equine into the dir2 directory.

$ mv filename newpathname

Page 148: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Moving a File or Directory

If you are using mv to move the file or directory to a different location you may want to consider copying it first and then deleting the original.

Page 149: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Moving a File or Directory

Always remember to ls the destination directory to verify there will be no conflict of names. If you attempt to move a directory to another location that does not exist, your directory will be renamed, not moved.

Page 150: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Moving a File or Directory

Go to the directory where the file is located:

$ cd pathname

Verify the file is there (and the spelling):

$ ls

Move the file to its new location:

$ mv filename newpathname

Page 151: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Moving a File or Directory

Move the file gerbils (in dir2) to your new directory (dir3).

Practice:

$ cd dir2 (if not already there)

$ ls $ mv gerbils ../dir3 (or) $ mv gerbils ~/Unix_class/dir3

Page 152: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Moving a File or Directory

All operands are independent of the commands that require them.

We use the ‘ls’ command to list directories but we’ll need to supply an operand. How about the destination directory?

How do you know that it worked?

$ ls ../dir3

Page 153: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Renaming a File or Directory

$ mv oldfilename newfilename

$ mv olddirname newdirname

Renaming a file or directory is really just moving it to a different name. There is no “rename” command.

Page 154: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Renaming a File or

Renaming a file or directory is really just moving it to a different name. There is no “rename” command.

Example: You have a file named costs and you

want to change the name to expenses.

Page 155: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Renaming a File or Directory

$ mv costs expenses

Renaming a file or directory is really just moving it to a different name. There is no “rename” command.

Page 156: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Renaming a File or Directory

Go to the directory where the file is located:

$ cd pathname

Verify the file is there (and the spelling):

$ ls

‘Move’ the file to its new name:

$ mv oldfilename newfilename

Page 157: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Renaming a File or Directory

Rename the file gerbils to furry.rodents

Practice:

$ cd ../dir3 $ ls $ mv gerbils furry.rodents $ ls

Page 158: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Renaming a File or Directory

Another reason to use mv is to correct a misspelled file name.

$ mv apr.bugdet apr.budget

Page 159: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Renaming a File or Directory

You can move and rename a file at the same time:

$ mv oldfilename newpathname/newfilename

Example: $ mv fall_classes ~/oldfiles/fall_2002 (The oldfiles directory has to already

exist)

Page 160: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Renaming a File or Directory

** Important! ** When using mv with directories…

$ mv oldname newname

If there already is a directory with the newname, then the oldname will become a subdirectory of the newname (the “rename” becomes a “move”).

Page 161: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Renaming a File or Directory

** Important! ** When using mv or cp with files…

$ mv oldname newname

If there already is a file with the newname, then the oldname will overwrite the newname.

Page 162: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Removing a File or Directory

You can remove (delete) a file with the rm command.

$ rm filename

You can remove (delete) an empty directory with the rmdir command.

$ rmdir directoryname

Page 163: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Removing a File or Directory

To remove a directory, you must first delete all the files in it:

$ rm filenamesThen move into the parent directory: $ cd .. Then delete the directory: $ rmdir directory

Page 164: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Removing a File or Directory

Remove the directory dir3

Practice:

$ rm furry.rodents $ cd .. $ rmdir dir3 $ ls

Page 165: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Removing a File or Directory

You can also remove more than one file at a time:

$ rm fileone filetwo filethree

Page 166: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Wildcards? *

Page 167: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Wildcards

There are two metacharacters which can act as a substitution for unknown letters or numbers in a filename or directory name.

? *

Page 168: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

? Wildcard

The wildcard ? (question mark) can be a substitute for any single letter, number, or character.

Page 169: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

? Wildcard Practice

$ ls sonnet? (in Shakespeare dir.)

This will list any filename that starts with sonnet and has exactly one character after sonnet.

The wildcard ? can be a substitute for any single letter, number, or character.

Page 170: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

? Wildcard Practice

The wildcard ? can be a substitute for any single letter, number, or character.

$ ls sonnet?

This will not list: sonnet10 sonnet.favorite Sonnet8 (capital S)

Page 171: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

* Wildcard

The wildcard * (asterisk) can be a substitute for any number of letters, numbers, or characters.

Page 172: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

* Wildcard Practice

The wildcard * can be a substitute for any number of letters, numbers, or characters.

$ ls sonnet*

This will list all names that begin with sonnet (and would include sonnet by itself). It will still not list Sonnet8

Page 173: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Wildcard Practice

$ cd ../Wildcards $ ls let*3 letter3 letterhome.13 lettering.type3 lettuce.file3

Wildcards can specify a group of letters or numbers.

Page 174: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Wildcard Practice

$ ls *13 email_mgs_1to13 letterhome.13 shell.script.113 testfile.8513

Page 175: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Wildcard Practice

$ ls *file* filet.mignon.recipe lettuce.file3 old.file sufiletters testfile.8513

Page 176: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Wildcard Practice

$ ls s* secret.ideas shell.script.113 shell.script.276 stuff sufiletters

(Remember that Unix is case

sensitive, so the file Sam would not

be found)

Page 177: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Wildcard Practice$ ls ???

Sam fl9 h.d kid pix

Page 178: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Wildcard Uses

You can use wildcards with commands other than ls.

Page 179: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Wildcard Uses

To move all files that begin with "assgn" (assgn3, assgn12, etc.) to the old.files directory, you can type:

$ mv assgn* old.files

The directory old.files has to already exist.

Page 180: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Wildcard Uses

To copy all the files from the current directory into a directory called temp, you can type:

$ cp * temp

The directory temp has to already exist.

Page 181: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Wildcard Uses

To remove all files with a certain ending, you can type:

$ rm *.txt

Page 182: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Wildcard Uses

However, before you remove them, type:

$ ls *.txt

This way you can make sure there is nothing there you did not want to delete.

Page 183: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Wildcard UsesHowever, DO NOT TYPE this line!

This is a typo to avoid!

The extra space means you would remove everything in the directory!

$ rm * .txt

↑Very important!!!!

Page 184: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Wildcard Practice

Create another directory in Unix_class called Poems

$ cd ..

$ pwd (verify you are in Unix_class)

$ mkdir Poems $ ls

Page 185: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Wildcard Practice

Copy everything from Shakespeare into Poems.

$ cd Shakespeare

$ cp * ../Poems

* - source (in this case, everything)

../Poems - destination

Page 186: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Wildcard Practice

Or, this is another way to achieve this: $ mkdir Poems

$ cd Poems

$ cp ../Shakespeare/* .

../Shakespeare/* - source

. - destination

(the single period represents your current directory)

Page 187: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Wildcards

Wildcards apply to all commands and are used in place of or in combination with operands.

Page 188: Intro to Unix-1-2014 - Indiana University Bloomingtoninfo.ils.indiana.edu/~stevecox/unix/unix_intro/intro_unix-1.pdf · Graphic from The Design of the Unix operating System by Maurice

Ready for more?


Recommended