Introduction to UNIX Command Line

Similar documents
Contents. Note: pay attention to where you are. Note: Plaintext version. Note: pay attention to where you are... 1 Note: Plaintext version...

Introduction: What is Unix?

Lab 2: Linux/Unix shell

Introduction p. 1 Who Should Read This Book? p. 1 What You Need to Know Before Reading This Book p. 2 How This Book Is Organized p.

Computer Systems and Architecture

Useful Unix Commands Cheat Sheet

Computer Systems and Architecture

Unix/Linux Operating System. Introduction to Computational Statistics STAT 598G, Fall 2011

Unix/Linux Basics. Cpt S 223, Fall 2007 Copyright: Washington State University

Introduction to Linux Workshop 1

Introduction to Unix The Windows User perspective. Wes Frisby Kyle Horne Todd Johansen

Lab Working with Linux Command Line

Introduction to the UNIX command line

Introduction to UNIX command-line II

Quick Start Guide. by Burak Himmetoglu. Supercomputing Consultant. Enterprise Technology Services & Center for Scientific Computing

Exercise 1: Basic Tools

Introduction to UNIX. Logging in. Basic System Architecture 10/7/10. most systems have graphical login on Linux machines

CSE 391 Lecture 3. bash shell continued: processes; multi-user systems; remote login; editors

Embedded Linux Systems. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

Introduction to Linux

Introduction To. Barry Grant

CSE 390a Lecture 3. bash shell continued: processes; multi-user systems; remote login; editors

Crash Course in Unix. For more info check out the Unix man pages -orhttp:// -or- Unix in a Nutshell (an O Reilly book).

Intro to Linux. this will open up a new terminal window for you is super convenient on the computers in the lab

CS197U: A Hands on Introduction to Unix

CS CS Tutorial 2 2 Winter 2018

Introduction to the Linux Command Line

GNU/Linux 101. Casey McLaughlin. Research Computing Center Spring Workshop Series 2018

Mills HPC Tutorial Series. Linux Basics I

Introduction to remote command line Linux. Research Computing Team University of Birmingham

A Brief Introduction to the Linux Shell for Data Science

Linux Essentials. Programming and Data Structures Lab M Tech CS First Year, First Semester

Getting Started With UNIX Lab Exercises

CISC 220 fall 2011, set 1: Linux basics

A Brief Introduction to Unix

Quick Start Guide. by Burak Himmetoglu. Supercomputing Consultant. Enterprise Technology Services & Center for Scientific Computing

Some useful UNIX Commands written down by Razor for newbies to get a start in UNIX

commandname flags arguments

Perl and R Scripting for Biologists

CENG 334 Computer Networks. Laboratory I Linux Tutorial

FREEENGINEER.ORG. 1 of 6 11/5/15 8:31 PM. Learn UNIX in 10 minutes. Version 1.3. Preface

Files

UNIX Quick Reference

Physics REU Unix Tutorial

Linux Training. for New Users of Cluster. Georgia Advanced Computing Resource Center University of Georgia Suchitra Pakala

Linux Operating System Environment Computadors Grau en Ciència i Enginyeria de Dades Q2

Lezione 8. Shell command language Introduction. Sommario. Bioinformatica. Mauro Ceccanti e Alberto Paoluzzi

Read the relevant material in Sobell! If you want to follow along with the examples that follow, and you do, open a Linux terminal.

Running Programs in UNIX 1 / 30

Unix basics exercise MBV-INFX410

Chapter-3. Introduction to Unix: Fundamental Commands

Lecture # 2 Introduction to UNIX (Part 2)

CHE3935. Lecture 1. Introduction to Linux

Basic Linux (Bash) Commands

Carnegie Mellon. Linux Boot Camp. Jack, Matthew, Nishad, Stanley 6 Sep 2016

Unix L555. Dept. of Linguistics, Indiana University Fall Unix. Unix. Directories. Files. Useful Commands. Permissions. tar.

Introduction to Linux

Part 1: Basic Commands/U3li3es

Processes. Shell Commands. a Command Line Interface accepts typed (textual) inputs and provides textual outputs. Synonyms:

First of all, these notes will cover only a small subset of the available commands and utilities, and will cover most of those in a shallow fashion.

acmteam/unix.pdf How to manage your account (user ID, password, shell); How to compile C, C++, and Java programs;

Lezione 8. Shell command language Introduction. Sommario. Bioinformatica. Esercitazione Introduzione al linguaggio di shell

Basic UNIX commands. HORT Lab 2 Instructor: Kranthi Varala

Introduction to the shell Part II

Getting your department account

This lab exercise is to be submitted at the end of the lab session! passwd [That is the command to change your current password to a new one]

The Unix Shell & Shell Scripts

IMPORTANT: Logging Off LOGGING IN

COMS 6100 Class Notes 3

Chap2: Operating-System Structures

Linux at the Command Line Don Johnson of BU IS&T

Research. We make it happen. Unix Basics. User Support Group help-line: personal:

Introduction to Linux Organizing Files

Set 1 MCQ Which command is used to sort the lines of data in a file in reverse order A) sort B) sh C) st D) sort -r

CS370 Operating Systems

Introduction to UNIX command-line

CS 307: UNIX PROGRAMMING ENVIRONMENT KATAS FOR EXAM 1

Working with Basic Linux. Daniel Balagué

Unix Tools / Command Line

Basic Unix Commands. CGS 3460, Lecture 6 Jan 23, 2006 Zhen Yang

The Linux Command Line & Shell Scripting

UNIX Quick Reference

BIOINFORMATICS POST-DIPLOMA PROGRAM SUBJECT OUTLINE Subject Title: OPERATING SYSTEMS AND PROJECT MANAGEMENT Subject Code: BIF713 Subject Description:

1. What statistic did the wc -l command show? (do man wc to get the answer) A. The number of bytes B. The number of lines C. The number of words

Traditional Access Permissions

Lab 1 Introduction to UNIX and C

UTA Tech Orientation Spring 2019

Introduction to Linux. Roman Cheplyaka

Introduction to Unix. University of Massachusetts Medical School. October, 2014

Week 2 Lecture 3. Unix

Introduction of Linux

Short Read Sequencing Analysis Workshop

CS197U: A Hands on Introduction to Unix

2 Lab 4. Unix Shell 2

Introduction to Linux Environment. Yun-Wen Chen

Exploring UNIX: Session 3

CS 3410 Intro to Unix, shell commands, etc... (slides from Hussam Abu-Libdeh and David Slater)

Linux Shell Script. J. K. Mandal

Arkansas High Performance Computing Center at the University of Arkansas

PROGRAMMAZIONE I A.A. 2015/2016

Transcription:

Introduction to UNIX Command Line Files and directories Some useful commands (echo, cat, grep, find, diff, tar) Redirection Pipes Variables Background processes Remote connections (e.g. ssh, curl) Scripts

The Command Line What is it? An interface to UNIX You type commands, things happen Also referred to as a shell We'll use the bash shell check you're using it by typing (you'll see what this means later): echo $SHELL If it doesn't say bash, then type bash to get into the bash shell

Files and Directories / home var usr mcuser abenson drmentor science catvideos stuff data code report M51.fits simulate.c analyze.py report.tex

Files and Directories Get a pre-made set of directories and files to work with We'll talk about what these commands do later The $ is the command prompt (yours might differ). Type what's listed after it, then press enter. $ curl curl -L -L -o -o playground.tar 'http://bit.ly/2swz1ef' $ tar tar xvf xvf playground.tar

Files and directories $ pwd pwd /home/abenson $ cd cd playground $ pwd pwd /home/abenson/playground animals documents science $ mkdir mystuff animals documents mystuff science $ cd cd animals/mammals badger.txt porcupine.txt -l -l total 8 -rw-r--r--. 1 abenson abenson 1944 1944 May May 31 31 18:03 badger.txt -rw-r--r--. 1 abenson abenson 1347 1347 May May 31 31 18:05 porcupine.txt

Files and directories Present Working Directory $ pwd pwd Shows the full path of your current /home/abenson location in the filesystem. $ cd cd playground $ pwd pwd /home/abenson/playground animals documents science $ mkdir mystuff animals documents mystuff science $ cd cd animals/mammals badger.txt porcupine.txt -l -l total 8 -rw-r--r--. 1 abenson abenson 1944 1944 May May 31 31 18:03 badger.txt -rw-r--r--. 1 abenson abenson 1347 1347 May May 31 31 18:05 porcupine.txt

Files and directories $ pwd pwd Change Directory /home/abenson $ cd cd playground Change to a new directory relative to $ pwd pwd current location unless you give a full /home/abenson/playground path animals documents science $ mkdir mystuff animals documents mystuff science $ cd cd animals/mammals badger.txt porcupine.txt -l -l total 8 -rw-r--r--. 1 abenson abenson 1944 1944 May May 31 31 18:03 badger.txt -rw-r--r--. 1 abenson abenson 1347 1347 May May 31 31 18:05 porcupine.txt

Files and directories $ pwd pwd /home/abenson $ cd cd playground $ pwd pwd LiSt /home/abenson/playground List the content of the current directory. animals documents science Shows both directories and files. $ mkdir mystuff animals documents mystuff science $ cd cd animals/mammals badger.txt porcupine.txt -l -l total 8 -rw-r--r--. 1 abenson abenson 1944 1944 May May 31 31 18:03 badger.txt -rw-r--r--. 1 abenson abenson 1347 1347 May May 31 31 18:05 porcupine.txt

Files and directories $ pwd pwd /home/abenson $ cd cd playground $ pwd pwd /home/abenson/playground MaKe DIRectory animals documents science $ mkdir mystuff Make a new directory in the current $ ls directory ls animals documents mystuff science $ cd cd animals/mammals badger.txt porcupine.txt -l -l total 8 -rw-r--r--. 1 abenson abenson 1944 1944 May May 31 31 18:03 badger.txt -rw-r--r--. 1 abenson abenson 1347 1347 May May 31 31 18:05 porcupine.txt

Files and directories $ pwd pwd /home/abenson $ cd cd playground $ pwd pwd /home/abenson/playground MaKe DIRectory animals documents science $ mkdir mystuff Make a new directory in the current $ ls directory ls animals documents mystuff science $ cd cd animals/mammals badger.txt porcupine.txt -l -l total 8 -rw-r--r--. 1 abenson abenson 1944 1944 May May 31 31 18:03 badger.txt -rw-r--r--. 1 abenson abenson 1347 1347 May May 31 31 18:05 porcupine.txt

Files and directories $ pwd pwd /home/abenson $ cd cd playground $ pwd pwd /home/abenson/playground animals documents science $ mkdir mystuff animals documents mystuff science $ cd cd animals/mammals Options -l to ls requests a long badger.txt porcupine.txt listing. -l -l total 8 -rw-r--r--. 1 abenson abenson 1944 1944 May May 31 31 18:03 badger.txt -rw-r--r--. 1 abenson abenson 1347 1347 May May 31 31 18:05 porcupine.txt

Files and directories $ pwd pwd /home/abenson $ cd cd playground $ pwd pwd /home/abenson/playground animals documents science $ mkdir mystuff animals documents mystuff science $ cd cd animals/mammals Options -l to ls requests a long badger.txt porcupine.txt listing. -l -l total 8 -rw-r--r--. 1 abenson abenson 1944 1944 May May 31 31 18:03 badger.txt -rw-r--r--. 1 abenson abenson 1347 1347 May May 31 31 18:05 porcupine.txt

Files and directories $ pwd pwd /home/abenson $ cd cd playground $ pwd pwd /home/abenson/playground animals documents science $ mkdir mystuff animals documents mystuff science $ cd cd animals/mammals badger.txt porcupine.txt -l -l total 8 -rw-r--r--. 1 abenson abenson 1944 1944 May May 31 31 18:03 badger.txt -rw-r--r--. 1 abenson abenson 1347 1347 May May 31 31 18:05 porcupine.txt Permissions User Group Size in bytes Creation time File name

Files and directories -a -a..... badger.txt porcupine.txt $ cd cd. $ pwd pwd /home/abenson/playground/animals/mammals $ cd cd.... $ pwd pwd /home/abenson/playground/animals $ cd cd $ pwd pwd /home/abenson $ cd cd ~ $ pwd pwd /home/abenson

Files and directories $ cd cd ~/playground/animals/mammals/ badger.txt porcupine.txt -l -l total 8 -rw-r--r--. 1 abenson abenson 1944 1944 May May 31 31 18:03 badger.txt -rw-r--r--. 1 abenson abenson 1347 1347 May May 31 31 18:05 porcupine.txt $ chmod go+w go+w badger.txt -l -l total 8 -rw-rw-rw-. 1 abenson abenson 1944 1944 May May 31 31 18:03 badger.txt -rw-r--r--. 1 abenson abenson 1347 1347 May May 31 31 18:05 porcupine.txt $ cp cp badger.txt super_badger.txt badger.txt porcupine.txt super_badger.txt $ mv mv super_badger.txt super_mellivorinae.txt badger.txt porcupine.txt super_mellivorinae.txt

Files and directories $ cd cd ~/playground/animals/mammals/ badger.txt porcupine.txt CHange MODe -l -l total 8 Changes permissions for the file: -rw-r--r--. 1 abenson abenson u 1944 = user 1944 May May 31 31 18:03 badger.txt -rw-r--r--. 1 abenson abenson g 1347 = group 1347 May May 31 31 18:05 porcupine.txt $ chmod go+w go+w badger.txt o = other -l -l total 8 +-= add, remove, set -rw-rw-rw-. 1 abenson abenson 1944 1944 May May 31 31 18:03 badger.txt -rw-r--r--. 1 abenson abenson rwx 1347 1347 read, May May write, 31 31 18:05 execute porcupine.txt $ cp cp badger.txt super_badger.txt badger.txt porcupine.txt super_badger.txt $ mv mv super_badger.txt super_mellivorinae.txt badger.txt porcupine.txt super_mellivorinae.txt

Files and directories $ cd cd ~/playground/animals/mammals/ CoPy badger.txt porcupine.txt Make a copy of a file you give the -l -l name of the original file, followed total 8 by the new file. -rw-r--r--. 1 abenson abenson 1944 1944 May May 31 31 18:03 badger.txt -rw-r--r--. 1 abenson abenson 1347 1347 May May 31 31 18:05 porcupine.txt $ chmod go+w go+w badger.txt -l -l total 8 -rw-rw-rw-. 1 abenson abenson 1944 1944 May May 31 31 18:03 badger.txt -rw-r--r--. 1 abenson abenson 1347 1347 May May 31 31 18:05 porcupine.txt $ cp cp badger.txt super_badger.txt badger.txt porcupine.txt super_badger.txt $ mv mv super_badger.txt super_mellivorinae.txt badger.txt porcupine.txt super_mellivorinae.txt

Files and directories $ cd cd ~/playground/animals/mammals/ badger.txt porcupine.txt -l -l total 8 MoVe -rw-r--r--. 1 abenson abenson 1944 1944 May May 31 31 18:03 badger.txt -rw-r--r--. 1 abenson abenson Move 1347 (rename) 1347 May May 31 a 31 18:05 file you porcupine.txt give the $ chmod go+w go+w badger.txt name of the original file, followed -l by the new name. -l total 8 -rw-rw-rw-. 1 abenson abenson 1944 1944 May May 31 31 18:03 badger.txt -rw-r--r--. 1 abenson abenson 1347 1347 May May 31 31 18:05 porcupine.txt $ cp cp badger.txt super_badger.txt badger.txt porcupine.txt super_badger.txt $ mv mv super_badger.txt super_mellivorinae.txt badger.txt porcupine.txt super_mellivorinae.txt

Useful Commands $ echo echo "Hello? Can Can you you hear hear me?" me?" Hello? Can Can you you hear hear me? me? $ cat cat badger.txt Badgers are are short-legged omnivores... $ cat cat badger.txt porcupine.txt Badgers are are short-legged omnivores... Porcupines are are rodents with with a coat coat of of sharp spines... $ more more badger.txt Badgers are are short-legged omnivores... $ less less badget.txt Badgers are are short-legged omnivores... $ man man less less NAME NAME less less - opposite of of more more SYNOPSIS less less -? -? less less --help

Useful Commands $ echo echo "Hello? Can Can you you hear hear me?" me?" Hello? Can Can you you hear hear me? me? $ cat cat badger.txt Badgers are are short-legged omnivores... $ cat cat badger.txt porcupine.txt Badgers are are short-legged omnivores... Porcupines are are rodents with with a coat coat of of sharp spines... $ more more badger.txt Badgers are are short-legged omnivores... $ less less badget.txt Badgers are are short-legged omnivores $ man man less less NAME NAME echo less less - opposite of of more more Write the given text to screen (or SYNOPSIS somewhere else more of this less less -? -? later). less less --help

Useful Commands $ echo echo "Hello? Can Can you you hear hear me?" me?" Hello? Can Can you you hear hear me? me? $ cat cat badger.txt Badgers are are short-legged omnivores... $ cat cat badger.txt porcupine.txt Badgers are are short-legged omnivores... Porcupines are are rodents with with a coat coat of of sharp spines... $ more more badger.txt Badgers are are short-legged omnivores... $ less less badget.txt Badgers are are short-legged omnivores $ man man less less NAME NAME concatenate less less - opposite of of more more Take the content of all files listed, SYNOPSIS join them together, and write it out. less less -? -? less less --help

Useful Commands $ echo echo "Hello? Can Can you you hear hear me?" me?" Hello? Can Can you you hear hear me? me? $ cat cat badger.txt Badgers are are short-legged omnivores... $ cat cat badger.txt porcupine.txt Badgers are are short-legged omnivores... Porcupines are are rodents with with a coat coat of of sharp spines... $ more more badger.txt Badgers are are short-legged omnivores... $ less less badget.txt Badgers are are short-legged omnivores $ man man less less NAME NAME concatenate less less - opposite of of more more Take the content of all files listed, SYNOPSIS join them together, and write it out. less less -? -? less less --help

Useful Commands $ echo echo "Hello? Can Can you you hear hear me?" me?" Hello? Can Can you you hear hear me? me? $ cat cat badger.txt Badgers are are short-legged omnivores... $ cat cat badger.txt porcupine.txt Badgers are are short-legged omnivores... Porcupines are are rodents with with a coat coat of of sharp spines... $ more more badger.txt Badgers are are short-legged omnivores... $ less less badget.txt Badgers are are short-legged omnivores $ man man less less NAME NAME more less less - opposite of of more more Display contents of a file to terminal SYNOPSIS with pagination (use return or space less less -? -? to step through). less less --help

Useful Commands $ echo echo "Hello? Can Can you you hear hear me?" me?" Hello? Can Can you you hear hear me? me? $ cat cat badger.txt Badgers are are short-legged omnivores... $ cat cat badger.txt porcupine.txt Badgers are are short-legged omnivores... Porcupines are are rodents with with a coat coat of of sharp spines... $ more more badger.txt Badgers are are short-legged omnivores... $ less less badget.txt Badgers are are short-legged omnivores $ man man less less NAME NAME less less less - opposite of of more more Fancy version of more. Scroll SYNOPSIS forward and backward. Search ( / ), less less -? -? etc. less less --help

Useful Commands $ echo echo "Hello? Can Can you you hear hear me?" me?" Hello? Can Can you you hear hear me? me? $ cat cat badger.txt MANual Badgers are are short-legged omnivores... $ cat cat badger.txt porcupine.txt Show documentation for a command. Badgers are are short-legged omnivores... Porcupines are are rodents with with a coat coat of of sharp spines... $ more more badger.txt Badgers are are short-legged omnivores... $ less less badget.txt Badgers are are short-legged omnivores $ man man less less NAME NAME less less - opposite of of more more SYNOPSIS less less -? -? less less --help

Useful Commands $ grep grep skunk badger.txt members of of the the skunk family, placing $ grep grep rodent *.txt porcupine.txt:porcupines are are rodents porcupine.txt:porcupines are are the the third-largest of of the the rodents, $ cd cd $ find find playground -name "*.txt" playground/animals/mammals/super_mellivorinae.txt playground/animals/mammals/badger.txt playground/animals/mammals/porcupine.txt playground/animals/reptiles/caiman.txt $ find find playground -type d playground playground/documents playground/animals playground/animals/mammals playground/animals/reptiles playground/science

Useful Commands $ grep grep skunk badger.txt members of of the the skunk family, placing $ grep grep rodent *.txt porcupine.txt:porcupines are are rodents porcupine.txt:porcupines are are the the third-largest of of the the rodents, $ cd cd $ find find playground -name "*.txt" playground/animals/mammals/super_mellivorinae.txt Get Regualr ExPression playground/animals/mammals/badger.txt playground/animals/mammals/porcupine.txt Search for a word (or words) in a file. playground/animals/reptiles/caiman.txt $ find find playground -type d playground playground/documents playground/animals playground/animals/mammals playground/animals/reptiles playground/science

Useful Commands $ grep grep skunk badger.txt members of of the the skunk family, placing $ grep grep rodent *.txt porcupine.txt:porcupines are are rodents porcupine.txt:porcupines are are the the third-largest of of the the rodents, $ cd cd $ find find playground -name "*.txt" playground/animals/mammals/super_mellivorinae.txt playground/animals/mammals/badger.txt playground/animals/mammals/porcupine.txt playground/animals/reptiles/caiman.txt $ find find playground -type d playground Wildcards playground/documents playground/animals * matches any sequence of characters playground/animals/mammals? matches any single character playground/animals/reptiles playground/science

Useful Commands $ grep grep skunk badger.txt members of of the the skunk family, placing $ grep grep rodent *.txt porcupine.txt:porcupines are are rodents porcupine.txt:porcupines are are the the third-largest of of the the rodents, $ cd cd $ find find playground -name "*.txt" playground/animals/mammals/super_mellivorinae.txt playground/animals/mammals/badger.txt playground/animals/mammals/porcupine.txt playground/animals/reptiles/caiman.txt $ find find playground -type d playground find playground/documents playground/animals Search a path for files/directories that playground/animals/mammals match some specification playground/animals/reptiles playground/science

Redirection $ rm rm super_mellivorinae.txt badger.txt porcupine.txt $ cd cd playground/animals/mammals/ $ cat cat badger.txt > another_badger.txt another_badger.txt badger.txt porcupine.txt $ cat cat > list_of_mammals.txt bat bat cat cat ocelot camel ^D ^D $ cat cat list_of_mammals.txt bat bat cat cat ocelot camel

Useful Commands $ tar tar cvf cvf playground.tar playground playground/ playground/documents/ playground/mystuff/ playground/animals/ playground/animals/mammals/ playground/animals/mammals/super_mellivorinae.txt playground/animals/mammals/badger.txt playground/animals/mammals/porcupine.txt playground/animals/reptiles/ playground/animals/reptiles/caiman.txt playground/science/ playground playground.tar

Useful Commands $ tar tar cvf cvf playground.tar playground playground/ playground/documents/ playground/mystuff/ playground/animals/ playground/animals/mammals/ playground/animals/mammals/super_mellivorinae.txt Tape ARchive playground/animals/mammals/badger.txt playground/animals/mammals/porcupine.txt Combine all files (and directories) into playground/animals/reptiles/ one archive file. Useful for sharing playground/animals/reptiles/caiman.txt data, archiving etc. playground/science/ Use: playground playground.tar tar xvf playground.tar to re-extract.

Redirection $ rm rm super_mellivorinae.txt badger.txt porcupine.txt $ cd cd playground/animals/mammals/ $ cat cat badger.txt > another_badger.txt another_badger.txt badger.txt ReMove porcupine.txt $ cat cat > list_of_mammals.txt bat bat Delete a file. THERE IS NO UNDO!!! cat cat ocelot Add -r option to recursively remove all camel files in a directory. ^D ^D $ cat cat list_of_mammals.txt THERE IS NO UNDO!!!!!!!!!!!!! bat bat cat cat ocelot camel

Redirection $ rm rm super_mellivorinae.txt badger.txt porcupine.txt $ cd cd playground/animals/mammals/ $ cat cat badger.txt > another_badger.txt another_badger.txt badger.txt porcupine.txt $ cat cat > list_of_mammals.txt bat bat cat cat Redirection ocelot camel > sends output to named file instead ^D ^D of to the terminal. So, this was a way $ cat cat list_of_mammals.txt to make a copy of our file. bat bat cat cat ocelot camel

Redirection $ rm rm super_mellivorinae.txt badger.txt porcupine.txt $ cd cd playground/animals/mammals/ $ cat cat badger.txt > another_badger.txt another_badger.txt badger.txt porcupine.txt $ cat cat > list_of_mammals.txt bat bat cat cat ocelot camel ^D ^D Redirection $ cat cat list_of_mammals.txt bat bat No input file given.. Terminal waits for cat cat you to type input. Whatever you type ocelot goes into the file. camel

Redirection $ echo echo "More badger stuff here here later." >> >> another_badger.txt $ cat cat badger.txt... More More badger stuff to to go go here here later. $ diff diff badger.txt another_badger.txt 7a8 7a8 > More More badger stuff to to go go here here later.

Redirection $ echo echo "More badger stuff here here later." >> >> another_badger.txt $ cat cat badger.txt... More More badger stuff to to go go here here later. $ diff diff badger.txt another_badger.txt 7a8 7a8 Append > More More badger stuff to to go go here here later. Like >, but appends instead of over-writing.

Redirection $ echo echo "More badger stuff here here later." >> >> another_badger.txt $ cat cat badger.txt... More More badger stuff to to go go here here later. $ diff diff badger.txt another_badger.txt 7a8 7a8 > More More badger stuff to to go go here here later. DIFFerence Show differences between two files.

Redirection and Pipes (and Sorting) $ sort sort list_of_mammals.txt bat bat camel cat cat ocelot $ sort sort < list_of_mammals.txt bat bat camel cat cat ocelot $ cat cat list_of_mammals.txt sort sort bat bat camel cat cat ocelot

Redirection and Pipes (and Sorting) $ sort sort list_of_mammals.txt bat bat camel cat cat ocelot $ sort sort < list_of_mammals.txt bat Sort bat camel cat Sort input into alphanumerical order. cat ocelot $ cat cat list_of_mammals.txt sort sort bat bat camel cat cat ocelot

Redirection and Pipes (and Sorting) $ sort sort list_of_mammals.txt bat bat camel cat cat ocelot $ sort sort < list_of_mammals.txt bat bat camel cat cat ocelot $ cat cat list_of_mammals.txt sort sort bat bat camel Redirect input cat cat ocelot Redirects input from a file into a command.

Redirection and Pipes (and Sorting) $ sort sort list_of_mammals.txt bat bat camel cat cat ocelot $ sort sort < list_of_mammals.txt bat bat camel cat cat ocelot $ cat cat list_of_mammals.txt sort sort bat bat camel cat cat ocelot Pipe takes output from first command and sends it as input to second.

Variables $ echo echo $SHELL /bin/bash $ echo echo $USER abenson $ echo echo $HOME /home/abenson $ workpath=$home/playground $ cd cd $workpath $ pwd pwd /home/abenson/playground

Variables $ echo echo $SHELL /bin/bash $ echo echo $USER abenson Environment Variables $ echo echo $HOME /home/abenson $ means replace following with the $ workpath=$home/playground value of the named variable. $ cd cd $workpath $ pwd pwd The shell sets up many environment /home/abenson/playground variables, such as those shown.

Variables $ echo echo $SHELL /bin/bash $ echo echo $USER abenson $ echo echo $HOME /home/abenson $ workpath=$home/playground $ cd cd $workpath $ pwd pwd /home/abenson/playground User Variables Define your own variables and then use them in the command line.

Background Processes $./job.sh $ ^C ^C $./job.sh $ ^Z ^Z $ jobs jobs $ fg fg $ ^Z ^Z $ bg bg $ jobs jobs

Background Processes $./job.sh $ ^C ^C $./job.sh $ ^Z ^Z $ jobs jobs $ fg fg $ ^Z ^Z $ bg bg $ jobs jobs A script we ll learn more about scripts soon this one just writes annoying messages

Background Processes $./job.sh $ ^C ^C $./job.sh $ ^Z ^Z Cancel [1]+ [1]+ Stopped./job.sh $ jobs jobs ^C cancels the running command [1]+ [1]+ Stopped./job.sh $ fg fg $./job.sh $ ^Z ^Z [1]+ [1]+ Stopped./job.sh $ bg bg [1]+ [1]+./job.sh & $ jobs jobs [1]+ [1]+ Running./job.sh & $./job.sh & [2] [2] 21194

Background Processes $./job.sh $ ^C ^C $./job.sh $ ^Z ^Z [1]+ [1]+ Stopped./job.sh $ jobs jobs Suspend [1]+ [1]+ Stopped./job.sh $ fg fg ^Z suspends the running command $./job.sh $ ^Z ^Z [1]+ [1]+ Stopped./job.sh $ bg bg [1]+ [1]+./job.sh & $ jobs jobs [1]+ [1]+ Running./job.sh & $./job.sh & [2] [2] 21194

Background Processes $./job/.sh $ ^C ^C $./job/.sh $ ^Z ^Z [1]+ [1]+ Stopped./job.sh $ jobs jobs [1]+ [1]+ Stopped./job.sh $ fg fg Jobs $./job/.sh $ ^Z ^Z Shows a list of jobs running or [1]+ [1]+ Stopped suspended./job.sh $ bg bg [1]+ [1]+./job.sh & $ jobs jobs [1]+ [1]+ Running./job.sh & $./job/.sh & [2] [2] 21194

Background Processes $./job.sh $ ^C ^C $./job.sh $ ^Z ^Z [1]+ [1]+ Stopped./job.sh $ jobs jobs [1]+ [1]+ Stopped./job.sh $ fg fg $./job.sh $ ^Z ^Z ForeGround [1]+ [1]+ Stopped./job.sh $ bg bg Bring the last suspended job back into [1]+ [1]+./job.sh & the foregound (i.e. start running again). $ jobs jobs [1]+ [1]+ Running./job.sh & $./job.sh & [2] [2] 21194

Background Processes $./job.sh $ ^C ^C $./job.sh $ ^Z ^Z [1]+ [1]+ Stopped./job.sh $ jobs jobs [1]+ [1]+ Stopped./job.sh $ fg fg $./job.sh $ ^Z ^Z [1]+ [1]+ Stopped./job.sh $ bg bg [1]+ [1]+./job.sh & $ jobs jobs BackGround [1]+ [1]+ Running./job.sh & $./job.sh & Run the last suspended job in the [2] [2] 21194 background.

Background Processes $./job.sh $ ^C ^C $./job.sh $ ^Z ^Z [1]+ [1]+ Stopped./job.sh $ jobs jobs [1]+ [1]+ Stopped./job.sh $ fg fg $./job.sh $ ^Z ^Z [1]+ [1]+ Stopped./job.sh $ bg bg [1]+ [1]+./job.sh & $ jobs jobs & [1]+ [1]+ Running./job.sh & $./job.sh & Start the command in the background. [2] [2] 21194

Network and Remote Connections $ hostname dhcp225.obs.carnegiescience.edu $ ssh ssh testuser@mies.stanford.edu Last Last login: Thu Thu Jun Jun 2 14:03:01 2016 2016 from from ociw.edu testuser@mies ~] ~] hostname obs-ssh.ad.ciw.edu testuser@mies ~] ~] exit exit Connection to to mies.stanford.edu closed. $ cd cd animals/mammals $ scp scp badger.txt testuser@mies.stanford.edu:myname.txt badger.txt 100% 100% 1944 1944 1.9KB/s 00:00 $ ssh ssh testuser@mies.stanford.edu Last Last login: Thu Thu Jun Jun 2 14:03:01 2016 2016 from from ociw.edu testuser@mies ~] ~] ls ls badger.txt testuser@mies ~] ~] rm rm myname.txt testuser@mies ~] ~] exit exit Connection to to mies.stanford.edu closed.

Network and Remote Connections $ hostname dhcp225.obs.carnegiescience.edu $ ssh ssh testuser@mies.stanford.edu Last Last login: Thu Thu Jun Jun 2 14:03:01 2016 2016 from from ociw.edu testuser@mies ~] ~] hostname obs-ssh.ad.ciw.edu testuser@mies ~] ~] exit exit Secure SHell Connection to to ssh.obs.carnegiescience.edu closed. $ cd cd animals/mammals Open a shell on a remote server. $ scp scp badger.txt testuser@mies.stanford.edu: badger.txt 100% 100% 1944 1944 Password 1.9KB/s is: HvtTc6Bw 00:00 $ ssh ssh testuser@mies.stanford.edu Last Last login: Thu Thu Jun Jun 2 14:03:01 2016 2016 from from ociw.edu testuser@mies ~] ~] ls ls badger.txt testuser@mies ~] ~] rm rm badger.txt testuser@mies ~] ~] exit exit Connection to to ssh.obs.carnegiescience.edu closed.

Network and Remote Connections $ hostname dhcp225.obs.carnegiescience.edu $ ssh ssh testuser@mies.stanford.edu Last Last login: Thu Thu Jun Jun 2 14:03:01 2016 2016 from from ociw.edu testuser@mies ~] ~] hostname obs-ssh.ad.ciw.edu testuser@mies ~] ~] exit exit Connection to to ssh.obs.carnegiescience.edu closed. $ cd cd animals/mammals $ scp scp badger.txt testuser@mies.stanford.edu: badger.txt 100% 100% 1944 1944 1.9KB/s 00:00 $ ssh ssh testuser@mies.stanford.edu Secure CoPy Last Last login: Thu Thu Jun Jun 2 14:03:01 2016 2016 from from ociw.edu testuser@mies ~] ~] ls ls Copy a file to a remote server. Or from badger.txt remote server to your laptop testuser@mies ~] ~] rm rm badger.txt testuser@mies ~] ~] exit exit Password is: HvtTc6Bw Connection to to ssh.obs.carnegiescience.edu closed.

Network and Remote Connections $ curl curl -L -L -o -o playground1.tar 'http://bit.ly/2swz1ef' curl Download a file from a URL. Useful for downloading big datasets on a remote server.

Scripts #!/bin/sh echo echo This This is is a script. echo echo Hello user user $USER echo echo Here Here are are all all the the files I can can find find find. -type f exit exit

Scripts $ cd cd ~/playground $./script.sh This This is is a script... Hello user user abensonca Here Here are are all all the the files I can can find./script.sh./animals/mammals/badger.txt./animals/mammals/porcupine.txt./animals/reptiles/caiman.txt

Scripts:.bashrc The script in ~/.bashrc gets run every time you log in Use it to configure the environment the way you want it to be For example, you could add an alias: $ alias up='cd..'..' $ cd cd ~/playground/animals $ pwd pwd /home/abenson/playground/animals $ up up $ pwd pwd /home/abenson/playground

Bonus: Text Editing with EMACS There are many text editors in Unix Use whichever you prefer One option available everywhere is EMACS $ emacs playground/animals/reptiles/caiman.txt & [1] [1] 29575

Bonus: Text Editing with EMACS Open file ^X^F Save file ^X^S Cut ^W Paste ^Y Close file ^X^K Search forward ^S Exit EMACS ^X^C Search backward ^R