Lab 2: Linux/Unix shell

Similar documents
Linux Command Line Primer. By: Scott Marshall

CSE 390a Lecture 2. Exploring Shell Commands, Streams, Redirection, and Processes

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

Computer Systems and Architecture

Perl and R Scripting for Biologists

Useful Unix Commands Cheat Sheet

Introduction To. Barry Grant

Introduction: What is Unix?

Connecting to ICS Server, Shell, Vim CS238P Operating Systems fall 18

Table of contents. Our goal. Notes. Notes. Notes. Summer June 29, Our goal is to see how we can use Unix as a tool for developing programs

The UNIX Shells. Computer Center, CS, NCTU. How shell works. Unix shells. Fetch command Analyze Execute

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

Linux Command Line Interface. December 27, 2017

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

Recap From Last Time: Setup Checklist BGGN 213. Todays Menu. Introduction to UNIX.

Introduction to UNIX Shell Exercises

Introduction to UNIX Command Line

Week 2 Lecture 3. Unix

UNIX System Programming Lecture 3: BASH Programming

The Unix Shell. Pipes and Filters

Review of Fundamentals

Computer Systems and Architecture

Shell. SSE2034: System Software Experiment 3, Fall 2018, Jinkyu Jeong

Mills HPC Tutorial Series. Linux Basics I

Recap From Last Time:

BGGN 213 Working with UNIX Barry Grant

The Command Line. Matthew Bender. September 10, CMSC Command Line Workshop. Matthew Bender (2015) The Command Line September 10, / 25

Introduction to Linux Organizing Files

CSE 390a Lecture 2. Exploring Shell Commands, Streams, and Redirection

CST Algonquin College 2

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

Using LINUX a BCMB/CHEM 8190 Tutorial Updated (1/17/12)

Command-line interpreters

A Brief Introduction to Unix

CSE Linux VM. For Microsoft Windows. Based on opensuse Leap 42.2

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.

Basic UNIX commands. HORT Lab 2 Instructor: Kranthi Varala

5/20/2007. Touring Essential Programs

Introduction to Linux Workshop 1

When talking about how to launch commands and other things that is to be typed into the terminal, the following syntax is used:

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

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

M2PGER FORTRAN programming. General introduction. Virginie DURAND and Jean VIRIEUX 10/13/2013 M2PGER - ALGORITHME SCIENTIFIQUE

Command Line Interface Techniques

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

CSE 303 Lecture 2. Introduction to bash shell. read Linux Pocket Guide pp , 58-59, 60, 65-70, 71-72, 77-80

bash, part 3 Chris GauthierDickey

Bashed One Too Many Times. Features of the Bash Shell St. Louis Unix Users Group Jeff Muse, Jan 14, 2009

Filesystem and common commands

DATA 301 Introduction to Data Analytics Command Line. Dr. Ramon Lawrence University of British Columbia Okanagan

Why learn the Command Line? The command line is the text interface to the computer. DATA 301 Introduction to Data Analytics Command Line

UNIX Quick Reference

Files and Directories

CS370 Operating Systems

System Administration

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

Introduction to Linux

EECS2301. Lab 1 Winter 2016

Introduction to Linux Environment. Yun-Wen Chen

Unix Processes. What is a Process?

Unix Basics. Systems Programming Concepts

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

unix intro Documentation

Introduction to the Linux Command Line January Presentation Topics

Advanced Linux Commands & Shell Scripting

CSC209H Lecture 1. Dan Zingaro. January 7, 2015

Chap2: Operating-System Structures

Utilities. September 8, 2015

Unix Tutorial Haverford Astronomy 2014/2015

Part 1: Basic Commands/U3li3es

Files

Basics. I think that the later is better.

Linux Kung Fu. Ross Ventresca UBNetDef, Fall 2017

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.

Getting your department account

Modern C++ for Computer Vision and Image Processing. Igor Bogoslavskyi and Cyrill Stachniss

Bioinformatics? Reads, assembly, annotation, comparative genomics and a bit of phylogeny.

Introduction to UNIX. Introduction EECS l UNIX is an operating system (OS). l Our goals:

Operating Systems. Copyleft 2005, Binnur Kurt

Linux Bootcamp Fall 2015

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

Shell Scripting. With Applications to HPC. Edmund Sumbar Copyright 2007 University of Alberta. All rights reserved

Lec 1 add-on: Linux Intro

Operating Systems 3. Operating Systems. Content. What is an Operating System? What is an Operating System? Resource Abstraction and Sharing

Review of Fundamentals. Todd Kelley CST8207 Todd Kelley 1

Introduction to Linux

Processes. System tasks Campus-Booster ID : **XXXXX. Copyright SUPINFO. All rights reserved

Running Programs in UNIX 1 / 30

Introduction to UNIX. Introduction. Processes. ps command. The File System. Directory Structure. UNIX is an operating system (OS).

Introduction to UNIX. CSE 2031 Fall November 5, 2012

Unix tutorial. Thanks to Michael Wood-Vasey (UPitt) and Beth Willman (Haverford) for providing Unix tutorials on which this is based.

UNIX COMMANDS AND SHELLS. UNIX Programming 2015 Fall by Euiseong Seo

UNIX Quick Reference

CS197U: A Hands on Introduction to Unix

CS101 Linux Shell Handout

Module 8 Pipes, Redirection and REGEX

This is Lab Worksheet 3 - not an Assignment

Unix basics exercise MBV-INFX410

A Brief Introduction to the Linux Shell for Data Science

Using UNIX. -rwxr--r-- 1 root sys Sep 5 14:15 good_program

Transcription:

Lab 2: Linux/Unix shell Comp Sci 1585 Data Structures Lab: Tools for Computer Scientists

Outline 1 2 3 4 5 6 7

What is a shell?

What is a shell? login is a program that logs users in to a computer. When it logs you in, login checks /etc/passwd for your shell. After it authenticates you, it runs whatever your shell happens to be. Shells give you a way to run programs and view their output. They also usually include some built-in commands. Shells use to track information about commands and the system environment. The standard interactive shell is bash : There are others, though, e.g., zsh and fish.

Outline 1 2 3 4 5 6 7

Outline 1 2 3 4 5 6 7

the filesystem $ ls List files. You can give it a directory to list. $ ls -l Display the output in a detailed list, one line per file. $ ls -h Display file sizes in a human-readable format. $ ls -a Display all files, including hidden ones. $ pwd Print working directory. $ cd DIRECTORY Change directory. $ cd without a directory takes you $HOME. $ cd - takes you to the previous directory you were in.

Outline 1 2 3 4 5 6 7

File and Directory Shortcuts. always refers to the directory you are currently in... always refers to the parent of the current directory. ~ refers to your home directory. / refers to the root directory. Everything lives under root. Globs: * matches 0 or more characters in a file or directory name? matches exactly one character in a file or directory name For example, $ ls *.cpp lists all your cpp files.

Outline 1 2 3 4 5 6 7

$ mv SOURCE DESTINATION Move (or rename) files. $ mv -i Interactively ask you before overwriting files. $ mv -n Never overwrite files. $ cp SOURCE DESTINATION Copy files. $ cp -r Recursively copy directories, which is what you want to do. $ rm FILE Remove one or more files. $ rm -f Forcibly remove nonexistent files. $ mkdir DIRECTORY Makes a directory. $ mkdir -p DIRECTORY/SUBDIRECTORY Makes every missing directory in the given path

Outline 1 2 3 4 5 6 7

$ cat [FILE] Print out file contents. $ less [FILE] Paginate files or STDIN. $ head [FILE] Print lines from the top of a file or STDIN. $ tail [FILE] Print lines from the end of a file or STDIN. $ tail -n LINES Print LINES lines instead of 10. $ tail -f Print new lines as they are appended ( $ tail only). $ sort [FILE] Sorts files or STDIN. $ sort -u Only prints one of each matching line (unique). Often paired with $ uniq for similar effect. $ diff FILE1 FILE2 Shows differences between files. a/d/c Added/Deleted/Changed.

Outline 1 2 3 4 5 6 7

Outline 1 2 3 4 5 6 7

Each program has three default streams: STDIN: input, by default from the keyboard (cin). STDOUT: output, by default to the screen (cout). : output, by default to the screen (cerr). We can redirect IO to or from files or other programs. $ cmd1 cmd2 Pipe STDOUT from cmd1 into STDIN for cmd2. $ cmd < input.txt Funnel data from input.txt to STDIN for cmd. $ cmd > output.txt Funnel STDOUT from cmd into output.txt. Question: what do you think the following does? $ cmd < input.txt > output.txt

Outline 1 2 3 4 5 6 7

redirection tricks bash uses 1 and 2 to refer to STDOUT and. $ cmd 2> err.txt Funnel from cmd into err.txt. $ cmd 2>&1 Funnel from cmd into STDOUT. $ cmd &> all-output.txt Funnel all output from cmd into all-output.txt Common usage: $ cmd &> /dev/null dumps all output to the bit bucket.

Outline 1 2 3 4 5 6 7

Variables Shells keep track of a lot of information in. $ printenv shows all the environment set in your shell $ env shows exported environment ( that are also set in the environment of programs launched from this shell). $ set lets you set them $ VAR="value" sets the value of $VAR. (No spaces around the =!) $ echo $VAR prints the value of a variable in the shell. You can get environment variable values in C++ with getenv()

Useful $PATH Colon-delimited list of directories to look for programs in. $EDITOR Tells which editor you would prefer programs to launch for you. $ ~/.bashrc runs every time you start bash, so you can export customizations there.

Outline 1 2 3 4 5 6 7

Neat bash tricks Tab completion works for files and commands! History: / scroll through history. Ctrl + r searches backwards through history. $!! holds the last command executed. $!$ holds the last argument to the last command. $ alias sl=ls runs ls when you type sl.

Outline 1 2 3 4 5 6 7

$ ps Process list. $ ps aux / $ ps -ef show lots of information about all processes. $ ps has crazy whack options. $ top and $ htop give an interactive process listing. Job Control: Start processes in the background: $ command & If you have a command running in the foreground, you can stop it with Ctrl + z. $ fg starts the last process in the foreground. $ bg starts the last process in the background. $ jobs shows your running jobs. $ fg %2 starts job 2 in the foreground. $ kill PID Kills a process. (You can do $ kill %1!) $ killall command Kills every process running command.

Outline 1 2 3 4 5 6 7

Last but not least: help, -h, and man $ COMMAND --help or $ COMMAND -h often provide concise help $ man COMMAND opens a full manual listing for that command. q quits the manual. j / k scroll up and down a line. Space scrolls down one page. /thing within a man page, less, more, and Vim searches for things. n / N go to next/previous search result. $ man man gives you the manual for the manual!