introduction to unix a user’s perspective: day 2 – command basics
Post on 22-Dec-2015
231 views
TRANSCRIPT
Review – UNIX Shells
The basics of UNIX Shells– Types
ksh & bash
– Initialization/configuration scripts /etc/profile & .profile /etc/bash_rc & .bash_rc
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?
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
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
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
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)
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)
Commands – Directed Function
Perform the command on a file– What can the file be?
ls index.html rm /u/ux101is1/hdisk0
Commands – Extended Function
Using switch(es) to refine the command output Usually provides more information Always deals with specific function of the base
command
Commands – Directed Extended Function
Refine the operation performed on a file(s) ls –ail index.html
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/
Example
cd ~ cd public_html ls –ailF cd test ls –ailF cd .. cp –h index.html .. cd .. ls –al rm index.html
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
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
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–
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
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
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
Putting it All Together
What do we gain– Extended functionality– Increased control– Innovative solutions– An understanding of both input and output
IN CLASS DEMONSTRATION
SIX Volunteers able to follow instructions– Hmmmm…
A paper | B | C | D | E | F > Frontdesk
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
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
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
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