Physics REU Unix Tutorial

Similar documents
Mills HPC Tutorial Series. Linux Basics I

Introduction to the UNIX command line

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

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

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

Essential Linux Shell Commands

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

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

Helpful Tips for Labs. CS140, Spring 2015

THE HONG KONG POLYTECHNIC UNIVERSITY Department of Electronic and Information Engineering

Introduction to the Linux Command Line

Chapter-3. Introduction to Unix: Fundamental Commands

Using the Zoo Workstations

Outline. Structure of a UNIX command

User Guide Version 2.0

FILE MAINTENANCE COMMANDS

Unix Filesystem. January 26 th, 2004 Class Meeting 2

vi Primer Adapted from:

Getting Started With UNIX Lab Exercises

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

CMSC 104 Lecture 2 by S Lupoli adapted by C Grasso

Scripting Languages Course 1. Diana Trandabăț

CHE3935. Lecture 1. Introduction to Linux

CSCI 2132 Software Development. Lecture 4: Files and Directories

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]

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

Find out where you currently are in the path Change directories to be at the root of your home directory (/home/username) cd ~

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

Unix Tutorial Haverford Astronomy 2014/2015

PDS Lab Section 16 Autumn Tutorial 1. Unix Commands pwd The pwd command displays the full pathname of the current directory.

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

CENG 334 Computer Networks. Laboratory I Linux Tutorial

Unix Introduction to UNIX

Introduction to Linux

Files

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

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

Introduction: What is Unix?

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

Tutorial 1: Unix Basics

Command Line Interface The basics

INTRODUCTION TO BIOINFORMATICS

Unix File System. Class Meeting 2. * Notes adapted by Joy Mukherjee from previous work by other members of the CS faculty at Virginia Tech

Introduction to Linux. Fundamentals of Computer Science

BE CAREFUL! The Summer Research Student s Guide to UNIX

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

Short Read Sequencing Analysis Workshop

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

Introduction to Linux Environment. Yun-Wen Chen

Working with Basic Linux. Daniel Balagué

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

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

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

Linux/Cygwin Practice Computer Architecture

Oxford University Computing Services. Getting Started with Unix

LAB 0: LINUX COMMAND LINE AND SVN

h/w m/c Kernel shell Application s/w user

Welcome to getting started with Ubuntu Server. This System Administrator Manual. guide to be simple to follow, with step by step instructions

UNIX File Hierarchy: Structure and Commands

Introduction. File System. Note. Achtung!

Intro to Linux & Command Line

Practical Session 0 Introduction to Linux

Introduction to Unix - Lab Exercise 0

When you first log in, you will be placed in your home directory. To see what this directory is named, type:

Unix basics exercise MBV-INFX410

A Brief Introduction to the Linux Shell for Data Science

INSE Lab 1 Introduction to UNIX Fall 2017

Introduction to UNIX Command Line

Introduction of Linux

Linux Systems Administration Getting Started with Linux

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

Chapter 4. Unix Tutorial. Unix Shell

You should see something like this, called the prompt :

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

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

Principles of Bioinformatics. BIO540/STA569/CSI660 Fall 2010

Week 2 Lecture 3. Unix

Course 144 Supplementary Materials. UNIX Fundamentals

Lab 1: Getting Started with Linux The Extremely Illustrated Version. Graham Northup

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

Introduction to Unix: Fundamental Commands

Introduction to Linux Workshop 1

CSE115 Lab exercises for week 1 of recitations Spring 2011

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

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

15-122: Principles of Imperative Computation

UNIX Tutorial One

C++ Programming on Linux

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

CS4350 Unix Programming. Outline

Unix background. COMP9021, Session 2, Using the Terminal application, open an x-term window. You type your commands in an x-term window.

Session 1: Accessing MUGrid and Command Line Basics

CSC111 Computer Science II

The Unix Shell. Pipes and Filters

CS246 Spring14 Programming Paradigm Notes on Linux

The Directory Structure

Development Environment & Linux Guide

CMSC 201 Spring 2017 Lab 01 Hello World

CS Unix Tools. Lecture 2 Fall Hussam Abu-Libdeh based on slides by David Slater. September 10, 2010

Getting your department account

Transcription:

Physics REU Unix Tutorial What is unix? Unix is an operating system. In simple terms, its the set of programs that makes a computer work. It can be broken down into three parts. (1) kernel: The component of the operating system working behind the scenes. (2) shell: This is where the user sends commands to the kernel, i.e. it is what allows the user and the kernel to talk to one another. (3) programs: These are the executables that do things for you in Unix, and generally this means they process or create files, or both. This tutorial should lead you through the basics of finding your way around Unix, but there are many online resources that will help you to do fancier things in the Unix operating system as you become more comfortable using it. Logging into your Unix account on faraday To log into faraday (the name of one of the physics computers) from the Windows machine, open the SSH Secure Shell Client. Hit enter and type faraday into the hostname field. Then type your username into the username field. Hit enter and then type in your password. You should now be logged into faraday. It will look something like... [username@faraday ~]$ This is the shell command line and is where we will give the operating system instructions for what we want it to do. Basic commands in Unix This set of basic commands will help you to maneuver at the simplest level in Unix. There are many more commands available, and here we'll just touch upon a few. Commands should be written at the shell command line as follows... [username@faraday ~]$ commandname Changing password For example, we'll start with the passwd command, which will let you change your current password. At the shell command line type passwd and then hit enter... [username@faraday ~]$ passwd Other command will be typed at the shell command line in the same way. Listing directory contents and finding where you are Notice that there is a ~ currently in the prompt, right after faraday. This ~ indicates you are in your home directory. A lot of Unix is learning how to move between directories, create directories, create files, and move files between directories. To see what your current directory path (a path is the absolute location of your directory within the Unix file-system), type pwd at the shell command line. The command pwd stands for print working directory. The results should look like... /usr3/username

This means that your home directory is called username and it is a subdirectory within the directory usr3 (as an example, it could be usr2, usr4, etc...) Now type ls.. at the shell command line. The result should be a large list of names. We'll break this command down. ls this is the command to list the contents of a directory.. this is a Unix notation that indicates the directory one level up from where you are at So, ls.. tells the operating system to list the contents of the directory one level up from your current location. Since your current location was /usr3/username, the ls.. command listed the contents of usr3/, which was a list of all the other users who have home directories in usr3/. Now type ls../.. at the shell command line. This will list the contents of the directory two levels up from your current location. To see the contents of your current location, just type ls at the shell command line. The result will be the files and/or directories in your current location. This should show you that we can think of the Unix filesystem as a tree, i.e. (root directory) ====================== usr1 usr2 usr3 ========= ======== ======== baker leone feynman einstein hawking ====== ====== ====== ===== ===== etc etc etc etc etc pwd (prints the path of the current working directory) ls (lists contents of a directory) Making directories and moving between them Sometimes we don't just want to list the contents of directories, but we want to be able to create directories and move between them. The next set of commands we are going to learn will enable us to do this. mkdir This command will make a directory within the current directory. Usage... [username@faraday ~]$ ls (see what the contents of the current directory are) [username@faraday ~]$ mkdir testdir1 (makes a new directory called testdir1) [username@faraday ~]$ ls (check to see that you've created the new directory) Now use the mkdir command to make a second directory called testdir2, then check with the ls

command that it exists. cd This command will allow you to move between directories, it stands for change directory. Usage... [username@faraday ~]$ pwd (print the current working directory is, the result should look like /usr3/username) [username@faraday ~]$ cd testdir1 (this will move you into testdir1) [username@faraday testdir1]$ pwd (see that you've moved into testdir1, the result should look like /usr3/username/testdir1. Note that the ~ in the command line has changed to say testdir1. The command line will tell you what current directory you are in like this.) Now list the contents of testdir1 with the ls command. It should be empty! We'll put stuff in it later. To go back to your home directory you have some options, so here are a few ways to do it... [username@faraday testdir1]$ cd.. (this will take you back to home, since home is only one directory up from where we are at. In general, cd.. means go up one level in the directory tree) [username@faraday ~]$ pwd (check to see you are back in home) [username@faraday ~]$ ls (check to see what directories and files are in home) [username@faraday ~]$ cd testdir1 (go back into testdir1 so we can try the other methods of getting back to home) [username@faraday testdir1]$ cd ~ (this will take you directly back to the home directory from ANYWHERE) [username@faraday ~]$ pwd (check to see you're in home) [username@faraday ~]$ ls (check directories and files) [username@faraday ~]$ cd testdir1 (go into testdir1 so we can try the final method) [username@faraday testdir1]$ cd /usr3/username (this will take you directly back to home from ANYWHERE also) [username@faraday ~]$ pwd (check the directory path) [username@faraday ~]$ ls (check the directory contents) mkdir (makes a directory within the current directory) cd (changes from one directory to another) Creating simple text files There are MANY tools in Unix for creating and editing simple text files (files without fancy formatting like font-types, boldface type, underlines, italics, etc.). We're going to use one called vi, which has extensive functionality, but only requires just a couple of key commands to use at the most basic level. You'll learn this basic level of vi operation, and can learn how to use it in a more advanced way at online resources like http://www.eng.hawaii.edu/tutor/vi.html as an example. To start the vi editor, just type vi at the shell command line followed by the name of the file (existant or non-existant) that you want to edit. Since we don't have any files yet, we will be creating and editing a non-existant file...

[username@faraday ~]$ vi myfile1.txt This will change your screen to the vi editor, where you'll see a cursor and lots of ~'s down the lefthand side of the screen. You won't be able to type in here yet. We have to go into insert mode. To enter insert mode in vi, just type the letter i. Now go ahead and write some stuff in the editor, whatever you want. Type two or three sentences. When you're done, hit the esc key on the keyboard. This will take you out of insert mode and back into command mode. Now, to save what you did to the file and quit, you should type :wq and hit enter. The w means write and the q means quit. You'll notice that you're now back at the shell command line. Note: If you are ever in vi and want to quit without saving, you can type :q! while in command mode. This will force quit without saving. If you now type ls you should see that the file, myfile1.txt, is found in your directory. Note: To edit it further, you would just use vi myfile1.txt, if you wanted. Moving, copying, and removing files and directories The last set of basic Unix skills we'll learn are how to manipulate files, and file locations once we've created them using something like vi. Type ls and you should see that myfile1.txt is in your directory (assuming you haven't changed directories since last section). We are going to start by making a copy of this file. cp This command will allow you to copy the contents of a file into a new file. If the file you are copying to already exists, it will be overwritten, so be careful! Usage... [username@faraday ~]$ cp myfile1.txt myfile1_copy.txt (this creates a copy of myfile1.txt called myfile1_copy.txt. Note that in Unix, you cannot have spaces in the names of files like in Windows, so good practice is to name files that have multiple words in them using underscores as separators). [username@faraday ~]$ ls (you should now see both files in your directory) To check that myfile1_copy.txt is REALLY a copy of myfile1.txt, let's use the cat command. cat Unix command to concatenate (combine together) and display files. Usage... [username@faraday ~]$ cat myfile1.txt (should display the contents of myfile1.txt to the screen) [username@faraday ~]$ cat myfile1_copy.txt (should display the contents of myfile1_copy.txt to the screen) Next we are going to move these files into the directories that we already have created, testdir1 and testdir2. mv This command allows you to move a file from one location to another. It also allows files to be renamed. We'll look at both usages. Usage...

[username@faraday ~]$ mv myfile1.txt testdir1/ (moves myfile1.txt into the directory testdir1) [username@faraday ~]$ mv myfile1_copy.txt myfile2.txt (renames myfile1_copy.txt as myfile2.txt) [username@faraday ~]$ mv myfile2.txt testdir2/ Note: Again, care must be taken with the mv command. If you move a file into another directory that already has a file of the same name, it will be overwritten. If you rename a file as the same name of another file, that file will be overwritten. Unix is unforgiving, and doesn't ask you are you sure like Windows before you make these decisions. Now if you type ls you'll see that the two text files are no longer in home. Change directory to testdir1. [username@faraday ~]$ cd testdir1 [username@faraday ~]$ ls You should see the contents of this directory are only the file myfile1.txt. Now we'll learn how to get rid of this file. rm This command will remove a file from existance. There is no turning back, so you have to be absolutely sure you know what you are removing. Never, ever type rm * unless you are sure of what you are doing. The * is a wildcard, and will match everything in the current directory, so this command would say to remove everything in the current directory. In other words, you could accidentally delete files that you don't mean to delete. Usage... [username@faraday ~]$ rm myfile1.txt (this will remove the file myfile1.txt) [username@faraday ~]$ ls (You should see there is nothing in the directory now) [username@faraday ~]$ cd ~ (change back to the home directory) Finally, we'll learn how to remove directories. Unix has one safeguard in place, in that it will only let you remove empty directories. We'll see how that works. rmdir This command will remove a directory, but only if it is empty. Usage... [username@faraday ~]$ rmdir testdir2 (You should notice that Unix complains that the directory is not empty and can't be removed) [username@faraday ~]$ rmdir testdir1 (This should work, since we got rid of myfile1.txt already) [username@faraday ~]$ ls (You should now see that only testdir2 remains, and testdir1 is gone) cp copy files from one location to another, make copies of files cat combine files together and display file content to screen mv move a file from one location to another, or rename a file rm delete a file from existance rmdir delete a directory from existance, only works on empty directories ------------------------------------------------------------------------------------------------------------------------- These are all of the most basic commands you'll need to use in Unix. For more info, just search Google for unix tutorials. A good link to start is http://www.ee.surrey.ac.uk/teaching/unix/ for more practice.