Unix Tutorial Haverford Astronomy 2014/2015

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

History. Terminology. Opening a Terminal. Introduction to the Unix command line GNOME

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

The Directory Structure

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

Lab Working with Linux Command Line

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

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

Scripting Languages Course 1. Diana Trandabăț

1 Getting Started with Linux.

CSC 112 Lab 1: Introduction to Unix and C++ Fall 2009

Using the Zoo Workstations

Perl and R Scripting for Biologists

Part I. Introduction to Linux

CS Fundamentals of Programming II Fall Very Basic UNIX

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

Tutorial 1: Unix Basics

Getting Started With UNIX Lab Exercises

Chapter Two. Lesson A. Objectives. Exploring the UNIX File System and File Security. Understanding Files and Directories

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

Unix Basics. Systems Programming Concepts

CS 215 Fundamentals of Programming II Spring 2019 Very Basic UNIX

INSE Lab 1 Introduction to UNIX Fall 2017

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

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

CS CS Tutorial 2 2 Winter 2018

Introduction: What is Unix?

Introduction to Unix - Lab Exercise 0

Session 1: Accessing MUGrid and Command Line Basics

Mills HPC Tutorial Series. Linux Basics I

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

Computer Architecture Lab 1 (Starting with Linux)

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

Introduction to Linux Workshop 1

UNIX Tutorial One

CSE115 Lab exercises for week 1 of recitations Spring 2011

Getting Started with UNIX

CENG 334 Computer Networks. Laboratory I Linux Tutorial

Operating System Interaction via bash

Linux hep.wisc.edu

Linux Command Line Primer. By: Scott Marshall

Linux Kung Fu. Ross Ventresca UBNetDef, Fall 2017

Parts of this tutorial has been adapted from M. Stonebank s UNIX Tutorial for Beginners (

Basic Survival UNIX.

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

Operating Systems and Using Linux. Topics What is an Operating System? Linux Overview Frequently Used Linux Commands

Unix/Linux Primer. Taras V. Pogorelov and Mike Hallock School of Chemical Sciences, University of Illinois

LAB #7 Linux Tutorial

Physics REU Unix Tutorial

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.

Lab 2: Linux/Unix shell

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

CS 2400 Laboratory Assignment #1: Exercises in Compilation and the UNIX Programming Environment (100 pts.)

Introduction to the Linux Command Line

Computer Systems and Architecture

Parallel Programming Pre-Assignment. Setting up the Software Environment

Laboratory 1 Semester 1 11/12

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]

Chapter-3. Introduction to Unix: Fundamental Commands

Brief Linux Presentation. July 10th, 2006 Elan Borenstein

Unit 10. Linux Operating System

Operating Systems. Copyleft 2005, Binnur Kurt

UNLV Computer Science Department CS 135 Lab Manual

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

CMSC 104 Lecture 2 by S Lupoli adapted by C Grasso

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.

THE HONG KONG POLYTECHNIC UNIVERSITY Department of Electronic and Information Engineering

CpSc 1111 Lab 1 Introduction to Unix Systems, Editors, and C

Part I. UNIX Workshop Series: Quick-Start

Introduction to Linux Spring 2014, Section 02, Lecture 3 Jason Tang

CSCI 2132 Software Development. Lecture 4: Files and Directories

The kernel is the low-level software that manages hardware, multitasks programs, etc.

Tiny Instruction Manual for the Undergraduate Mathematics Unix Laboratory

Oxford University Computing Services. Getting Started with Unix

Command Line Interface The basics

Short Read Sequencing Analysis Workshop

1 Installation (briefly)

Systems Programming and Computer Architecture ( ) Exercise Session 01 Data Lab

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

Commands are in black

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

Introduction to Unix: Fundamental Commands

Essential Linux Shell Commands

A Brief Introduction to the Linux Shell for Data Science

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

EECS Software Tools. Lab 2 Tutorial: Introduction to UNIX/Linux. Tilemachos Pechlivanoglou

Guided Tour (Version 3.3) By Steven Castellucci as Modified by Brandon Haworth

COMS 6100 Class Notes 3

Linux Bootcamp Fall 2015

Introduction to Linux

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

5/8/2012. Creating and Changing Directories Chapter 7

CHEM 5412 Spring 2017: Introduction to Maestro and Linux Command Line

Linux Tutorial. Ken-ichi Nomura. 3 rd Magics Materials Software Workshop. Gaithersburg Marriott Washingtonian Center November 11-13, 2018

EKT332 COMPUTER NETWORK

commands exercises Linux System Administration and IP Services AfNOG 2015 Linux Commands # Notes

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

In this exercise you will practice working with HDFS, the Hadoop. You will use the HDFS command line tool and the Hue File Browser

Introduction to the Linux Command Line January Presentation Topics

Transcription:

Unix Tutorial Haverford Astronomy 2014/2015 Overview of Haverford astronomy computing resources This tutorial is intended for use on computers running the Linux operating system, including those in the Observatory lab and the Stokes 012 astronomy lab. This tutorial is also relevant to using the terminal environment in the OSX operating system run by Macs. The Strawbridge Observatory lab contains 6 computers: 5 computers with the Ubuntu Linux operating system and one with a Mac operating system. The Stokes 012 student astronomy research lab has ~9 computers: 5 Ubuntu Linux computers and 4 Mac computers. To conduct your research, you will be using these machines. If you sit at a Linux machine, you will be doing your actual calculations and analysis on the processors in the machine you are sitting at. If you sit at a Mac, then you will use that Mac to log into a Linux machine for your calculations. All computers have web browsers that you can use for email, blogging, and research. If you are already comfortable working with a Linux operating system, you should still read through this entire tutorial to check your familiarity, and then you may skip the tutorial except the Changing your password, Creating directories, and Edit your.bashrc file sections. Logging In If you are sitting at a Linux machine (anything that is not a Mac), log in using the username and password given to you by your advisor. The Macs have a different login system. The password for the student account on the Macs in Stokes 012 is TBD. Ask one of us and/or click the Hint button. You can only log into the Mac in the Observatory if you are a Haverford student. Linux and the terminal working environment Begin by logging into the machine in front of you. Working From a Mac To open a Terminal from a Mac (whether your laptop or a desktop), you can find the application in the Finder. Depending on the operating system of your Mac, you may also need to manually open X11 or Xquartz.

If you logged into a Mac, then you need to open a secure connection to Frank or another Linux computer. To do this, go into a terminal window and type (using your username instead of mine): ssh -X yourname@frank.astro.haverford.edu If you d like, you can open multiple terminal windows/tabs and log into Frank multiple times with this method. If you ssh to a Linux machine from a Mac and have display issues, be sure that X11 or Xquartz is running as well as terminal. Make sure the line ForwardX11Timeout 596h is at the end of your /etc/ssh_config file. Working from a Linux machine You will use terminal windows to enter and execute commands to the operating system. To open up a Terminal window, click on the circle icon on the upper left of the screen that is called Dash Home. Then select the Terminal icon from the submenu or search for Terminal. You can use the menubar that opens up when running terminal to open more than one terminal window, either by using tabs or by opening separate windows. Please try this now. Changing your password Once you are happily logged into a Linux machine and have a terminal window going, change your password with kpasswd. File Directory Structure The directory architecture used by Unix is a hierarchical tree structure, much like what you may have used in a Windows or other computing environment. When you first log onto a Unix system, you land in your home directory. Instead of clicking on folders, you navigate through the directory structure by changing directories using the command cd at the prompt in your terminal window. The directory that you are currently sitting in at a prompt is your working directory. The top of the tree is the root directory, designated with a slash sign (/). Directory names build on the root directory, with a slash designating a new branch in the directory structure. For example, the full (absolute) path name for my home directory would be /homes/bwillman/. Directories can also have relative path names, which are interpreted as starting from the present working directory. If we were in the /homes/ directory, the relative path name to my home directory would be bwillman.

Changing Directories Learn where you are in the directory structure by typing pwd which is an abbreviation for print working directory. The cd command moves you around in the directory structure, and takes an argument that is the desired destination directory. The argument can be either a relative or an absolute pathname. Try switching into one of my directories to see what is inside. Type: cd /courses/bwillman/ To switch in to one of my directories. You could also try: cd /data03/bwillman/ Unix provides some useful shortcuts for navigating directories. A single dot,., always refers to the current directory. Double dots,.. refer to the parent directory. You can therefore move into the directory /courses/bwillman from /courses/ bwillman/astr206 by simply typing: cd.. Creating Directories Create a new directory in which you will begin your research by using the command mkdir. You should make this directory in /students/username/. You can call this directory anything you d like, but for simplicity avoid whitespaces and name it something that makes sense, like code or data. mkdir code Now list the contents of your current working directory to verify that your new directory has been created.

Directories can be deleted with the rmdir command. Try creating a removing a couple of directories. Listing the Contents of a Directory The command ls is used to list the contents of a directory. Under Unix, files, directories and even devices are treated as philosophically equal, so a directory could contain any one of these types of items. The ls command can be invoked with a variety of options, which modify its action. Under Unix, command options are preceded by a hyphen. A few of the more useful forms of ls include: ls ls l ls p ls a ls t lists all filenames, including directories generates a full listing, including dates, sizes, etc distinguishes between directories and regular files lists all files, including those that begin with a., which are otherwise hidden files. lists contents by date of their creation, latest first. Try each of these ls commands in order and notice the way they indicate your home directory s contents. You can combine different options when executing a Unix command, for example: ls apt Switch into one or more of my directories and list the contents. Then use what you ve learned above to explore the contents of this directory. Practice changing into and out of directories. You can always get back to your home directory by typing cd with no arguments. Copying Files The command cp is used to copy files: cp source destination For example I could make a second copy of the file foo.txt by typing cp foo.txt foo2.txt

(There is no file named foo.txt. Its just an example.) Use what you ve learned to copy a program from one of my directories into your home directory. Some Basic Linux Commands and Programs Viewing and editing the contents of a file The tasks cat file and more file print the contents of a simple text file to the terminal window. The cat task scrolls the entire thing past with no pauses. The more task more allows you to page through the file, using the spacebar to move one screenful and the Enter key to move down one line at a time. You are probably used to using Microsoft Word to edit and save text files in.doc format. We use different programs to edit text files in a Linux operating system. I use the program emacs. You open up a file to edit with emacs by typing: emacs myfile You can do this whether or not the file yet exists. Its better if you open a file using emacs by typing: emacs myfile & The & will run emacs in the background of your terminal, freeing up your terminal prompt for you to execute commands. If you have a problem with emacs display, try using emacs2 instead of emacs. Go to the directory that you created for this class. Use emacs to create a file in which you will keep notes. Write a couple of notes, and save and close the file. Edit your.bashrc File Your.bashrc file in your home directory contains commands that you want to be executed each time you open up a terminal window. I want you to add an alias to your.bashrc file that will help prevent you from accidentally deleting files that you want. Add the line: alias rm= rm -i Save and quit this file. To compile your edited.bashrc file, type source.bashrc

Now when you try to use rm to delete a file, you should be automatically asked whether you want to actually remove the file. Filenames and Wildcards Files in the current working directory can be referred to simply by their filename. As we ve already seen, a file can also be referred to using its full directory path /homes/bwillman/foo.txt where the last element, foo.txt, is the file name. When manipulating files, Unix allows you to use * to select a subset of the objects of interest. For example, to obtain a listing of all files that end in.pro, you would type ls *.pro You could also move all files that fit a particular pattern with mv../*.pro. Redirection One of the most useful aspects of Unix is the ability to redirect streams of information, input and output to and from files and processes. The symbols >, < and >> are used to accomplish this. For example, to send the listing of all the files in the current directory into a file called foo, one would type ls a > foo This has the feature that if a file called foo existed already, it would be overwritten with the new information. You could instead append the directory listing to a preexisting file called foo by using ls a >> foo Alternatively, you can pipe the results from one process into the input stream of another process. For example, he output of the ls command can be piped into the more command using the pipe symbol, which is a vertical bar: ls l more

Who is logged in? What are they running? You can determine who s logged onto a system by typing who. You can see what processes are actively running (and what resources they are consuming) by typing top. Type q to quit the top process. You can see the status of processes running (even if they aren t appearing with a top command) using ps, process status. The man page for ps gives many different options. This is a good way to diagnose whether you are running IDL or have a web browser running without you realizing it. For example: ps -aux grep idl Will tell you whether anyone is running idl on the machine. ps -aux lists all of the processes running, and grep searches a set of information for a specific string, in this case idl. To kill a process that you can not stop another way, do: kill -9 pid where pid is the process ID number returned by top or by ps -ux (or a variant thereof). Online help under Unix The on-line documentation for Unix can be accessed through man pages, short for manual. If you remember the relevant work, you can type man k keyword Which will produce a listing of all the man pages that pertain to that topic. You can then type man foo to get specific information on the topic foo. For more detailed information you can use the info command, e.g., info foo. Because foo isn t actually a Unix command, there isn t a manual page for foo. Instead try reading the manual page for some other command that you ve used today. A Multi-tasking and Multi-user operating system

The Linux and Mac operating systems are somewhat different from what you might be used to in your own computer s system. Multiple users can be logged in at once. Also, the computer can be running multiple tasks at the same time. A single CPU can only execute one instruction at a time, but it rapidly switches between tasks so they appear to be running simultaneously. You can determine who s logged onto a system by typing who. You can see what processes are running (and what resources they are consuming) by typing top. Type q to quit the top process. You should think of the Unix system as taking input from one or more files (which includes the keyboard, as it treats devices as a kind of file). This information can then be passed through one or more processes to produce an output file. Rather than having to store intermediate results in temporary files you can pipe the results from one process into the input stream of another process. This is one of the really powerful aspects of Unix, but it takes a while to embrace this perspective. An example might help. The output of the ls command can be piped into the more command using the pipe symbol, which is a vertical bar: ls l more mini Unix Survival Guide cd name changes directory to name (relative or absolute path) cd.. changes directory up one level cd ~ changes to home directory cd (with no argument) changes to home directory pwd print current working directory (i.e. where am I?) ls lists contents of current directory ps lists processes running on the machine mkdir name creates a directory called name rm i file deletes file, but asks first. rmdir directory deletes directory, but it must be empty first more file types the contents of file to the screen, one page at a time cp file1 file2 makes a copy of file1 called file2 > file sends output stream to file, overwriting if it exists >> file appends output stream to end of file task1 task2 pipes the output of task1 into task2 man topic produces help listing on topic. info topic produces help listing on topic