Command Line - Part 1



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

Introduction to Mac OS X

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

Tutorial 0A Programming on the command line

Command Line Crash Course For Unix

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

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

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

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

CS 103 Lab Linux and Virtual Machines

University of Toronto

Chapter 2 Text Processing with the Command Line Interface

An Introduction to the Linux Command Shell For Beginners

CS 2112 Lab: Version Control

Introduction to Operating Systems

AN INTRODUCTION TO UNIX

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

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

CMSC 216 UNIX tutorial Fall 2010

Unix Sampler. PEOPLE whoami id who

A UNIX/Linux in a nutshell

Tutorial Guide to the IS Unix Service

ICS 351: Today's plan

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

New Lab Intro to KDE Terminal Konsole

Lab 1 Beginning C Program

Introduction to the UNIX Operating System and Open Windows Desktop Environment

Extreme computing lab exercises Session one

Editing Files on Remote File Systems

HP-UX Essentials and Shell Programming Course Summary

Agenda. Using HPC Wales 2

Running your first Linux Program

Open Source Computational Fluid Dynamics

A Crash Course on UNIX

Hands-On UNIX Exercise:

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

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

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

TEL2821/IS2150: INTRODUCTION TO SECURITY Lab: Operating Systems and Access Control

Basic Linux & Package Management. Original slides from GTFO Security

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

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

Lab 1: Introduction to the network lab

Unix the Bare Minimum

Linux System Administration

Version control. HEAD is the name of the latest revision in the repository. It can be used in subversion rather than the latest revision number.

Thirty Useful Unix Commands

CONNECTING TO DEPARTMENT OF COMPUTER SCIENCE SERVERS BOTH FROM ON AND OFF CAMPUS USING TUNNELING, PuTTY, AND VNC Client Utilities

Vim, Emacs, and JUnit Testing. Audience: Students in CS 331 Written by: Kathleen Lockhart, CS Tutor

The Linux Operating System and Linux-Related Issues

Linux System Administration on Red Hat

File Management With Windows Explorer

Introduction to Unix Tutorial

Hadoop Basics with InfoSphere BigInsights

Getting Started with Command Prompts

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

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

Introduction to UNIX and SFTP

your Apple warranty; see There are two main failure modes for a mirrored RAID 1 set:

Basic Linux and Unix commands, editing and transfering files

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

L01 Introduction to the Unix OS

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

LSN 10 Linux Overview

Introduction to Linux operating system. module Basic Bioinformatics PBF

How to FTP (How to upload files on a web-server)

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

Linux Labs: mini survival guide

Introduction to Shell Programming

Cloud Server powered by Mac OS X. Getting Started Guide. Cloud Server. powered by Mac OS X. AKJZNAzsqknsxxkjnsjx Getting Started Guide Page 1

Instructions for Accessing the Advanced Computing Facility Supercomputing Cluster at the University of Kansas

Recommended File System Ownership and Privileges

TNM093 Practical Data Visualization and Virtual Reality Laboratory Platform

Hypercosm. Studio.

Windows File Management A Hands-on Class Presented by Edith Einhorn

Using the Radmind Command Line Tools to. Maintain Multiple Mac OS X Machines

Kernel. What is an Operating System? Systems Software and Application Software. The core of an OS is called kernel, which. Module 9: Operating Systems

Introduction to the UNIX Operating System on IT Systems

Introduction to Running Hadoop on the High Performance Clusters at the Center for Computational Research

The Einstein Depot server

CPSC 226 Lab Nine Fall 2015

Bank Reconciliation User s Guide

Computer Programming In QBasic

Shellshock Security Patch for X86

VIP Quick Reference Card

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

Help File. Version February, MetaDigger for PC

Prescribed Specialised Services 2015/16 Shadow Monitoring Tool

1001ICT Introduction To Programming Lecture Notes

CGS 1550 File Transfer Project Revised 3/10/2005

Code::Blocks Student Manual

Installing FEAR on Windows, Linux, and Mac Systems

A Brief Introduction to the Command Line and Git

LPI certification 101 exam prep, Part 1

Unix Scripts and Job Scheduling

Navigating the Rescue Mode for Linux

CS2510 Computer Operating Systems Hadoop Examples Guide

Transcription:

Command Line - Part 1 STAT 133 Gaston Sanchez Department of Statistics, UC Berkeley gastonsanchez.com github.com/gastonstat Course web: gastonsanchez.com/teaching/stat133

GUIs 2

Graphical User Interfaces Windows and Mac use a Graphical User Interface (GUI) for you to interact with the OS. GUIs are easy to learn GUIs rely on visual displays GUIs can be extremely useful GUIs have improved the friendliness and usability of computers 3

GUIs or Command Line? However, GUIs come with trade-offs They don t allow you to have more control over what your computer can do Some operations are labor intensive and repetitive You organize things by clicking and dragging with the cursor (which reduces reproducibility) 4

GUI Disadvantages Lack of repeatability Lack of reproducibility Some tasks may be labor intensive using a GUI GUIs limit analyses on a cluster of computers 5

Command Line 6

Command Line Instead of using a GUI, we can use a command line program The command line program is known as the shell By typing commands we perform tasks on the computer (without using a mouse) 7

Shell You re working with a program called the shell The shell interprets the commands you enter It runs the program you ve asked for It coordinates what happens between you and the operating system There are various kinds or flavors of shells: e.g. Bourne (BASH), Korn, C shell 8

Command Line To interact with the shell we need a terminal emulator In Unix-like systems (e.g. Mac) the terminal is usually known as terminal Windows does not really provide a terminal; instead it provides the command prompt 9

Command Prompt in Windows Finding MS Windows command prompt Click the Start button Click All Programs Click Accessories Click Command Prompt Windows command prompt is not a UNIX shell 10

Shells for Windows Instead of using the command prompt you can use ad-hoc shell environments for Windows e.g. Git-Bash, PowerShell, Cygwin Git for Windows provides a BASH emulation PowerShell is part of Windows Management Framework 4.0 Cygwin is large collection of GNU and Open Source tools 11

Mac Terminal Go to Applications Go to Utilities Click Terminal 12

Try Some Commands date (current time and date) cal (calendar of current month) df (amount of free space in your disk drives) who (logged in users) echo Hello 13

Shell Shells run in terminal emulators, or terminals In Mac OS X, the default reminal program is called Terminal The command line is displayed within the terminal window The program behind the terminal is the shell There are many different shell programs 14

BASH The most common type of shell is BASH BASH: Bourne Again SHell BASH is the default shell for Linux BASH is usually the default shell on Mac type echo $SHELL to see your shell type bash to get a bash shell 15

BASH A shell does much more than simply run commands It has wildcards for matching filenames It has a command history to recall previous commands quickly It has pipes for making the output of one command become the input of another It has variables for storing values for use by the shell 16

Command who who displays a list of users that are currently logged in who am i (whoami) tells you the current user name 17

Shell Command Syntax command -options arg1 arg2 Blanks and "-" are delimiters The number of arguments may vary An argument comes at the end of the command line It s usually the name of a file or some text Many commands have default arguments 18

Date and Calendar date cal (current calendar year) cal july 2015 (July 2015) cal jan 2000 ncal -w july 2015 (week number) 19

Options command -options arg1 arg2 Options come between the command and the arguments They tell the command to do something other than its default They are usually prefaced with one or two hyphens e.g. ncal -w july 2015 20

Some Control Sequences keys C + l C + c C + z C + k C + r C + n C + p description clear screen stop current command suspend current command kill to end of line search history next history item previous history item 21

Manual Documentation To see the help documentation of a command use man followed by the name of the command: man cal man date man who q quits manual documentation 22

Logging Out exit logs you out q quits manual documentation 23

System Navigation 24

Filesystem Reminder The nested hierarchy of folders and files on your computer is called the filesystem The filesystem follows a tree-like structure The root directory is the most includive folder on the system The root directory serves as the container ofr all other files and folders A Unix-based system (e.g. OS X) has a single root directoyr Windows users usually have multiple roots (C:, D:, etc) 25

Paths Each file and directory has a unique name in the filesystem Such unique name is called a path A path can be absolute or relative An absolute path is a complete and unambiguous description of where something is in relation to the root A relative describes where a folder or file is in relation to another folder 26

Paths There are two special relative paths:. and.. The single period. refers to your current directory The two periods means your parent directory, one level above 27

Home Directory User s personal files are found in the /Users directory A user directory is the home directory cd (with no other arguments) returns you to your home directory echo $HOME prints your home directory cd takes you to your home directory 28

Working Directory Another special type of directory is the so-called working directory The working directory is the current directory where you perform any task pwd prints the working directory 29

Changing Directories cd cd.. cd / cd cd /Documents 30

Absolute Path Names / directory x file A B C D x x From the root directory to D: cd /A/B/D 31

Relative Path Names / directory x file A B C D x x Changing directories from D to C cd../../c 32

Listing Contents in a Directory ls ls -1 (one entry per line) ls -l (list in long format) ls -a (show files starting with a dot) man ls (manual documentation) 33

Listing Contents in a Directory ls / (specify root directory) ls /usr (specifying a directory) ls (home directory) ls -lt (long format, sorted by modification time) 34

Listing Contents / directory x file A B C D x x Show contents in D from C ls../b/d/ 35

Inspecting Files 36

File Permissions run the command: ls -l directories may be displayed as: drwxr-xr-x files may be displayed as: -rw-r--r-- file permissions are the 10 most left characters r means reads w means write x means execute 37

File Permissions Read from left to right the permissions mean position description 1 File type. A dash - means a plain file and d means a directory. There are other less common options. 2-4 Owner permissions: read, write, and execute permissions for the file s owner. 5-7 Group permissions: read, write, and execute permissions for the file s group. 8-10 World permissions: read, write, and execute permissions for all other users. 38

Type of File Determine the type of a file: file filename 39

Some commands for inspecting text files wc filename cat filename head filename tail filename more filename less filename 40

Viewing file contents with less There are several commands that display the contents of text files The most commonly used file viewer is less less presents the contents of that file on the screen one page at a time There are various keyboard surtcuts to navigate in less 41

Viewing file contents with less key Page Up or b Page Down or space Up Arrow Down Arrow G 1G or g /hello n h q description scroll back one page scroll forward one page scroll up one line scroll down one line move to the end of text file move to the beginning of the text file search forward to next occurrence of hello search for the next search occurrence display help screen quit less 42

Quoting Files If you want a word to contain whitespace (e.g. a filename with a space in it), surround it with single or double quotes to make the shell treat it as a unit: ls "My file" 43

Exploring a file cd into a given directory List the directory contents with ls -l Determine the contents of a file with file If it looks like it might be text, try viewing it with less 44

Editing text files at the command line Sometimes it is more convenient to create or modify a file right at the command line Although less is a convenient file viewer, itdoes not allow you to edit the contents Depending on your operating system and shell tool, you may have one or more command-line text editors: e.g. vi, nano, gedit 45

Editing text files at the command line One common text editor is vi (there s also vim) It should be available in Mac, and also in Git-Bash (Windows) Depending on your operating system and shell tool, you may have one or more command-line text editors: Type which vi to fing out if you have it 46

Editing text files with vi To create and start editing a file simply type vi followed by the name of the new file: vi newfile.txt Press the I key to start editing content When you re done, press the ESC key Then type :wq to save and quit You can reopen it again with: vi newfile.txt Google vi cheat sheet to find more information 47

File Management 48

Managing Files Common actions creating a directory creating a file copying a file moving a file deleting a file searching a file 49

Managing Files Common actions creating a directory: mkdir creating a file: usually through a text editor copying a file: cp moving a file: mv deleting a file: rm searching a file:? 50

Creating Directories and Files Create a directory "summer2015" in my Documents cd ~/Documents mkdir summer2015 Create an empty file "README.md" in summer2015 cd summer2015 touch README.md 51

Copying Files cp is the command to copy files cp can be used in two ways: cp file1 file2 copies file1 into file2 cp file1 directory copies file1 into a directory (directory must already exists) 52

Copying Files Copying functions.r from Documents to HW6 cp ~/Documents/functions.R ~/Desktop/HW6/ Copying starwars.csv to current directory cp ~/Documents/starwars.csv. 53

Deleting files Deleting README.md and starwars2.csv cd ~/Documents/summer2015 rm README.md rm starwars2.csv 54

Wildcards the shell provides special characters to specify filenames these special characters are called wildcards using wildcards allow you to select filenames based on patterns of characters these wildcards are similar to some regular expression characters 55

* Wildcard Use * to refer to multiple files at once; it stands for anything $ ls AGing.txt Bing.xt Gagging.text Going.nxt ing.ext $ ls G* Gagging.txt Going.nxt $ ls *.xt Bing.xt 56

? Wildcard The question mark? represents a single character $ ls AGing.txt Bing.xt Gagging.text Going.nxt ing.ext $ ls?ing.xt Bing.xt 57

[] Wildcard Brackets [] can be replaced by whatever characters are within those characters: $ ls AGing.txt Bing.xt Gagging.text Going.nxt ing.ext $ ls [B]ing.* Bing.xt $ ls [A-G]ing.* Bing.xt 58

Combining Wildcards Wildcards can be combine: $ ls AGing.txt Bing.xt Gagging.text Going.nxt ing.ext $ ls *G* AGing.txt Gagging.txt Going.nxt $ ls *i*.*e* Gagging.text ing.ext 59

Test Yourself $ ls AGing.txt Bing.xt Gagging.text Going.nxt ing.ext What s the output of the following commands: ls *ing.*xt ls?ing.*xt ls?ing.?xt ls?ing.xt ls *ing.?xt 60

Wildcards wildcard description * matches any characters? matches any single character [characters] matches any character that is a member of the set characetrs!characters] matches any character that is not a member of the set characters [[:class:]] matches any character that is a member of the specified class 61

Wildcard Examples Pattern Matches * all files a* any file beginning with a *.txt any file ending with.txt b*.txt any file beginning with b followed by any characters and ending with.txt [gst]* any file beginning with either a g, and s, or a t [[:digit:]]* any file beginning with a number [[:upper:]]* any file beginning with an uppercase letter 62