Top Banner
Introduction to UNIX A User’s Perspective: Day 2 – Command Basics
39

Introduction to UNIX A User’s Perspective: Day 2 – Command Basics.

Dec 22, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Introduction to UNIX A User’s Perspective: Day 2 – Command Basics.

Introduction to UNIX

A User’s Perspective:Day 2 – Command Basics

Page 2: Introduction to UNIX A User’s Perspective: Day 2 – Command Basics.

Review – UNIX Shells

The basics of UNIX Shells– Types

ksh & bash

– Initialization/configuration scripts /etc/profile & .profile /etc/bash_rc & .bash_rc

Page 3: Introduction to UNIX A User’s Perspective: Day 2 – Command Basics.

Review – File System

Everything is a file Paths Ownership & Permissions

Page 4: Introduction to UNIX A User’s Perspective: Day 2 – Command Basics.

Let’s Log into the Server

A few changes– The server we will use:

137.99.110.55 spf1n5.ucc.uconn.edu

– The login utility: ssh

Why the changes?

Page 5: Introduction to UNIX A User’s Perspective: Day 2 – Command Basics.

Review - Commands

ls – LiSt cd – Change Directory pwd – Present Working

Directory rm – ReMove mkdir – Make Directory mv – MoVe cp – CoPy touch – Create cat – conCATenate echo – Hello…lloo..llooo…

ln – Link chmod – Change permissions chown – Change Ownership

Shortcuts to your home directory

– cd– cd ~– cd ~user-name– cd $HOME

Page 6: Introduction to UNIX A User’s Perspective: Day 2 – Command Basics.

Command Exercise

1. pwd

2. ls -al

3. touch index.html

4. ls –al

5. mkdir –p public_html/test/page

6. cp -p index.html public_html/test/page

7. mv index.html public_html/test

8. cd public_html

9. echo “name Loves UNIX” > test/index.html

10. cd ..

11. echo “Mitch Loves UNIX” > test/page/index.html

12. ln –s test/index.html index.html

13. cat index.html

14. rm test/index.html

15. cat index.html

16. ln test/page/index.html test/index.html

17. cat index.html

18. echo “UNIX rules” >> test/page/index.html

19. cat index.html

Page 7: Introduction to UNIX A User’s Perspective: Day 2 – Command Basics.

What Did We Do?

Page 8: Introduction to UNIX A User’s Perspective: Day 2 – Command Basics.

Some Loose Ends

CTRL-C– Terminate the current process

CTRL-D– Close the connection immediately

Page 9: Introduction to UNIX A User’s Perspective: Day 2 – Command Basics.

What We Will Cover Today

Extend our knowledge and use of commands Learn how to find help Standard I/O/E Redirection & Piping Customize our Shell account Begin to learn VI

Page 10: Introduction to UNIX A User’s Perspective: Day 2 – Command Basics.

Command Arguments

Typically one or more file names the command will operate on

Page 11: Introduction to UNIX A User’s Perspective: Day 2 – Command Basics.

Switches!?! We don’t need no stink’in Switches

Switches give us power/functionality Increase the functionality of a command Almost all commands have available switches Switches are denoted with a – (minus or

hyphen)

Page 12: Introduction to UNIX A User’s Perspective: Day 2 – Command Basics.

Anatomy of a Command

Command-name– Basic function

Command-name arguments– Basic function performed on some file(s)

Command-name –switches– Extended function

Command-name –switches arguments– Extended function performed on some file(s)

Page 13: Introduction to UNIX A User’s Perspective: Day 2 – Command Basics.

Commands - Basic Function

Single function ls, cp, mv, etc.

– Minimal functionality– Minimal output

Page 14: Introduction to UNIX A User’s Perspective: Day 2 – Command Basics.

Commands – Directed Function

Perform the command on a file– What can the file be?

ls index.html rm /u/ux101is1/hdisk0

Page 15: Introduction to UNIX A User’s Perspective: Day 2 – Command Basics.

Commands – Extended Function

Using switch(es) to refine the command output Usually provides more information Always deals with specific function of the base

command

Page 16: Introduction to UNIX A User’s Perspective: Day 2 – Command Basics.

Commands – Directed Extended Function

Refine the operation performed on a file(s) ls –ail index.html

Page 17: Introduction to UNIX A User’s Perspective: Day 2 – Command Basics.

Manual Pages – The UNIX Bible

Everything you need to know… man pages

– System resident manuals

Available: – for most commands– on most UNIX systems– on the Web

http://www.linuxcentral.com/linux/man-pages/

Page 18: Introduction to UNIX A User’s Perspective: Day 2 – Command Basics.

Using man

Syntax– man “command-name”– man –k “descriptor”

Page 19: Introduction to UNIX A User’s Perspective: Day 2 – Command Basics.

Anatomy of a man Page

Purpose Syntax Description Details of switches Examples

Page 20: Introduction to UNIX A User’s Perspective: Day 2 – Command Basics.

Example

cd ~ cd public_html ls –ailF cd test ls –ailF cd .. cp –h index.html .. cd .. ls –al rm index.html

Page 21: Introduction to UNIX A User’s Perspective: Day 2 – Command Basics.

What Should You Know?

Basic Command Use How to use switches and arguments How to find help

Page 22: Introduction to UNIX A User’s Perspective: Day 2 – Command Basics.

Question?

Anyone… anyone?

Page 23: Introduction to UNIX A User’s Perspective: Day 2 – Command Basics.

Redirection & Pipes

Understanding UNIX

Input and Output

Page 24: Introduction to UNIX A User’s Perspective: Day 2 – Command Basics.

What is Input?

Information fed into a data processing system or computer (Merriam-Webster Dictionary)

Data necessary to create some action or output. Text

– ‘Joshua’

Keystroke combinations– CTRL -D

Page 25: Introduction to UNIX A User’s Perspective: Day 2 – Command Basics.

Input Sources

Standard Input (stdin) Device– That part of the operating system controlling from

where a program receives its input.– keyboard

Any defined device capable of receiving input

Page 26: Introduction to UNIX A User’s Perspective: Day 2 – Command Basics.

What is Output?

The information produced by a computer (Merriam-Webster Dictionary)

Data created as a result of some action or input. Text

– ‘Hello Joshua’

Pictures & Graphics–

Page 27: Introduction to UNIX A User’s Perspective: Day 2 – Command Basics.

Output Destinations

Standard Output (stdout) Devices– That part of the operating system that controls where a

program writes its output.– Monitor– Printer

Any defined device capable of receiving output

Page 28: Introduction to UNIX A User’s Perspective: Day 2 – Command Basics.

Redirection

Where? > the redirection operator

– Allows for an output destination other then standard output (stdout).

– Is a write only operation Can only redirect to regular files.

# ls –al /usr > directory.lst

Page 29: Introduction to UNIX A User’s Perspective: Day 2 – Command Basics.

Pipes

Keeping the Flow Going… | the pipe operator

– Allows for the output (stdout) of one command to serve as the input (stdin) of another command

– No write involved in the process Can only be used with commands (executables)

# ls –al /usr/bin | grep ls

                 

                  

Page 30: Introduction to UNIX A User’s Perspective: Day 2 – Command Basics.

Putting it All Together

What do we gain– Extended functionality– Increased control– Innovative solutions– An understanding of both input and output

Page 31: Introduction to UNIX A User’s Perspective: Day 2 – Command Basics.

IN CLASS DEMONSTRATION

SIX Volunteers able to follow instructions– Hmmmm…

A paper | B | C | D | E | F > Frontdesk

Page 32: Introduction to UNIX A User’s Perspective: Day 2 – Command Basics.

A Real World Example

cp –p /u/ux101is1/tfile . ls –al tfile wc tfile sort tfile | wc sort tfile | uniq –c | wc sort tfile | uniq –c | sort –rn > tfile2 wc tfile wc tfile2 more tfile more tfile2

Page 33: Introduction to UNIX A User’s Perspective: Day 2 – Command Basics.

Running Processes

Foreground– Ties up the command-prompt

Loose control

– Not really multi-tasking

Background– Keep control of the command prompt

Maintain control

– Multi-tasking

Page 34: Introduction to UNIX A User’s Perspective: Day 2 – Command Basics.

What’s Running?

ps –ef | grep ux ps aux | more ps –ef | grep “string”

Page 35: Introduction to UNIX A User’s Perspective: Day 2 – Command Basics.

Cron Jobs

Scheduling jobs…– Minute Hour Day Month Day_of_the_Week

Sunday = 0 * = Match all

Examples:– 0,5,10,15,20,25,30,35,40,45,50,55 * * * * $HOME/automation.pl– 0 2 * * 4 /usr/sbin/acct/dodisk– 5 * * * * /usr/sbin/acct/ckpacct– 0 4 * * 1-6 /usr/sbin/acct/runacct 2>/var/adm/acct/nite/accterr

Page 36: Introduction to UNIX A User’s Perspective: Day 2 – Command Basics.

What Should You Know?

– Basic Command Use– How to use switches and arguments– How to find help

Understand Standard I/O/E Understand Redirection Understand Pipes How to use Redirection and Pipes Process management

Page 37: Introduction to UNIX A User’s Perspective: Day 2 – Command Basics.

Question?

Anyone… anyone?

Page 38: Introduction to UNIX A User’s Perspective: Day 2 – Command Basics.

What Will Cover Tomorrow…

Advanced UNIX commands VI

Page 39: Introduction to UNIX A User’s Perspective: Day 2 – Command Basics.

THANK YOU FOR ATTENDING

Please fill out the Evaluation Form before leaving