A Crash Course on UNIX



Similar documents
Basic C Shell. helpdesk@stat.rice.edu. 11th August 2003

Cisco Networking Academy Program Curriculum Scope & Sequence. Fundamentals of UNIX version 2.0 (July, 2002)

Unix Shell Scripts. Contents. 1 Introduction. Norman Matloff. July 30, Introduction 1. 2 Invoking Shell Scripts 2

Hands-On UNIX Exercise:

HP-UX Essentials and Shell Programming Course Summary

Unix Sampler. PEOPLE whoami id who

Fred Hantelmann LINUX. Start-up Guide. A self-contained introduction. With 57 Figures. Springer

Unix the Bare Minimum

Command Line - Part 1

AN INTRODUCTION TO UNIX

Linux command line. An introduction to the Linux command line for genomics. Susan Fairley

UNIX / Linux commands Basic level. Magali COTTEVIEILLE - September 2009

A Brief Introduction to the Use of Shell Variables

grep, awk and sed three VERY useful command-line utilities Matt Probert, Uni of York grep = global regular expression print

Tutorial 0A Programming on the command line

Lecture 4: Writing shell scripts

Lab 1: Introduction to C, ASCII ART and the Linux Command Line Environment

CS 2112 Lab: Version Control

ICS 351: Today's plan

Unix Guide. Logo Reproduction. School of Computing & Information Systems. Colours red and black on white backgroun

The Linux Operating System and Linux-Related Issues

Shell Scripts (1) For example: #!/bin/sh If they do not, the user's current shell will be used. Any Unix command can go in a shell script

Linux Overview. Local facilities. Linux commands. The vi (gvim) editor

A UNIX/Linux in a nutshell

UNIX, Shell Scripting and Perl Introduction

Tutorial Guide to the IS Unix Service

UNIX Basics. Ian Darwin TCP Informatics January, Presented from a Mac using Apple s Keynote presentation software

Command Line Crash Course For Unix

Introduction to Mac OS X

Unix Scripts and Job Scheduling

L01 Introduction to the Unix OS

Thirty Useful Unix Commands

An Introduction to the Linux Command Shell For Beginners

Week Overview. Running Live Linux Sending from command line scp and sftp utilities

CS 103 Lab Linux and Virtual Machines

Agenda. Using HPC Wales 2

Command-Line Operations : The Shell. Don't fear the command line...

TNM093 Practical Data Visualization and Virtual Reality Laboratory Platform

Linux System Administration on Red Hat

An A-Z Index of the Apple OS X command line (TERMINAL) The tcsh command shell of Darwin (the open source core of OSX)

CMSC 216 UNIX tutorial Fall 2010

Advanced Bash Scripting. Joshua Malone

Introduction to Unix Tutorial

Introduction to Shell Programming

Open Source Computational Fluid Dynamics

Birmingham Environment for Academic Research. Introduction to Linux Quick Reference Guide. Research Computing Team V1.0

UNIX Intro and Basic C shell Scripting

1 Intro 1. 2 man - Accessing On-Line Manual Pages 1. 3 pwd - Print the Working Directory 2. 4 cd - Changing Directory 2

University of Toronto

CSIL MiniCourses. Introduction To Unix (I) John Lekberg Sean Hogan Cannon Matthews Graham Smith. Updated on:

CS2720 Practical Software Development

CPSC2800: Linux Hands-on Lab #3 Explore Linux file system and file security. Project 3-1

Introduction to Shell Scripting

USEFUL UNIX COMMANDS

CS Unix Tools & Scripting Lecture 9 Shell Scripting

Syntax: cd <Path> Or cd $<Custom/Standard Top Name>_TOP (In CAPS)

Hadoop Hands-On Exercises

Bash shell programming Part II Control statements

1 Basic commands. 2 Terminology. CS61B, Fall 2009 Simple UNIX Commands P. N. Hilfinger

The Linux Operating System

Introduction to the UNIX Operating System on IT Systems

LPI certification 101 exam prep, Part 1

LSN 10 Linux Overview

Basic Linux & Package Management. Original slides from GTFO Security

Beginners Shell Scripting for Batch Jobs

Sophos Anti-Virus for Linux configuration guide. Product version: 9

Linux System Administration

Learn Perl by Example - Perl Handbook for Beginners - Basics of Perl Scripting Language

Running your first Linux Program

GNU/Linux Command Line Tools Summary

Introduction to Linux and Cluster Basics for the CCR General Computing Cluster

Lecture 4. Regular Expressions grep and sed intro

Systems Programming & Scripting

Installation & Configuration Guide for Solaris 8

Setting up PostgreSQL

Stata R Release 13 Installation Guide

An Introduction to Using the Command Line Interface (CLI) to Work with Files and Directories

Unix Primer - Basic Commands In the Unix Shell

Cygwin command line windows. Get that Linux feeling - on Windows

List of FTP commands for the Microsoft command-line FTP client

SWsoft Plesk 8.3 for Linux/Unix Backup and Restore Utilities

Automated Offsite Backup with rdiff-backup

Lecture 18 Regular Expressions

SSH Connections MACs the MAC XTerm application can be used to create an ssh connection, no utility is needed.

Unix and Linux. David J. Scott. Department of Statistics, University of Auckland. Unix and Linux p. 1/4

Getting Started with Mplus Version 7.31 Demo for Mac OS X and Linux

SWsoft Plesk 8.2 for Linux/Unix Backup and Restore Utilities. Administrator's Guide

Hadoop Hands-On Exercises

SAS 9.4 In-Database Products

Outline. Unix shells Bourne-again Shell (bash) Interacting with bash Basic scripting References

Operating System Structure

L04 C Shell Scripting - Part 2

SSH and Basic Commands

How To Use The Librepo Software On A Linux Computer (For Free)

LECTURE-7. Introduction to DOS. Introduction to UNIX/LINUX OS. Introduction to Windows. Topics:

UNIX Tutorial for Beginners

Introduction to. UNIX Bob Booth December 2004 AP-UNIX2. University of Sheffield

Windows PowerShell Essentials

Plesk 8.0 for Linux/UNIX Backup and Restore Utilities

UNIX Comes to the Rescue: A Comparison between UNIX SAS and PC SAS

Transcription:

A Crash Course on UNIX UNIX is an "operating system". Interface between user and data stored on computer. A Windows-style interface is not required. Many flavors of UNIX (and windows interfaces). Solaris, Mandrake, RedHat (fvwm, Gnome, KDE),... Most UNIX users use "shells" (or "xterms"). UNIX windows systems do provide some Microsoft Windows functionality.

The Shell A shell is a command-line interface to UNIX. Also many flavors, e.g. sh, bash, csh, tcsh. The shell provides commands and functionality beyond the basic UNIX tools. E.g., wildcards, shell variables, loop control, etc. For this tutorial, examples use tcsh in RedHat Linux running Gnome. Differences are minor for the most part...

Basic Commands You need these to survive: ls, cd, cp, mkdir, mv. Typically these are UNIX (not shell) commands. They are actually programs that someone has written. Most commands such as these accept (or require) "arguments". E.g. ls -a [show all files, incl. "dot files"] mkdir ASTR688 [create a directory] cp myfile backup [copy a file] See the handout for a list of more commands.

A Word About Directories Use cd to change directories. By default you start in your home directory. E.g. /home/dcr Handy abbreviations: Home directory: ~ Someone else's home directory: ~user Current directory:. Parent directory:..

Shortcuts To return to your home directory: cd To return to the previous directory: cd - In tcsh, with filename completion (on by default): Press TAB to complete filenames as you type. Press Ctrl-D to print a list of filenames matching what you have typed so far. Completion works with commands and variables too! Use,, Ctrl-A, & Ctrl-E to edit previous lines.

Man Pages To see all possible options to a command, use the man command, e.g. man mv. WARNING: the man pages are very terse... Not for the novice; get a book instead, or go surfing. You can search the man pages by keyword with the -k option. E.g. man -k rename Sometimes a command provides its own help.

Wildcards Wildcards provide handy filename substitution. E.g. ls *.c [list all files with extension ".c"] In tcsh, square brackets substitute for a range. E.g. cp obs0[0-9].fits tmp [copy first 10 FITS files] Curly brackets can be used to repeat patterns. E.g. a{b,c,d}e is shorthand for abe ace ade Use \ or single quotes (') to disable substitution. E.g. cd Data\[Oct01\] or cd 'Data[Oct01]'

Stream Redirection Normally commands expect to receive input from the keyboard and/or send output to the screen. Special redirection symbols can override this. E.g. ls > files.txt [send listing to file] mail dcr < hwk [mail file to user dcr] ls -l more [pause listing by screenfuls] There are many other examples: see handout. WARNING: the syntax is very shell dependent!

Shell Variables & Aliases You can store information in a shell variable. E.g. set work = /home/dcr/work To access the info, prepend a dollar sign ($). E.g. cd $work Shell variables are local to the shell; environment variables are inherited by new shells and can even be accessed internally by programs. E.g. setenv WORK /home/dcr/work

Shell Variables & Aliases, Cont'd There are certain special variables. E.g. PATH contains a list of directories to search for commands Aliases allow you to define new commands. E.g. alias rm rm -i [make rm ask for confirmation] Variables and aliases that you use all the time can be defined in your "startup" file. E.g. in tcsh, ~/.tcshrc is your startup script

Command Substitution In tcsh, you can use the result of a command as part of a command. E.g. setenv OS `uname` Anything inside backward single quotes is first evaluated in its own shell, and the result is returned as a string of one or more words. This is very handy in scripts and in conjunction with tools like sed and awk.

A Quick Word on Editors There are many text editors to choose from. E.g. vi, emacs, pico, etc. To create scripts or programs, you will need to learn how to use an editor! Also essential if you want to use formatting tools such as LaTeX, etc. Windows systems often have good GUI editors. Note you can use cat or more to show file data.

sed The "stream editor" (sed) is a useful tool for changing the contents of a file (or stream). E.g. sed s/apples/oranges/ myfile.txt will change the first occurrence of "apples" on each line of myfile.txt into "oranges". To change every occurrence, do the following: sed s/apples/oranges/g myfile.txt. sed is great in scripts, but it can also be used from the command line. E.g., in conjunction with the foreach command, it's a handy way to rename lots of files, like all *.JPEG files to *.jpg (EFTS).

awk awk is a powerful "pattern scanning and processing" language. Use it to print a column of a file: E.g. awk '{print $2}' myfile.txt [print 2 nd column] Use it to do math: E.g. awk '{print $1+$2}' myfile.txt [add columns] Use it as a calculator: E.g. echo '' awk '{print sqrt(2)}'

awk, cont'd You can write entire programs in awk: E.g. awk '/error/{print $0; n += 1} END {print n}' myfile.txt [counts and displays lines containing "error" in file] Like tcsh itself, awk syntax is reminscent of the programing language C. awk, sed, wildcards, shell variables, stream redirection, and command substitution enable the creation of very sophisticated tcsh scripts...

Scripts A script is a sequence of shell commands, usually stored in a file and either sourced or executed like a program. Here's a simple example: foreach file (*) if (-d $file) then echo $file is a directory endif end To aid with scripting, tcsh has a number of builtin commands, such as foreach, if, while, etc.

Scripts, cont'd A special variable called argv is defined inside a script (shell). It contains any arguments passed to the script (shell). E.g. echo $argv [show all arguments] echo $argv[2] [show the 2 nd argument] echo $#argv [show the number of args] You can do integer math within a script using @. E.g. set x = 0; @ x = $x + 1; echo $x [good for loops!]

What We Didn't Cover File permissions (chmod) Managing jobs (ps, nice, kill) Printing (lpr) Remote connections (ssh, scp) System administration (not for the faint of heart) And lots of other stuff! See the handout for web tutorials, etc.