CHE3935. Lecture 1. Introduction to Linux

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

Linux/Cygwin Practice Computer Architecture

Mills HPC Tutorial Series. Linux Basics I

Helpful Tips for Labs. CS140, Spring 2015

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

Introduction. File System. Note. Achtung!

Lab 3a Using the vi editor

Short Read Sequencing Analysis Workshop

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

Introduction to Linux Environment. Yun-Wen Chen

Physics REU Unix Tutorial

CS 143A. Principles of Operating Systems. Instructor : Prof. Anton Burtsev

Linux Systems Administration Getting Started with Linux

Introduction to the Linux Command Line

Introduction to Linux. Fundamentals of Computer Science

15-122: Principles of Imperative Computation

Introduction to Linux. Woo-Yeong Jeong Computer Systems Laboratory Sungkyunkwan University

Basic Linux Command Line Interface Guide

Basic Linux Command Line Interface Guide

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

A Brief Introduction to the Linux Shell for Data Science

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

CS CS Tutorial 2 2 Winter 2018

FILE MAINTENANCE COMMANDS

Part I. UNIX Workshop Series: Quick-Start

THE HONG KONG POLYTECHNIC UNIVERSITY Department of Electronic and Information Engineering

Std: XI CHAPTER-3 LINUX

Chapter 1 An Introduction to C++, Unix, SSH and Komodo Edit

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.

CS101 Linux Shell Handout

Outline. Structure of a UNIX command

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

Introduction to Unix and Linux. Workshop 1: Directories and Files

Chapter-3. Introduction to Unix: Fundamental Commands

Linux Shell Script. J. K. Mandal

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

Unix File System. Learning command-line navigation of the file system is essential for efficient system usage

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

CISC 220 fall 2011, set 1: Linux basics

Using the Zoo Workstations

Introduction: What is Unix?

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

Week Overview. Unix file system File types and file naming Basic file system commands: pwd,cd,ls,mkdir,rmdir,mv,cp,rm man pages

Chapter 1 An Introduction to C++, Unix, SSH and Komodo Edit

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]

AMS 200: Working on Linux/Unix Machines

Introduction to the UNIX command line

vi Primer Adapted from:

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

5/20/2007. Touring Essential Programs

Introduction to Linux Workshop 1

Basic Survival UNIX.

Introduction. SSH Secure Shell Client 1

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

User Guide Version 2.0

Operating Systems. Copyleft 2005, Binnur Kurt

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

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

Introduction to UNIX Command Line

: the User (owner) for this file (your cruzid, when you do it) Position: directory flag. read Group.

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

Introduction to Linux

Introduction to Linux

Lecture # 2 Introduction to UNIX (Part 2)

The Command Shell. Fundamentals of Computer Science

COMS 6100 Class Notes 3

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

Perl and R Scripting for Biologists

CS246 Spring14 Programming Paradigm Notes on Linux

CENG 334 Computer Networks. Laboratory I Linux Tutorial

Unix basics exercise MBV-INFX410

Oregon State University School of Electrical Engineering and Computer Science. CS 261 Recitation 1. Spring 2011

Development Environment. ICLAB NCTU Institute of Electronics

Introduction to Linux

Getting started with Hugs on Linux

CS 215 Fundamentals of Programming II Spring 2019 Very Basic UNIX

Introduction to Unix: Fundamental Commands

EE516: Embedded Software Project 1. Setting Up Environment for Projects

CS4350 Unix Programming. Outline

INTRODUCTION TO UNIX

CS Fundamentals of Programming II Fall Very Basic UNIX

Getting started with Hugs on Linux

One of the hardest things you have to do is to keep track of three kinds of commands when writing and running computer programs. Those commands are:

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

Lab Working with Linux Command Line

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

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

Hand-on Labs for Chapter 1 and Appendix A CSCE 212 Introduction to Computer Architecture, Spring

Editors in Unix come in two general flavours:

UNIX. The Very 10 Short Howto for beginners. Soon-Hyung Yook. March 27, Soon-Hyung Yook UNIX March 27, / 29

Command Line Interface The basics

Setting up and running the pyrophosphate tools under the Knoppix GNU Linux system

Lab 2: Linux/Unix shell

mkdir Phys338 s2017 Draw the tree of the directories and files for this step and all the following cd Phys338 s2017

Course 144 Supplementary Materials. UNIX Fundamentals

Getting Started With UNIX Lab Exercises

Introduction to Linux for BlueBEAR. January

Introduction to Linux (Part II) BUPT/QMUL 2018/03/21

27-Sep CSCI 2132 Software Development Lab 4: Exploring bash and C Compilation. Faculty of Computer Science, Dalhousie University

Getting Started. Running Utilities. Shells. Special Characters. Special Characters. Chapter 2 Unix Utilities for non-programmers

Transcription:

CHE3935 Lecture 1 Introduction to Linux 1

Logging In PuTTY is a free telnet/ssh client that can be run without installing it within Windows. It will only give you a terminal interface, but used with a PC X Window server and tunneling X11 through ssh should be able to launch graphical applications as well Open PuTTY by going to C:\tools and double clicking on putty.exe In the Host Name box type puccini.che.pitt.edu Type your pitt.edu username at the login as: prompt Your initial password is username @new12 Change your password by typing yppasswd and following the instructions Make sure to choose a secure, strong password that is not the same as your pitt.edu password. 2

Some Basic Commands (1) See http://collab.sam.pitt.edu/dev/karls-course for more detailed instructions There are many different Linux shells you will be using the bash shell (bournagain shell, free replacement of the Bourn shell, and combines, bashes together, features of sh, csh, and ksh shells) The commands you type at the command line prompt are bash commands First command: ls -la type this and see what you get This is a directory listing (many commands are like abbreviated words without vowels, ls = list in this case) The -la part adds options. Compare by typing ls What do you get? Second command: man ls The man command lists manual pages for all bash commands, so man ls gives the manual page for the ls command. Look at the manual page for ls and find out what -la does. Hint: Move forward and backward on the man page by using the f (or space ) and b keys. Hint: You can search for text within the man page by pressing the / key and then typing text to match. Note: The search is Case Sensitive! Type n for the next search match and p for the previous search match. 3

Some Basic Commands (2) Locating commands: which ls Now try ls /bin Note that /bin is a directory (folder). Changing directories: cd /bin puts you into the /bin directory, which you do not own, but you can visit. Find out where you are: pwd stand for print working directory. Now type cd followed by pwd to see where you went. Making directories can be done with the mkdir command. Type man mkdir to see how it works. Make a directory called tmp by typing mkdir tmp Type ls l to see your newly created directory then cd tmp to go into that directory. Type ls and ls -la to see what is in your directory. 4

Some Basic Commands (3) So far you don t have any files, so let s create some to play with. Type the following (in your tmp directory): echo This is my first file > file1 Now type ls -l to see your file and cat file1 to dump the contents of the file to your screen. The cat command concatenates one or more files and sends them to the standard output. Note that you can redirect the output to a file as well. For example, create another file by typing echo This is another file > file2 Now type ls -l to see that both files are there. Now you can cat the contents of both files to a third file: cat file1 file2 > file3 Now type ls followed by cat file3 to see what you have done. 5

Some Basic Commands (4) File manipulation: Moving, copying, and deleting files can be accomplished with the mv, cp, and rm commands, respectively. Try them and see how they work! Use the man pages if you need to. Note that these commands are like driving without seatbelts or airbags. E.g., if you do cp file1 file2 you will clobber file2 replacing it with file1 with no warning. We will now change this behavior. Type cd to get to your home directory then type the following: echo "alias rm='rm -i'" >.bash_aliases echo "alias cp='cp -i'" >>.bash_aliases echo "alias mv='mv -i'" >>.bash_aliases source.bash_aliases Now try these commands and see what happens. The.bash_aliases file should be read whenever you log in from now on so that you can drive with some seatbelts. 6

Text Editing With vim(1) There are many text editors available in the Linux environment, but vi (or vim=vi improved) will work on any terminal and is something everyone claiming Linux expertise should know. There are many vi tutorials on the web. E.g., http://linuxconfig.org/vim_tutorial I encourage you to try these out. The thing about vi that will take some getting used to is that it does not behave like any text editor you have used before (probably). It has two modes of operation: (1) visual mode (where you can move around in the file, issue keyboard commands to delete characters, words, etc., issue commands on the command line, etc., and (2) insert mode where you can type text into the file. This is fundamentally different from all modern text editors. The reason for this is that these modes allow you to use any keyboard to run vi as long as it has the esc key and the regular alphanumeric keys. You don t need arrow keys, a mouse, or anything else. This was very useful in the olden days when keyboards didn t have arrow keys and a computer mouse was a rodent who programmed. Let s copy a file from somewhere so we can practice editing stuff with vi (which is actually vim on puccini) cp ~webpages/web-docs/johnson_pub.html. ls l 7

Text Editing With vim(2) Edit the file: vi johnson_pub.html You are automatically in visual mode when you open any file. You can move the cursor around using the hklj keys, with h=left, k=up, l=right, j=down. Try it and see what happens. You can also use the arrow keys. Now let s quit the file without saving changes. Type :q! and you should be back at the bash command line. The : means go to the command line within vi, q means quit and! means discard any changes. Get back into the file and let s learn some more features. Edit the file: vi johnson_pub.html There are many things you can do in visual mode. Delete characters: x=delete the character under the cursor, X=delete character to the left of the cursor (note that vi commands are case sensitive) Delete words: dw Delete from cursor position to end of line: d$ or D Move to the beginning of a word: w Move to the end of a word: e Repeat a command n times: ncommand E.g., 15x will delete 15 characters, 7w will move forward 7 words, etc. Undo a command: u Try these out! 8

Text Editing With vim(3) Now you have made changes to a file you can either quit without saving or you can save the file (and quit). Try typing :q and see what happens. Now type :wq to write and quit. A shortcut for wq is x, i.e., :x does the same thing as :wq You can also save the file at any point by typing :w and then continuing with editing the file. Saving the file with a new name: :w filename Edit the file again and let s play some more. Let s enter the insert mode. You can do this in a number of ways. Insert at cursor position: i Append at end of line: A Open new line below current line: o Open new line above current line: O To get out of insert mode, hit the esc key. Try it. Note that you can move around using the arrow keys, but not the hjkl keys (for obvious reasons). Practice going in and out of insert mode to get the hang of it. It becomes very natural after some practice. You can repeat the last command by typing. in visual mode. Try it by inserting a word, hit escape, then move the cursor and type. to insert the word again in a new place. 9

Text Editing With vim(4) Let s go back to visual mode and learn some more commands Delete a line: dd Yank (copy) lines: yy Paste anything just deleted or copied: p or P Replace a single character: r or multiple characters: R Go to end or beginning of line: $ or 0 Go to end of file: G Go to beginning of file: gg or 1G Go to line n: ng Execute a shell command within vi: :!cmd, e.g., :!ls -la will list all files in the current directory Read in a file to the current file: :r filename Edit a different file: :e filename Try these commands 10

Text Editing With vim(5) Search and regex: vi uses regular-expressions (regex) in searching. This is a very powerful pattern language. See http://www.regular-expressions.info/ for details. We will only scratch the surface of regex Searches in vi are case sensitive by default. To ignore case type :set ic in visual mode. Basic search: /regex or?regex where regex is the expression to search for. E.g., search for Zhang in the file by typing /Zhang Find next or previous: n or N Examples of regex search: /[1-4] finds any number in the range 1-4. /<sub>\d finds the characters <sub> followed by any digit. \[A-Z] finds any upper case letter, etc. There are many other things you can do with regex searching. 11

Text Editing With vim(6) Search and replace Replace the first occurrence of str1 with str2 on a single line: :s/str1/str2 Replace all occurrences on a single line: :s/str1/str2/g where g=global Replace all occurrences in a file: :%s/str1/str2/g Confirm each replace: :%s/str1/str2/gc Replace all occurrences between lines n and m: :n,ms/str1/str2/g, e.g., :10,50s/Johnson/Nosnhoj/g replaces every occurrence of Johnson with Nosnhoj anywhere in the range of lines 10 to 50. Try these commands 12

More Shell Commands The shell provides scripting capabilities that are very powerful. See http://linuxconfig.org/bash_scripting_tutorial for an introductory tutorial To see some examples of scripts that are run every time you login go to your root directory and edit the.bashrc file: vi.bashrc Note the alias commands, note the case esac pairs. Try to figure out what each line does. Be careful not to change this file or you could mess up your shell environment. In order to run scripts the files containing the scripts must be executable. You can make any file executable by using the chmod command. This command controls all the file attributes or permissions. See, for example, http://en.wikipedia.org/wiki/chmod 13