SlideShare a Scribd company logo
1 of 43
Download to read offline
Unix and Linux
David J. Scott
d.scott@auckland.ac.nz
Department of Statistics, University of Auckland
Unix and Linux – p. 1/4
Outline
Unix basics
Command line structure
Using files and directories
System resources and printing
Unix shells
Shell programming
Unix and Linux – p. 2/4
Resources
Introduction to Unix by University Technology Services, Ohio
State University, available at
http://wks.uts.ohio-state.edu/unix_course/
Includes lecture slides, and notes in pdf and html formats
Unix commands reference card from University Information
Technology Services, available at
http://www.digilife.be/quickreferences/quickrefs.h
The official Bash Reference Manual from GNU
http://www.gnu.org/software/bash/manual/bash.html
The Bash FAQ
http://tiswww.case.edu/php/chet/bash/FAQ
Unix and Linux – p. 3/4
Resources
Tutorials
Tutorials from Imperial College
http://www.doc.ic.ac.uk/~wjk/UnixIntro/
Exercise Sheets 1 to 4 (1 has some IC-specific material)
Linux Mini-lesson
http://librenix.com/?inode=4052
Tutorials from linux.org
http://www.linux.org/lessons/
A Bash tutorial
http://www.hypexr.org/bash_tutorial.php
Unix and Linux – p. 4/4
Unix Philosophy
Multiuser system with multitasking
Tools available for common tasks
Flexibility and extendability
Designed by programmers for programmers
Unix and Linux – p. 5/4
Unix Structure
Unix and Linux – p. 6/4
Unix File System
/ root directory
/bin unix commands
/home/frank/, /home/lindab/, /home/rfunk/
user directories
Unix and Linux – p. 7/4
Unix Programs
Shell is the command line interpreter: just another program
A program or command interacts with the kernel, may be any of
a built in shell command
interpreted script
compiled object code file
Unix and Linux – p. 8/4
Getting Started
Login with user name and password
The command passwd only changes your password on the
local host machine
To change your password across the whole system use
yppasswd
Change your password as soon as you are given your
temporary password
logout logs the user off the system
exit leaves the shell
Unix and Linux – p. 9/4
Command Line Structure
A command has the form
command options arguments
Whitespace, that is space(s) or tab(s) separate parts of the
command line
An argument indicates the object on which the command
operates
An option modifies the command, usually starts with “-”
Options and syntax for a command are given on the “man
page” for the command
Commands to access the on-line manual
$ man command
$ man -k keyword
Unix and Linux – p. 10/4
Directory Commands
pwd print working directory
cd change working directory
no argument changes to home directory
.. move up one level
∼dscott change to home directory of user dscott
mkdir create a directory
rmdir remove directory
ls list directory contents
ls -l long listing
ls -a list all files (including those starting with “.”)
Unix and Linux – p. 11/4
Long Listing
Each line gives details on one file or directory
type field: d for directory, l for link
access permissions for owner, group and others
3 characters for each
read permission, write permission, executer permission
access is allowed if character (r, w, or x) appears, is
denied if character - appears
Permissions can be changed with chmod
Owner or group are changed with chown and chgrp
Unix and Linux – p. 12/4
Change Permissions
Command is chmod [options] filename
Use + and - with a single letter
u user (owner of file)
g group
o others
a all (includes, user, group and others)
Examples
chmod u+w filename gives user write permission
chmod g+r filename gives group read permission
chmod a-r filename ensures no-one can read the file
Can also use numeric representations for permissions
Unix and Linux – p. 13/4
Commands Dealing With Files
rm remove (delete) a file
cp move a file or directory
mv move a file, includes renaming
Great care is needed with rm
rm * will remove everything in your directory
mv can copy over an existing file (clobber the file)
Most people modify rm to be rm -i which asks before
removing files
Can still access the real rm as rm
Unix and Linux – p. 14/4
Display Commands
echo echo the text string to stdout (standard output
cat concatenate (list)
head display first 10 or specified number of lines of file
tail display last 10 or specified number of lines of file
more page through file
less page through file
When paging through a file, the space bar moves one page
down, enter moves one line down, b back one page, q quits,
/word searches for the specified word
Unix and Linux – p. 15/4
Processes
ps shows running processes
kill kills a process
kill -9 processID kills specified process
Unix and Linux – p. 16/4
Enquiries
Find out about users
who lists current users on the system
who am i information on command user
whoami user name of command user
Find out about programs
whereis location of program, e.g.
whereis R
which the file to be executed using that command, e.g.
which R
Unix and Linux – p. 17/4
Enquiries
Find out about the system
hostname machine being used
uname prints system information (has options)
uname -o operating system
uname -p processor
uname -a all the information
Unix and Linux – p. 18/4
Date
Find time and date information in various formats
date has options and formats (preceded by “+”)
date -u Greenwich mean time, or Universal Time
date +%a%t%D
date +%Y:%j
Unix and Linux – p. 19/4
Printing
CUPS, the common unix printing system includes both lp and
lpr
CUPS allows modification to output with -o option
Most useful is -o number-up=2
Also -o sides=two-sided-long-edge
Control print queues and jobs
lpq check entries in the print queue
lprm remove an entry from the print queue
Unix and Linux – p. 20/4
Printing
To print text on a postscript printer, mpage is useful. Options:
Multiple pages with -2, -4 etc
Header with -H
Don’t forget -P to send the result to the printer, not standard
output
Alternative is psnup. Options:
Multiple pages with -nup 4, -nup 6 etc
-d draw a box around pages (can specify width)
-l landscape pages (rotated 90◦
clockwise)
-r seascape pages (rotated 90◦
anticlockwise)
-f pages with width and height interchanged, not rotated
Unix and Linux – p. 21/4
Compression and Archiving
On CRAN under packages you will find files with the
extensions .tar.gz, and .tgz. What are these?
They are archived and compressed files
tar “tape archive and retrieval” combines multiple files
into one
gzip and gunzip compress and decompress files
Standard method of archiving
tar -cf texfiles.tar *.tex
gzip -9 texfiles.tar
gunzip texfiles.tar.gz
tar -xf texfiles.tar
Unix and Linux – p. 22/4
Compression and Archiving
Create texfiles.tar containing all files with extension .tex
Compress to form texfiles.tar.gz using best available
compression (-9)
Unzip to recover tar file
Extract contents of tar file
Other possibilities
tar -tf texfiles.tar
lists contents of tar file
tar -cf directory.tar directoryname
creates tar file containing contents of directory and all
subdirectories
Unix and Linux – p. 23/4
The bash Shell
bash is a modern shell derived from the Bourne shell sh
It is the default shell on Linux
It extends sh and includes commands originally in csh
In sh to execute commands in the file file.sh required
. file.sh, but bash allows source file.sh
sh allowed no aliases, you had to define functions,
bash includes the alias command
Unix and Linux – p. 24/4
Configuring the bash Shell
/etc/profile
global system configuration (for all users), controls
environmental variables and programs to be run when logging
in
/etc/bashrc
global system configuration (for all users), sets up aliases and
functions. May not be used, everything put in /etc/profile
∼/.bash_profile
local system configuration (for specific user), controls
environmental variables and programs to be run when starting
a bash shell
∼/.bashrc
local system configuration (for specfic user), sets up aliases
and functions, executed after /etc/bashrc
Unix and Linux – p. 25/4
Configuring the bash Shell
Set values of environment variables
DISPLAY the window being used
PRINTER your default printer
PAGER usually less
R_LIBS location of R packages
PATH search path when trying to find files or programs
Using bash, the syntax is
NAME=value; export NAME
export NAME=value
Unix and Linux – p. 26/4
A Sample .profile File
PATH=/usr/bin:/usr/local/bin/:.
export PATH
stty erase ˆH
PS1="{‘hostname‘ ‘whoami‘}"
stat12() { ssh -X -l dscott stat12.stat.auckland.ac.nz; }
umask 077
Set the PATH variable and export it
Set the backspace key to delete the preceding character
Set the prompt to include the name of the host machine and
my login name
Define a function which creates an alias for the command
stat12
An alternative definition using the alias command is
alias stat12=’ssh -X -l dscott stat12.stat.auckland.ac.nz’
Set the default permissions on files
Unix and Linux – p. 27/4
Job Control
To put a job in the background terminate the command with &
To stop a job use ˆZ
To put the job into the background use bg
To return a background job to the foreground use fg
To see what jobs are in the background use jobs
To kill job number n, use kill -9 %n
Unix and Linux – p. 28/4
History
Commands used are recorded if history (in tcsh) or
HISTSIZE (in bash) are >0
history nn
prints last nn commands
!!
repeats the last command
!string
repeats latest command starting with string
Unix and Linux – p. 29/4
Unix Features
Output redirection to a file
Input direction from a file
Piping
Terminology
stdin standard input to the program
normally from the keyboard
could be from a file or command
stdout standard output from the program
stderr standard error output
both usually to the terminal screen
could be to a file or command
Unix and Linux – p. 30/4
File Redirection
> redirect standard output to file
command > outfile
>> append standard output to file
command >> outfile
< input redirection from file
commmand < infile
| pipe output to another command
command1 | command2
Unix and Linux – p. 31/4
Quoting in Commands
 take the next character literally
’ ’ don’t allow any special meaning to characters
" " allow variable and command substitution
does not disable $ and 
‘command‘ substitute output of command into command line
works inside double quotes
Unix and Linux – p. 32/4
Wildcards
Simple pattern matches
? match a single character
* match any string of zero or more characters
[abc] match any of the enclosed characters
[a-z] match any character in the range a to z
[!def] match any characters not enclosed
Composite pattern matches where patternlist is a list of one or
more patterns separated by a ’|’.
?(pattern-list) matches zero or one occurrence
*(pattern-list) matches zero or more occurrences
+(pattern-list) matches one or more occurrences
Requires the shell option extglob to be set to on Unix and Linux – p. 33/4
Word Count
wc [options] file
Options
-c count bytes
-m count characters
-l count lines
-w count words
Unix and Linux – p. 34/4
Gnome Graphical User Interface
Galeon browser and file system explorer
Actions: Search for Files
Productivity software
Open Office: oowriter, oocalc, ooimpress
Gnu: abiword,gnumeric
KDE: kword
Workplace switcher
Explore yourself
Documentation
Quick introduction to Gnome at:
http://www.gnome.org/learn/
Gnome User Guide on the 782 Home Page
Unix and Linux – p. 35/4
Unix Tools
xfig
gimp (The Gnu Image Manipulation Program)
ImageMagick
ssh
xemacs
make
Create your own shell programs and put in your binaries
directory
Unix and Linux – p. 36/4
xfig
Invoke with xfig&
Allows drawing and editing of drawings
Vector graphics
Can save into different formats: eps, tex, gif, jpeg, png (not all
of which are vector graphics formats)
Diagram at top right shows button usage (note changes with
actions)
Look at manual under help
Used for diagrams in STATS 320
Unix and Linux – p. 37/4
GIMP
Invoke with gimp&
Can paint with gimp
Bitmapped or raster graphics
Can save in different formats, convert between formats
Read files produced by xfig and add additional elements
Convert back to xfig format (.fig) with pstoedit or transfig
Unix and Linux – p. 38/4
ImageMagick
Convert an image from one format to another (e.g. TIFF to
JPEG)
Resize, rotate, sharpen, color reduce, or add special effects to
an image
Create a montage of image thumbnails
Create a transparent image suitable for use on the Web
Turn a group of images into a GIF animation sequence
Create a composite image by combining several separate
images
Draw shapes or text on an image
Decorate an image with a border or frame
Describe the format and characteristics of an image
Unix and Linux – p. 39/4
Secure Shell
Log in to another computer
Invoke with
ssh computer name
Don’t need a password when using computers on the Statistics
network
May need resetting when systems change
Can login with another user name using
ssh -X -l username computer name
The -X option permits the use of X Windows applications
Unix and Linux – p. 40/4
Make
Used for regular tasks such as compilation and linking of
programs
Very useful for conversions, processing of LaTeX, cleaning up
directories
hardcopy4: $(FILENAME).pdf
acroread -toPostScript -size a4 -shrink -pairs $(FI
rm -f tempmpage.ps
mpage -P- -4 -R -ba4 temp.ps>tempmpage.ps
rm -f temp.ps
ps2pdf tempmpage.ps tempmpage.pdf
acroread tempmpage.pdf&
viewtex: $(FILENAME).tex
latex $(FILENAME)
dvips -o $(FILENAME).ps $(FILENAME).dvi
ps2pdf $(FILENAME).ps $(FILENAME).pdf
acroread $(FILENAME).pdf&
clean:
rm -f *.dvi *.aux *.log *.out *˜ temp* Unix and Linux – p. 41/4
Make
File Makefile contains the text shown on the previous slide
Usage is then when using tcsh
stat12/dscott10> setenv FILENAME Unix
stat12/dscott11> make viewtex
which produces a great deal of output in this case, or
stat12/dscott9> make clean
rm -f *.dvi *.aux *.log *.out *˜ temp*
When using the bash the only change is setting the
environment variable
[dscott@stat12 dscott]$ export FILENAME=Unix
Unix and Linux – p. 42/4
Binary files
Put in a directory /bin
Put /bin in your path
Make executable with chmod u+x filename
stat71/dscott9> more deltex
rm -i *.dvi *.log *.aux *˜
stat71/dscott10> more viewtex
latex $1
dvips -o $1.ps $1.dvi
gv $1.ps&
Works in every directory whereas Makefile is specific to the
directory in which it resides
Unix and Linux – p. 43/4

More Related Content

What's hot

101 3.4 use streams, pipes and redirects
101 3.4 use streams, pipes and redirects101 3.4 use streams, pipes and redirects
101 3.4 use streams, pipes and redirectsAcácio Oliveira
 
101 3.2 process text streams using filters
101 3.2 process text streams using filters101 3.2 process text streams using filters
101 3.2 process text streams using filtersAcácio Oliveira
 
Unix(introduction)
Unix(introduction)Unix(introduction)
Unix(introduction)meashi
 
UNIX Command Cheat Sheets
UNIX Command Cheat SheetsUNIX Command Cheat Sheets
UNIX Command Cheat SheetsPrashanth Kumar
 

What's hot (14)

101 3.4 use streams, pipes and redirects
101 3.4 use streams, pipes and redirects101 3.4 use streams, pipes and redirects
101 3.4 use streams, pipes and redirects
 
101 3.2 process text streams using filters
101 3.2 process text streams using filters101 3.2 process text streams using filters
101 3.2 process text streams using filters
 
Unix(introduction)
Unix(introduction)Unix(introduction)
Unix(introduction)
 
Unix practical file
Unix practical fileUnix practical file
Unix practical file
 
Prabu linux
Prabu linuxPrabu linux
Prabu linux
 
Linux commands
Linux commandsLinux commands
Linux commands
 
Basic Linux day 2
Basic Linux day 2Basic Linux day 2
Basic Linux day 2
 
Piping into-php
Piping into-phpPiping into-php
Piping into-php
 
Basic Linux day 1
Basic Linux day 1Basic Linux day 1
Basic Linux day 1
 
Unix Basics For Testers
Unix Basics For TestersUnix Basics For Testers
Unix Basics For Testers
 
Basic linux day 3
Basic linux day 3Basic linux day 3
Basic linux day 3
 
UNIX Command Cheat Sheets
UNIX Command Cheat SheetsUNIX Command Cheat Sheets
UNIX Command Cheat Sheets
 
Babitha.linux
Babitha.linuxBabitha.linux
Babitha.linux
 
Babitha.linux
Babitha.linuxBabitha.linux
Babitha.linux
 

Similar to Unix and Linux - The simple introduction

101 3.1 gnu and unix commands
101 3.1 gnu and unix commands101 3.1 gnu and unix commands
101 3.1 gnu and unix commandsAcácio Oliveira
 
Linux powerpoint
Linux powerpointLinux powerpoint
Linux powerpointbijanshr
 
Shell_Scripting.ppt
Shell_Scripting.pptShell_Scripting.ppt
Shell_Scripting.pptKiranMantri
 
Complete Guide for Linux shell programming
Complete Guide for Linux shell programmingComplete Guide for Linux shell programming
Complete Guide for Linux shell programmingsudhir singh yadav
 
8.1.intro unix
8.1.intro unix8.1.intro unix
8.1.intro unixsouthees
 
Linux file commands and shell scripts
Linux file commands and shell scriptsLinux file commands and shell scripts
Linux file commands and shell scriptsPrashantTechment
 
Linux commands and file structure
Linux commands and file structureLinux commands and file structure
Linux commands and file structureSreenatha Reddy K R
 
linux-lecture4.ppt
linux-lecture4.pptlinux-lecture4.ppt
linux-lecture4.pptLuigysToro
 
Nguyễn Vũ Hưng: Basic Linux Power Tools
Nguyễn Vũ Hưng: Basic Linux Power Tools Nguyễn Vũ Hưng: Basic Linux Power Tools
Nguyễn Vũ Hưng: Basic Linux Power Tools Vu Hung Nguyen
 
Karkha unix shell scritping
Karkha unix shell scritpingKarkha unix shell scritping
Karkha unix shell scritpingchockit88
 
Introduction to the linux command line.pdf
Introduction to the linux command line.pdfIntroduction to the linux command line.pdf
Introduction to the linux command line.pdfCesleySCruz
 
Unix Linux Commands Presentation 2013
Unix Linux Commands Presentation 2013Unix Linux Commands Presentation 2013
Unix Linux Commands Presentation 2013Wave Digitech
 
Linux Introduction (Commands)
Linux Introduction (Commands)Linux Introduction (Commands)
Linux Introduction (Commands)anandvaidya
 

Similar to Unix and Linux - The simple introduction (20)

101 3.1 gnu and unix commands
101 3.1 gnu and unix commands101 3.1 gnu and unix commands
101 3.1 gnu and unix commands
 
Linux powerpoint
Linux powerpointLinux powerpoint
Linux powerpoint
 
Shell_Scripting.ppt
Shell_Scripting.pptShell_Scripting.ppt
Shell_Scripting.ppt
 
Linux Commands
Linux CommandsLinux Commands
Linux Commands
 
58518522 study-aix
58518522 study-aix58518522 study-aix
58518522 study-aix
 
Complete Guide for Linux shell programming
Complete Guide for Linux shell programmingComplete Guide for Linux shell programming
Complete Guide for Linux shell programming
 
8.1.intro unix
8.1.intro unix8.1.intro unix
8.1.intro unix
 
Linux file commands and shell scripts
Linux file commands and shell scriptsLinux file commands and shell scripts
Linux file commands and shell scripts
 
Linux commands and file structure
Linux commands and file structureLinux commands and file structure
Linux commands and file structure
 
linux-lecture4.ppt
linux-lecture4.pptlinux-lecture4.ppt
linux-lecture4.ppt
 
Linux
LinuxLinux
Linux
 
Directories description
Directories descriptionDirectories description
Directories description
 
Nguyễn Vũ Hưng: Basic Linux Power Tools
Nguyễn Vũ Hưng: Basic Linux Power Tools Nguyễn Vũ Hưng: Basic Linux Power Tools
Nguyễn Vũ Hưng: Basic Linux Power Tools
 
Karkha unix shell scritping
Karkha unix shell scritpingKarkha unix shell scritping
Karkha unix shell scritping
 
Linux
LinuxLinux
Linux
 
Introduction to the linux command line.pdf
Introduction to the linux command line.pdfIntroduction to the linux command line.pdf
Introduction to the linux command line.pdf
 
Nithi
NithiNithi
Nithi
 
Unix Linux Commands Presentation 2013
Unix Linux Commands Presentation 2013Unix Linux Commands Presentation 2013
Unix Linux Commands Presentation 2013
 
lec1.docx
lec1.docxlec1.docx
lec1.docx
 
Linux Introduction (Commands)
Linux Introduction (Commands)Linux Introduction (Commands)
Linux Introduction (Commands)
 

More from Amity University Noida

Greenhouse Effect and Global Carbon Footprint
Greenhouse Effect and Global Carbon FootprintGreenhouse Effect and Global Carbon Footprint
Greenhouse Effect and Global Carbon FootprintAmity University Noida
 
The definitive presentation on Black Holes (School Level)
The definitive presentation on Black Holes (School Level)The definitive presentation on Black Holes (School Level)
The definitive presentation on Black Holes (School Level)Amity University Noida
 
Hello git - a soft introduction to git (Talk Slides)
Hello git - a soft introduction to git (Talk Slides) Hello git - a soft introduction to git (Talk Slides)
Hello git - a soft introduction to git (Talk Slides) Amity University Noida
 

More from Amity University Noida (6)

Impossible Pictures
Impossible PicturesImpossible Pictures
Impossible Pictures
 
Greenhouse Effect and Global Carbon Footprint
Greenhouse Effect and Global Carbon FootprintGreenhouse Effect and Global Carbon Footprint
Greenhouse Effect and Global Carbon Footprint
 
The definitive presentation on Black Holes (School Level)
The definitive presentation on Black Holes (School Level)The definitive presentation on Black Holes (School Level)
The definitive presentation on Black Holes (School Level)
 
Sustainable Development 2018
Sustainable Development 2018Sustainable Development 2018
Sustainable Development 2018
 
Faith, Belief and Environment
Faith, Belief and EnvironmentFaith, Belief and Environment
Faith, Belief and Environment
 
Hello git - a soft introduction to git (Talk Slides)
Hello git - a soft introduction to git (Talk Slides) Hello git - a soft introduction to git (Talk Slides)
Hello git - a soft introduction to git (Talk Slides)
 

Recently uploaded

Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsPrecisely
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 

Recently uploaded (20)

Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power Systems
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 

Unix and Linux - The simple introduction

  • 1. Unix and Linux David J. Scott d.scott@auckland.ac.nz Department of Statistics, University of Auckland Unix and Linux – p. 1/4
  • 2. Outline Unix basics Command line structure Using files and directories System resources and printing Unix shells Shell programming Unix and Linux – p. 2/4
  • 3. Resources Introduction to Unix by University Technology Services, Ohio State University, available at http://wks.uts.ohio-state.edu/unix_course/ Includes lecture slides, and notes in pdf and html formats Unix commands reference card from University Information Technology Services, available at http://www.digilife.be/quickreferences/quickrefs.h The official Bash Reference Manual from GNU http://www.gnu.org/software/bash/manual/bash.html The Bash FAQ http://tiswww.case.edu/php/chet/bash/FAQ Unix and Linux – p. 3/4
  • 4. Resources Tutorials Tutorials from Imperial College http://www.doc.ic.ac.uk/~wjk/UnixIntro/ Exercise Sheets 1 to 4 (1 has some IC-specific material) Linux Mini-lesson http://librenix.com/?inode=4052 Tutorials from linux.org http://www.linux.org/lessons/ A Bash tutorial http://www.hypexr.org/bash_tutorial.php Unix and Linux – p. 4/4
  • 5. Unix Philosophy Multiuser system with multitasking Tools available for common tasks Flexibility and extendability Designed by programmers for programmers Unix and Linux – p. 5/4
  • 6. Unix Structure Unix and Linux – p. 6/4
  • 7. Unix File System / root directory /bin unix commands /home/frank/, /home/lindab/, /home/rfunk/ user directories Unix and Linux – p. 7/4
  • 8. Unix Programs Shell is the command line interpreter: just another program A program or command interacts with the kernel, may be any of a built in shell command interpreted script compiled object code file Unix and Linux – p. 8/4
  • 9. Getting Started Login with user name and password The command passwd only changes your password on the local host machine To change your password across the whole system use yppasswd Change your password as soon as you are given your temporary password logout logs the user off the system exit leaves the shell Unix and Linux – p. 9/4
  • 10. Command Line Structure A command has the form command options arguments Whitespace, that is space(s) or tab(s) separate parts of the command line An argument indicates the object on which the command operates An option modifies the command, usually starts with “-” Options and syntax for a command are given on the “man page” for the command Commands to access the on-line manual $ man command $ man -k keyword Unix and Linux – p. 10/4
  • 11. Directory Commands pwd print working directory cd change working directory no argument changes to home directory .. move up one level ∼dscott change to home directory of user dscott mkdir create a directory rmdir remove directory ls list directory contents ls -l long listing ls -a list all files (including those starting with “.”) Unix and Linux – p. 11/4
  • 12. Long Listing Each line gives details on one file or directory type field: d for directory, l for link access permissions for owner, group and others 3 characters for each read permission, write permission, executer permission access is allowed if character (r, w, or x) appears, is denied if character - appears Permissions can be changed with chmod Owner or group are changed with chown and chgrp Unix and Linux – p. 12/4
  • 13. Change Permissions Command is chmod [options] filename Use + and - with a single letter u user (owner of file) g group o others a all (includes, user, group and others) Examples chmod u+w filename gives user write permission chmod g+r filename gives group read permission chmod a-r filename ensures no-one can read the file Can also use numeric representations for permissions Unix and Linux – p. 13/4
  • 14. Commands Dealing With Files rm remove (delete) a file cp move a file or directory mv move a file, includes renaming Great care is needed with rm rm * will remove everything in your directory mv can copy over an existing file (clobber the file) Most people modify rm to be rm -i which asks before removing files Can still access the real rm as rm Unix and Linux – p. 14/4
  • 15. Display Commands echo echo the text string to stdout (standard output cat concatenate (list) head display first 10 or specified number of lines of file tail display last 10 or specified number of lines of file more page through file less page through file When paging through a file, the space bar moves one page down, enter moves one line down, b back one page, q quits, /word searches for the specified word Unix and Linux – p. 15/4
  • 16. Processes ps shows running processes kill kills a process kill -9 processID kills specified process Unix and Linux – p. 16/4
  • 17. Enquiries Find out about users who lists current users on the system who am i information on command user whoami user name of command user Find out about programs whereis location of program, e.g. whereis R which the file to be executed using that command, e.g. which R Unix and Linux – p. 17/4
  • 18. Enquiries Find out about the system hostname machine being used uname prints system information (has options) uname -o operating system uname -p processor uname -a all the information Unix and Linux – p. 18/4
  • 19. Date Find time and date information in various formats date has options and formats (preceded by “+”) date -u Greenwich mean time, or Universal Time date +%a%t%D date +%Y:%j Unix and Linux – p. 19/4
  • 20. Printing CUPS, the common unix printing system includes both lp and lpr CUPS allows modification to output with -o option Most useful is -o number-up=2 Also -o sides=two-sided-long-edge Control print queues and jobs lpq check entries in the print queue lprm remove an entry from the print queue Unix and Linux – p. 20/4
  • 21. Printing To print text on a postscript printer, mpage is useful. Options: Multiple pages with -2, -4 etc Header with -H Don’t forget -P to send the result to the printer, not standard output Alternative is psnup. Options: Multiple pages with -nup 4, -nup 6 etc -d draw a box around pages (can specify width) -l landscape pages (rotated 90◦ clockwise) -r seascape pages (rotated 90◦ anticlockwise) -f pages with width and height interchanged, not rotated Unix and Linux – p. 21/4
  • 22. Compression and Archiving On CRAN under packages you will find files with the extensions .tar.gz, and .tgz. What are these? They are archived and compressed files tar “tape archive and retrieval” combines multiple files into one gzip and gunzip compress and decompress files Standard method of archiving tar -cf texfiles.tar *.tex gzip -9 texfiles.tar gunzip texfiles.tar.gz tar -xf texfiles.tar Unix and Linux – p. 22/4
  • 23. Compression and Archiving Create texfiles.tar containing all files with extension .tex Compress to form texfiles.tar.gz using best available compression (-9) Unzip to recover tar file Extract contents of tar file Other possibilities tar -tf texfiles.tar lists contents of tar file tar -cf directory.tar directoryname creates tar file containing contents of directory and all subdirectories Unix and Linux – p. 23/4
  • 24. The bash Shell bash is a modern shell derived from the Bourne shell sh It is the default shell on Linux It extends sh and includes commands originally in csh In sh to execute commands in the file file.sh required . file.sh, but bash allows source file.sh sh allowed no aliases, you had to define functions, bash includes the alias command Unix and Linux – p. 24/4
  • 25. Configuring the bash Shell /etc/profile global system configuration (for all users), controls environmental variables and programs to be run when logging in /etc/bashrc global system configuration (for all users), sets up aliases and functions. May not be used, everything put in /etc/profile ∼/.bash_profile local system configuration (for specific user), controls environmental variables and programs to be run when starting a bash shell ∼/.bashrc local system configuration (for specfic user), sets up aliases and functions, executed after /etc/bashrc Unix and Linux – p. 25/4
  • 26. Configuring the bash Shell Set values of environment variables DISPLAY the window being used PRINTER your default printer PAGER usually less R_LIBS location of R packages PATH search path when trying to find files or programs Using bash, the syntax is NAME=value; export NAME export NAME=value Unix and Linux – p. 26/4
  • 27. A Sample .profile File PATH=/usr/bin:/usr/local/bin/:. export PATH stty erase ˆH PS1="{‘hostname‘ ‘whoami‘}" stat12() { ssh -X -l dscott stat12.stat.auckland.ac.nz; } umask 077 Set the PATH variable and export it Set the backspace key to delete the preceding character Set the prompt to include the name of the host machine and my login name Define a function which creates an alias for the command stat12 An alternative definition using the alias command is alias stat12=’ssh -X -l dscott stat12.stat.auckland.ac.nz’ Set the default permissions on files Unix and Linux – p. 27/4
  • 28. Job Control To put a job in the background terminate the command with & To stop a job use ˆZ To put the job into the background use bg To return a background job to the foreground use fg To see what jobs are in the background use jobs To kill job number n, use kill -9 %n Unix and Linux – p. 28/4
  • 29. History Commands used are recorded if history (in tcsh) or HISTSIZE (in bash) are >0 history nn prints last nn commands !! repeats the last command !string repeats latest command starting with string Unix and Linux – p. 29/4
  • 30. Unix Features Output redirection to a file Input direction from a file Piping Terminology stdin standard input to the program normally from the keyboard could be from a file or command stdout standard output from the program stderr standard error output both usually to the terminal screen could be to a file or command Unix and Linux – p. 30/4
  • 31. File Redirection > redirect standard output to file command > outfile >> append standard output to file command >> outfile < input redirection from file commmand < infile | pipe output to another command command1 | command2 Unix and Linux – p. 31/4
  • 32. Quoting in Commands take the next character literally ’ ’ don’t allow any special meaning to characters " " allow variable and command substitution does not disable $ and ‘command‘ substitute output of command into command line works inside double quotes Unix and Linux – p. 32/4
  • 33. Wildcards Simple pattern matches ? match a single character * match any string of zero or more characters [abc] match any of the enclosed characters [a-z] match any character in the range a to z [!def] match any characters not enclosed Composite pattern matches where patternlist is a list of one or more patterns separated by a ’|’. ?(pattern-list) matches zero or one occurrence *(pattern-list) matches zero or more occurrences +(pattern-list) matches one or more occurrences Requires the shell option extglob to be set to on Unix and Linux – p. 33/4
  • 34. Word Count wc [options] file Options -c count bytes -m count characters -l count lines -w count words Unix and Linux – p. 34/4
  • 35. Gnome Graphical User Interface Galeon browser and file system explorer Actions: Search for Files Productivity software Open Office: oowriter, oocalc, ooimpress Gnu: abiword,gnumeric KDE: kword Workplace switcher Explore yourself Documentation Quick introduction to Gnome at: http://www.gnome.org/learn/ Gnome User Guide on the 782 Home Page Unix and Linux – p. 35/4
  • 36. Unix Tools xfig gimp (The Gnu Image Manipulation Program) ImageMagick ssh xemacs make Create your own shell programs and put in your binaries directory Unix and Linux – p. 36/4
  • 37. xfig Invoke with xfig& Allows drawing and editing of drawings Vector graphics Can save into different formats: eps, tex, gif, jpeg, png (not all of which are vector graphics formats) Diagram at top right shows button usage (note changes with actions) Look at manual under help Used for diagrams in STATS 320 Unix and Linux – p. 37/4
  • 38. GIMP Invoke with gimp& Can paint with gimp Bitmapped or raster graphics Can save in different formats, convert between formats Read files produced by xfig and add additional elements Convert back to xfig format (.fig) with pstoedit or transfig Unix and Linux – p. 38/4
  • 39. ImageMagick Convert an image from one format to another (e.g. TIFF to JPEG) Resize, rotate, sharpen, color reduce, or add special effects to an image Create a montage of image thumbnails Create a transparent image suitable for use on the Web Turn a group of images into a GIF animation sequence Create a composite image by combining several separate images Draw shapes or text on an image Decorate an image with a border or frame Describe the format and characteristics of an image Unix and Linux – p. 39/4
  • 40. Secure Shell Log in to another computer Invoke with ssh computer name Don’t need a password when using computers on the Statistics network May need resetting when systems change Can login with another user name using ssh -X -l username computer name The -X option permits the use of X Windows applications Unix and Linux – p. 40/4
  • 41. Make Used for regular tasks such as compilation and linking of programs Very useful for conversions, processing of LaTeX, cleaning up directories hardcopy4: $(FILENAME).pdf acroread -toPostScript -size a4 -shrink -pairs $(FI rm -f tempmpage.ps mpage -P- -4 -R -ba4 temp.ps>tempmpage.ps rm -f temp.ps ps2pdf tempmpage.ps tempmpage.pdf acroread tempmpage.pdf& viewtex: $(FILENAME).tex latex $(FILENAME) dvips -o $(FILENAME).ps $(FILENAME).dvi ps2pdf $(FILENAME).ps $(FILENAME).pdf acroread $(FILENAME).pdf& clean: rm -f *.dvi *.aux *.log *.out *˜ temp* Unix and Linux – p. 41/4
  • 42. Make File Makefile contains the text shown on the previous slide Usage is then when using tcsh stat12/dscott10> setenv FILENAME Unix stat12/dscott11> make viewtex which produces a great deal of output in this case, or stat12/dscott9> make clean rm -f *.dvi *.aux *.log *.out *˜ temp* When using the bash the only change is setting the environment variable [dscott@stat12 dscott]$ export FILENAME=Unix Unix and Linux – p. 42/4
  • 43. Binary files Put in a directory /bin Put /bin in your path Make executable with chmod u+x filename stat71/dscott9> more deltex rm -i *.dvi *.log *.aux *˜ stat71/dscott10> more viewtex latex $1 dvips -o $1.ps $1.dvi gv $1.ps& Works in every directory whereas Makefile is specific to the directory in which it resides Unix and Linux – p. 43/4