Introduction to UNIX Directory structure and navigation

Slides:



Advertisements
Similar presentations
CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
Advertisements

Now, return to the Unix Unix shells: Subshells--- Variable---1. Local 2. Environmental.
Linux+ Guide to Linux Certification, Second Edition
Guide To UNIX Using Linux Third Edition
Lecture 02CS311 – Operating Systems 1 1 CS311 – Lecture 02 Outline UNIX/Linux features – Redirection – pipes – Terminating a command – Running program.
Introduction to UNIX GPS Processing and Analysis with GAMIT/GLOBK/TRACK T. Herring, R. King. M. Floyd – MIT UNAVCO, Boulder - July 8-12, 2013 Directory.
Unix Filters Text processing utilities. Filters Filter commands – Unix commands that serve dual purposes: –standalone –used with other commands and pipes.
Shell Script Examples.
Introduction to Linux Workshop February Introduction Rob Lane & The HPC Support Team Research Computing Services CUIT.
Advanced File Processing
Lesson 7-Creating and Changing Directories. Overview Using directories to create order. Managing files in directories. Using pathnames to manage files.
Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell.
Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell.
Chapter Four UNIX File Processing. 2 Lesson A Extracting Information from Files.
Guide To UNIX Using Linux Fourth Edition
Introduction to Unix (CA263) File Processing. Guide to UNIX Using Linux, Third Edition 2 Objectives Explain UNIX and Linux file processing Use basic file.
The UNIX Shell. The Shell Program that constantly runs at terminal after a user has logged in. Prompts the user and waits for user input. Interprets command.
Linux+ Guide to Linux Certification, Third Edition
CS 403: Programming Languages Fall 2004 Department of Computer Science University of Alabama Joel Jones.
Session 2 Wharton Summer Tech Camp Basic Unix. Agenda Cover basic UNIX commands and useful functions.
Week 3 Exploring Linux Filesystems. Objectives  Understand and navigate the Linux directory structure using relative and absolute pathnames  Describe.
OPERATING SYSTEMS DESIGN UNIX BASICS & SHELL SCRIPTING.
Advanced File Processing. 2 Objectives Use the pipe operator to redirect the output of one command to another command Use the grep command to search for.
UNIX Shell Script (1) Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology
Chapter Five Advanced File Processing Guide To UNIX Using Linux Fourth Edition Chapter 5 Unix (34 slides)1 CTEC 110.
Chapter Five Advanced File Processing. 2 Objectives Use the pipe operator to redirect the output of one command to another command Use the grep command.
Lesson 9-Setting and Using Permissions. Overview Describing file permissions. Using execute permissions with a file. Changing file permissions using mnemonics.
Introduction to Unix – CS 21 Lecture 12. Lecture Overview A few more bash programming tricks The here document Trapping signals in bash cut and tr sed.
ITR3 lecture 6: intoduction to UNIX Thomas Krichel
INFO 320 Server Technology I Week 5 Shell environments and scripting 1INFO 320 week 5.
Chapter Five Advanced File Processing. 2 Lesson A Selecting, Manipulating, and Formatting Information.
Introduction to Programming Using C An Introduction to Operating Systems.
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
– Introduction to the Shell 1/21/2016 Introduction to the Shell – Session Introduction to the Shell – Session 3 · Job control · Start,
Linux+ Guide to Linux Certification, Second Edition Chapter 4 Exploring Linux Filesystems.
ORAFACT Text Processing. ORAFACT Searching Inside Files grep - searches for patterns within files grep [options] [[-e] pattern] filename [...] -n shows.
CS 403: Programming Languages Lecture 20 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
Unix Lab Fall Shell Scripting ●Through the shell (LXTerminal) you can: ●Run programs. ●Interact with the file system. ●Change settings. ●Send/receive.
Learning Unix/Linux Based on slides from: Eric Bishop.
INTRODUCTION TO SHELL SCRIPTING By Byamukama Frank
Filters and Utilities. Notes: This is a simple overview of the filtering capability Some of these commands are very powerful ▫Only showing some of the.
Working with command-line systems and GAMIT/GLOBK M. A. Floyd T. A. Herring Massachusetts Institute of Technology GAMIT/GLOBK/TRACK Short Course for GPS.
CS 350 Lecture 3 UNIX/Linux Shells by İlker Korkmaz and Kaya Oğuz.
Tutorial of Unix Command & shell scriptS 5027
Lesson 5-Exploring Utilities
Working with command-line systems and GAMIT/GLOBK
Commands Basic syntax of shell commands UNIX or shell commands have a basic structure command -options target command comes first (such as cd or ls) any.
Linux Commands Help HANDS ON TRAINING Author: Muhammad Laique
The UNIX Shell Learning Objectives:
Working with command-line systems and GAMIT/GLOBK
Part 1: Basic Commands/Utilities
Some Linux Commands.
Shell Scripting March 1st, 2004 Class Meeting 7.
Shell Script Assignment 1.
PROGRAMMING THE BASH SHELL PART IV by İlker Korkmaz and Kaya Oğuz
CSE 303 Concepts and Tools for Software Development
Tutorial of Unix Command & shell scriptS 5027
Basic UNIX OLC Training.
Introduction to UNIX.
Tutorial of Unix Command & shell scriptS 5027
Working with command-line systems and GAMIT/GLOBK
John Carelli, Instructor Kutztown University
Guide To UNIX Using Linux Third Edition
Tutorial of Unix Command & shell scriptS 5027
Chapter Four UNIX File Processing.
Working with command-line systems and GAMIT/GLOBK
Linux Shell Script Programming
Chapter 3 The UNIX Shells
Working with command-line systems and GAMIT/GLOBK
Presentation transcript:

Introduction to UNIX Directory structure and navigation Using a command line Commands to know Introduction to shell scripts GPS Processing and Analysis with GAMIT/GLOBK/TRACK M. Floyd – MIT Baku, Azerbaijan – September 8-12, 2014

Quick poll Who is using what type of operating system? Linux (flavor?) Mac OS X Windows Who has installed the software successfully? Who has run the example successfully?

Directory structure and navigation

Directory structures One must be familiar with the layout of files and directories (or “folders”) Once one has a mental “map” of the directory structure, navigating between directories and finding files is easier Think of it as a filing cabinet or family tree / 1a 2a 2b 3a 3b 1b 2c 1c 2d 3c 3d

Directory structures Top-level (“root”) directory (“/” on UNIX, “C:\” on Windows, etc.) User’s current working directory is referred to by the shorthand “.” [period] The “parent” directory is one level above the current working directory in the hierarchy Parent directory is referred to by the shorthand “..” [double period] / 1a 2a 2b 3a 3b 1b 2c 1c 2d 3c 3d

Changing directory Once user knows where they are with “mental map” of directory structure, move around. We can move up or down the hierarchy but not sideways. cd / Takes user to top-level (“root”) directory cd 1b Takes user to “1b” directory in first level (move down hierarchy) cd 2c Takes user to “2c” directory in second level, below “1b” (move down hierarchy) cd 2d Unknown directory. Why? User attempting to move sideways but “2c” not connected directly to “2d”. / 1a 2a 2b 3a 3b 1b 2c 1c 2d 3c 3d Think of moving within the directory structure like a family tree where you can only move along direct blood lines, i.e. parent to child, child to parent, parent to “grand”-parent, etc. but not brother to sister, cousin to cousin or aunt to nephew.

Absolute paths To move back up the hierarchy to “2d”, one may explicitly start from the top level, e.g. cd / cd 1c cd 2d or, combined, simply cd /1c/2d Directories are separated by forward slashes / 1a 2a 2b 3a 3b 1b 2c 1c 2d 3c 3d

Relative paths Or: Move back up to “1b” Move back up to “/” cd .. Move back up to “/” Move down to “1c” cd 1c Move down to “2d” cd 2d Or, combined, simply: cd ../../1c/2d / 1a 2a 2b 3a 3b 1b 2c 1c 2d 3c 3d

Using a command line

UNIX commands Basic syntax is: <command> <options> <argument(s)> <command> is the program to run, including path if not included in PATH environment variable (more in a couple of slides…) <options> are usually prepended by a dash (e.g. -a) <argument(s)> are usually input or output files to work on Commands may or may not have options or expect arguments

Basic commands cd pwd ls Use the “tab” key to auto-complete options Change directory, for navigating the directory structure pwd Print working directory, to know where you are ls List directories and files in current working directory (“.”) or directory given after command Use the “tab” key to auto-complete options

Environment variables A computer must be told information in order to work the way you expect Many important settings are kept in “environment variables” $HOME = user’s home directory $PATH = list of directories containing programs $SHELL = user’s command shell env Prints information on environment variables

Local variables To make life easier, one may also set local variables, which may be referred back to at any time Useful if one finds the need to write the same thing may times sh/bash: var=‘Hello’ Instead of writing ‘Hello’, any reference to $var will be equivalent ‘Hello’ var=( Hello Goodbye ) Any reference to ${var[0]} will be equivalent to ‘Hello’ and ${var[1]} to ‘Goodbye’ csh/tcsh: set var = ‘Hello’ Instead of writing ‘Hello’, any reference to $var will be equivalent to ‘Hello’ set var = ( Hello Goodbye ) Any reference to $var[1] will be equivalent to ‘Hello’ and $var[2] to goodbye Note that sh/bash variable arrays are indexed to 0 and csh/tcsh variable arrays indexed to 1. Note also the required curly brackets surrounding the reference to the sh/bash variable array.

Commands to know

Everyday commands awk grep sed sort paste/join tr echo/cat

awk Powerful formatted read/write utility, e.g. awk ‘{print $1,$2,$3}’ <file> Prints first, second and third white-spaced columns (“fields”) from each line of <file> awk –v n=3 –F’,’ ‘{print $NF/n}’ <csv-file> Prints the last comma-separated field divided by 3 from each line of <csv-file> awk ‘BEGIN {sum=0}; {sum=sum+$1}; END {printf(“%.1f\n”,sum/NR)}’ <file> Calculate mean of first field: sums first field on each line then divides by number of lines (“records”)

grep Pattern-matching command (“general regular expression”) grep ‘hello’ <file> Prints all lines from <file> with occurrence of “hello” in them grep –ci ‘^apr’ <file> Prints the number (“-c”) of lines that begin (“^”) with “apr” in either upper- or lower-case letters (“-i”) in <file> grep ‘^ .* P$’ <file> Print all lines in <file> that begin (“^”) with a space, followed by any number of any characters (“.*”), and end (“$”) with a space followed by P

sed Basic text editor sed ‘s/ //g’ <file> Substitute (“s”) all (“g”) instances of a single whitespace with nothing (i.e. delete all whitespace) sed ‘/^ *$/d; s/hello/goodbye/1’ <file> Delete (“d”) all empty lines and substitute the first instance of “hello” with “goodbye” on each line of <file>

sort Sorts records sort <file> sort –u <file> Outputs basic alpha-numerically ordered <file> sort –u <file> Same as above but uniquely sorted (i.e. removes duplicate records) sort –gk3 <file> General numeric ordering based on third field of <file> sort –uk2.1,2.4 <file> Sort based on first character of second field to fourth character of second field and use this as the basis for the uniqueness test

tr Basic translation tr ‘[:upper:]’ ‘[:lower:]’ tr –d ‘\r’ Transposes all upper-case letters to lower-case tr –d ‘\r’ Deletes all carriage return (“CR”) characters (useful for changing a file’s line ending from DOS to UNIX format)

echo/cat Echoes the argument echo ‘Help!’ cat <file> Prints “Help!” cat <file> Reads out entirety of <file> cat << END Help! END Same as “echo ‘Help!’”

Redirection The output from one command may be written to a file… “>” to overwrite an existing file “>>” to append to an existing file sort [file] > [sorted file] …or “piped” to another command, effectively forming the second command’s input “|” grep ‘^ .* P$’ [file] | sort > [grep’d and sorted file]

Shorthands Top-level (“root”) directory = “/”, e.g. cd / Your home directory = “~” or “$HOME”, e.g. ls ~ “Links” or “shortcuts” may be created, e.g. ln –s /usr/local/gg/10.4 ~/gg This creates a link in the user’s home directory called “gg” that points to the directory /usr/local/gg/10.4 Rather than cd /usr/local/gg/10.4, one can get to the same place simply with cd ~/gg (This is used in GAMIT-GLOBK scripts and must remain in place!)

Useful commands du df top ps Disk usage: useful if you want to know how much space your (or others’!) directories are taking up df Disk free space: useful if you want to know how much disk space is used and free top Table Of Processes: useful if you want a real-time overview of running processes ps List processes: useful if you want to see what processes are running and their process numbers, commands, etc.

Introduction to shell scripts

What is a script? Scripts contain a series of commands written in one file and prepended by a “hashbang” #!/bin/sh for original Bourne Shell (usually the same as bash on modern systems) #!/bin/bash for Bourne Again Shell #!/bin/csh for C Shell (usually the same as tcsh on modern systems) #!/bin/tcsh for TENEX C Shell The script may then be executed to run all of the commands in sequence as written

Script example #!/bin/bash echo –n ‘The ISO date is: ‘ date +‘%Y-%m-%dT%H:%M:%S%Z’ echo –n ‘The mean of all numbers between 1 and 10 is: ’ echo 1 10 | awk ‘BEGIN {sum=0; n=0}; {for (i=$1; i<=$2; i++) {sum=sum+i; n++}}; END {print sum/n}’ echo ‘Goodbye!’