Introduction to Linux

Similar documents
Perl and R Scripting for Biologists

Introduction to Linux

Outline. Structure of a UNIX command

CS4350 Unix Programming. Outline

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

CISC 220 fall 2011, set 1: Linux basics

Introduction to Linux. Fundamentals of Computer Science

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

Introduction to Linux Workshop 1

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

Introduction to Linux Basics

CS Fundamentals of Programming II Fall Very Basic UNIX

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

Introduction: What is Unix?

Introduction to Linux

INSE Lab 1 Introduction to UNIX Fall 2017

Mills HPC Tutorial Series. Linux Basics I

*nix Crash Course. Presented by: Virginia Tech Linux / Unix Users Group VTLUUG

INF322 Operating Systems

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

Operating Systems. Copyleft 2005, Binnur Kurt

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

Introduction to Linux

commandname flags arguments

Week 2 Lecture 3. Unix

Chapter-3. Introduction to Unix: Fundamental Commands

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

CS 215 Fundamentals of Programming II Spring 2019 Very Basic UNIX

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

Introduction to the Linux Command Line

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

Unix Filesystem. January 26 th, 2004 Class Meeting 2

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

Linux Training. for New Users of Cluster. Georgia Advanced Computing Resource Center University of Georgia Suchitra Pakala

Brief Linux Presentation. July 10th, 2006 Elan Borenstein

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]

Linux Command Line Primer. By: Scott Marshall

GNU/Linux 101. Casey McLaughlin. Research Computing Center Spring Workshop Series 2018

Getting started with Hugs on Linux

Unix basics exercise MBV-INFX410

Working with Basic Linux. Daniel Balagué

CSCI 2132 Software Development. Lecture 4: Files and Directories

Oxford University Computing Services. Getting Started with Unix

Chap2: Operating-System Structures

Practical Session 0 Introduction to Linux

Linux Systems Administration Getting Started with Linux

Unix Introduction to UNIX

12/7/10 ATSC 212 UNIX ATSC 212 ATSC 212 UNIX

Overview LEARN. History of Linux Linux Architecture Linux File System Linux Access Linux Commands File Permission Editors Conclusion and Questions

CS246 Spring14 Programming Paradigm Notes on Linux

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

A Brief Introduction to Unix

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

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

Introduction to Linux

INTRODUCTION TO LINUX

Introduction to Unix: Fundamental Commands

CENG393 Computer Networks Labwork 1

Computer Systems and Architecture

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

Session 1: Accessing MUGrid and Command Line Basics

XSEDE Scholars Program Introduction to the Linux Environment. Tips and Tricks for Linux Users John Lockman III June 5 th, 2012

Presented by Bill Genske Gary Jackson

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

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

UNIX Quick Reference

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

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

Computer Systems and Architecture

Hands-on Keyboard: Cyber Experiments for Strategists and Policy Makers

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

Linux Command Line Interface. December 27, 2017

Unix Tutorial Haverford Astronomy 2014/2015

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

Examples: Directory pathname: File pathname: /home/username/ics124/assignments/ /home/username/ops224/assignments/assn1.txt

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

BIOINFORMATICS POST-DIPLOMA PROGRAM SUBJECT OUTLINE Subject Title: OPERATING SYSTEMS AND PROJECT MANAGEMENT Subject Code: BIF713 Subject Description:

Unix Workshop Aug 2014

National University of Computer and Emerging Sciences Operating System Lab - 02 Lab Manual

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.

The Unix Shell & Shell Scripts

LAB #7 Linux Tutorial

Introduction to Linux

UTA Tech Orientation Spring 2019

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

UNIX Quick Reference

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

Command-line interpreters

CS370 Operating Systems

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

Basic Survival UNIX.

Practical Computing-II. Programming in the Linux Environment. 0. An Introduction. B.W.Gore. March 20, 2015

EECS2301. Lab 1 Winter 2016

Computer Architecture Lab 1 (Starting with Linux)

IMPORTANT: Logging Off LOGGING IN

Common UNIX Commands. Unix. User Interfaces. Unix Commands Winter COMP 1270 Computer Usage II 9-1. Using UNIX. Unix has a command line interface

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

Exercise Sheet 2. (Classifications of Operating Systems)

Linux Refresher (1) 310/ Fourth Workshop on Distributed Laboratory Instrumentation Systems (30 October - 24 November 2006)

Some useful UNIX Commands written down by Razor for newbies to get a start in UNIX

Transcription:

Introduction to Linux Phil Mercurio The Scripps Research Institute mercurio@scripps.edu 1

Session Overview What is Linux Shells & Windows The Linux File System Assorted Commands 2

What Is Linux? Linux is a free open-source operating system based on Unix. Linux was originally created by Linus Torvalds with the assistance of developers around the world. Developed under the GNU General Public License, the source code for Linux is freely available to everyone. 3

An Operating System The Kernel: a program that's always running, providing an interface to the hardware The Filesystem: schemes for storing data on disk drives, networks, and other media Libraries & Applications: a collection of software that provide services or are used directly by the user 4 User Applications Libraries Kernel Hardware

Source Code A program is a sequence of instructions in the binary language of a processor Programs are written in a higherfoo.cpp level language The human-readable text of a Compiler program is called its source code A compiler converts source code to binary code This process is irreversible #include <iostream.h> void main() { double f = 42.0; double x; } Foo.o 5 x = sqrt(f); 7F45 0004 0023 0001 0000 0014 2F6C 4E41 5F63 6D61 4C46 0008 0042 0BE4 2030 1D11 6992 4D49 7869 714D 0102 0015 0000 0F42 0000 2F75 2F54 6D6F 7400 714D 0100 0016 0001 0034 0000 7372 642E 6465 7F66 714D

The GNU Public License Software can be delivered to the end user in binary form only (closed source) Without access to the source code, the user cannot modify the software The GNU Public License is an open source license agreement Binaries can be given freely or sold, but the source code must be made freely available Modifications to the the source code must also be released under the GPL 6

From Unix to Linux The Unix operating system was developed by Bell Labs in the '70s The GNU (Gnu is Not Unix) project began in 1984 to implement a free Unix-like operating system In 1991, Linus Torvalds began to write a free Unix-like kernel called Linux, and released it under the GPL Combined with the GNU Project software, a complete operating system was built: GNU/Linux Thousands of developers throughout the world have contributed to GNU/Linux, enhancing the kernel and writing applications 7

Linux Distributions Although the source code is free, building a complete system from the source is difficult Linux vendors may add value by adding installers and commercial (closed-source) applications High compatibility across distributions that use the same kernel (current version: 2.6) 8

Shells & Windows Two most common human/computer interfaces: GUI: Graphical User Interface CLI: Command Line Interface 9

X Window System Most users are familiar with the Windows or Mac GUI desktops The GUI desktop used by most Unix systems is the X Window System: X server: application that manages the display and input devices (keyboard, mouse, etc.) X libraries: program pieces that talk to the X server X applications: complete programs built using the X libraries X window manager: an application that manages multiple X windows Desktop suite: a collection of libraries, applications, and a window manager, creating a complete desktop environment 10

Logging In and Out Linux is a multi-user operating system Your username is student Your password is cryo If the X server is running, you'll get a GUI screen where you can log in If not, you'll get a textual login: prompt After logging in, type startx to start X Use the Log Out entry on the System menu to log out or shutdown the machine CTRL-ALT-BACKSPACE will restart the X server if it gets stuck 11 This will kill all X Windows apps

Gnome Desktop 12

Using the Gnome Desktop Mac users will need to acquaint themselves with the right mouse button, sometimes used to bring up a menu Most operations performed with left mouse button Menubar at top Program menus at left Icons for frequently used programs in middle System information at right Task bar at bottom Button at left hides all open windows Middle populated with a button for each open application Squares at right switch between 4 desktops 13

File Browser The Places menu provides access to the File Browser 14

Shells The Command-Line Interface (CLI) predated the GUI Under Linux, the CLI is accessed via a shell program Bourne Shell (sh or bash) The C Shell (csh or tcsh) From the Gnome desktop, the Terminal program creates a new GUI window containing a CLI shell You may have multiple terminals open We'll use the C Shell for this class 15

The Prompt The shell begins with a prompt consisting of: The name of the machine History number (1, 2, 3...) A colon 16

A Command The user types a command, followed by ENTER The output appears below the command, followed by a new prompt 17

Structure of a Command cryo 1: man -k color prompt program arguments options Arguments are often file names Each program handles arguments in its own way Options control the execution of the program and often begin with - or - Many commands accept -h or --help and display usage info 18

Command Editing & History and scroll through the history of commands and, HOME and END for in-line editing Control-U erases entire line The command is not issued until you hit ENTER History substitutions:!! previous command!* arguments from previous command!$ last argument from previous command!4 command #4 from history!m last command that began with 'm' ^gif^png replace gif with png in previous command history prints list of commands executed 19

The Linux File System Linux has a hierarchical file system Folders are called directories The top of the hierarchy is / / /usr usr etc home /home/student bin man local passwd refine.log student practicals EMAN /home/student/refine.log 20

Current Working Directory The shell keeps track of your current location in the file system hierarchy Print your current working directory with pwd Change your current working directory with cd cryo 1: pwd /home/student cryo 2: cd /usr cryo 3: pwd /usr cryo 4: cd cryo 5: pwd /home/student 21

Pathnames A pathname is text specifying the location of a file or directory An absolute pathname begins with a / and uniquely locates a file or directory /home/student/refine.log A relative pathname specifies a location relative to the current working directory refine.log refers to the same file if cwd is /home/student Spaces aren't allowed, use \ or /home/student/my\ Files/Paper\ Abstract.doc /home/student/ My Files / Paper Abstract.doc 22

... and ~.. refers to the directory above,. refers to the cwd ~ refers to your home directory ~user refers to user's home directory cryo 1: pwd /home/student cryo 2: cd.. cryo 3: pwd /home cryo 4: cd ~ cryo 5: pwd /home/student 23

Environment Variables The shell keeps track of environment variables available to all programs Environment variables are set with setenv and displayed with printenv cryo 1: setenv LOGFILE ~/refine.log cryo 2: printenv LOGFILE /home/student/refine.log cryo 3: 24

Execution PATH The PATH is a list of directories to search for programs The program name is the name of a file somewhere on the path Use an absolute pathname to specify a program exactly cryo 1: printenv PATH /home/student/xtalview/bin/ibmpclinux2:/home /student/eman/bin:/home/student/eman2/bin:/u sr/bin:/home/student/chimera/bin:/home/stude nt/icos/allprograms:/home/student/em2em/bin: /home/student/web/bin:/home/student/spider/b in:.:/home/student/bin:/usr/local/bin:/usr/l ocal/sbin:/bin:/sbin:/usr/sbin:/usr/x11r6/bi n:/home/student/image2000/bin2000/local/stud 25

Built-Ins, Aliases, and which Some commands are built into the C shell Command shortcuts can be made with alias Identify a command with which cryo 1: which cd cd: shell built-in command. cryo 2: which d d: aliased to ls --color -FC!* cryo 3: which spider /home/student/spider/bin/spider cryo 4: 26

ls ls lists the files in the current directory cryo 1: ls 1d_result.out admin bin ccp4-5.0.2 chimera cmap.robem Desktop drivers em2em _em2em.dff EMAN EMAN2 27 fft1dca.txt GroEL icos image2000 _imagic.dff jweb laser lib map pkgs practicals refine.log scripts spider spire-1.4.0 tcltk tests tmp web xtal xtal_info XtalView

ls -F and ls -a ls -F adds / to directories and * to programs Filenames beginning with. are hidden, use ls -a cryo 1: cd ~/tests/filesys cryo 2: ls directory1 file1 program directory2 file2 cryo 3: ls -F directory1/ file1 program* directory2/ file2 cryo 4: ls -af./ directory1/ file1.hidden../ directory2/ file2 program* 28

d aliased to ls -color -FC d is a handy alias for listing directories Created in the hidden file ~/.cshrc, read by the C shell when it starts Your PATH is also set in ~/.cshrc cryo 1: cd ~/tests/filesys cryo 2: d directory1/ file1 program* directory2/ file2 cryo 3: d -a./ directory1/ file1.hidden../ directory2/ file2 program* 29

ls -l ls -l shows all the details of file ownership cryo 1: cd ~/tests/filesys cryo 2: ls -l total 24 drwxr-xr-x 2 student student 15:03 directory1 drwxr-xr-x 2 student student 15:03 directory2 -rw-r--r-- 1 student student 15:32 file1 -rw------- 1 student student 15:33 file2 -rwxr-xr-x 1 student student 15:33 program 30 4096 2005-10-26 4096 2005-10-26 3068 2005-10-26 6136 2005-10-26 15 2005-10-26

ls -l Output permissions links owner group size -rw-r--r-- 1 student student 3068 2005-10-26 15:32 file1 time modified 31 file name date modified

Groups Each user belongs to one or more groups List the groups you belong to with groups Change the group a file belongs to with chgrp cryo 1: groups student adm dialout cdrom floppy audio dip video plugdev lpadmin scanner admin cryo 2: chgrp admin file1 cryo 3: ls -l file1 -rw-r--r-- 1 student admin 3068 2005-10-26 15:32 file1 cryo 4: 32

Users and the Superuser One user is the superuser, or adminstrator The superuser logs in with the name root root can read or write any file, and can change the ownership of a file with chown cryo 1: su root Password: cryo2005 cryo 1# chown root file1 cryo 2# exit cryo 2: ls -l file1 -rw-r--r-- 1 root admin 3068 2005-10-26 15:32 file1 cryo 3: 33

Permissions o g u permissions for the user who owns the file permissions for members of the group that owns the file permissions for others, those not in the file's group -rw-r--r-file type - plain file d directory (other codes used by system files) 34 r w x read file or list directory write file or modify directory execute file as a program cd to directory

chmod chmod changes the permissions (mode) of a file chmod <mode> files... <mode> is ugoa + rwx - cryo 1: ls -l file1 -rw-------... file1 cryo 2: chmod a+rwx file1 cryo 3: ls -l!$ -rwxrwxrwx... file1 cryo 4: chmod o-w file1 ;!ls -rwxrwxr-x... file1 cryo 5: 35

Editing Files There are two popular CLI text editors: vi and emacs Both are difficult to learn Two X Windows editors are available: nedit and gedit 36

Copying, Moving, Deleting Files To copy a file: cp <source> <destination> To move a file: mv <oldname> <newname> To delete a file: rm <files...> cryo 1: ls file1 file2 cryo 2: cp file2 file3 ; ls file1 file2 file3 cryo 3: mv file1 file99 ; ls file2 file3 file99 cryo 4: rm file3 ; ls file2 file99 cryo 5: 37

Directories To make a new directory: mkdir <dir> To delete an empty directory: rmdir <dir> To delete a non-empty directory: rm -rf <dir> cp and mv accept a directory as last argument cryo 1: mkdir dir1 cryo 2: ls -F dir1/ file1 file2 cryo 3: mv file1 dir1 ; ls -F dir1/ file2 cryo 4: rmdir dir1 rmdir: `dir1': Directory not empty cryo 5: rm -rf dir1 ; ls file2 38

Specifying Filenames via Wildcards? matches a single character, * matches zero or more [] specifies a range of values for a single character cryo 1: a1 a2 cryo 2: a1 b1 cryo 3: a1 b1 cryo 4: a1 a2 cryo 5: cryo 6: cryo 7: 39 ls b1 b2 bb1 bb2 ls *1 bb1 c1 d1 ls?1 c1 d1 ls [a-c]* b1 b2 bb1 bb2 rm * ls c1 c2 c1 c2 d1 d2

Command Completion and Correction TAB causes the shell to expand filenames, presenting all the files that match what you've typed so far Works for program names too The shell will also prompt you if it thinks a command is misspelled cryo 1: ls -l bbtab bb1 bb2 cryo 1: ls bb cryo 2: emin CORRECT>eman (y n e a)? 40

cat and more cat takes input from the keyboard and outputs it to the screen, or outputs a file to the screen more outputs to the screen one page at a time cryo 1: cat Hi There! Hi There! ^D cryo 2: more longfile.txt This is a long file that would just scroll off the screen if I used cat, but because I used more it pauses at the end of each screenful and prompts me to press space to --More--(42%) 41

Redirecting Input and Output Normal input is the keyboard, output is the screen Use < to read input from a file, > to send output to a file, to send the output to another program cryo 1: cat < onelinefile This is the contents of onelinefile. cryo 2: ls > outputfile cryo 3: more outputfile onelinefile outputfile cryo 4: ls -FC ~/dirwithlotsoffiles more dir1/ dir2/ dir3/ file1 file2 file3 file4 file5 prog1* prog2* --More-42

Job Control Use & to run a program in the background jobs lists the background tasks tail -f outputs the last lines of a file as its written cryo 1: computemeaningoflife > answer & [1] 4815 cryo 2: jobs [1] + Running computemeaningoflife cryo 3: tail -f answer 00:00 Starting computation of Meaning of Life 00:10 Hmmm... this may take a while 00:20 My, this is a tricky problem, isn't it? 00:30 Still thinking... 00:40 Still thinking... 43

More Job Control Use ^C to cancel your foreground job, ^Z to suspend it bg runs the suspended job in the background kill cancels the job, fg makes it the foreground job cryo 1: computemeaningoflife 00:00 Starting computation of Meaning of Life 00:10 Hmmm... this may take a while ^Z [1] + Suspended computemeaningoflife cryo 2: bg %1 [1] computemeaningoflife & cryo 3: kill %1 [1] Killed computemeaningoflife cryo 4: 44

Remote Access Use ssh to open a shell on another computer Communication is encrypted, your password is safe -X option causes X Windows apps run on remote computer to appear on your local desktop cryo 1: ssh -X -l mercurio tippy.scripps.edu Password: Welcome to tippy.scripps.edu tippy 1: xclock ^C tippy 2: exit cryo 2: 45

du and df du reports the amount of disk space used by a directory Normally shows all subdirectories, use -s for summary df reports the amount of free space on a disk Use -h for human-readable output (ls too) cryo 1: du -s ~ 4815162 /home/student cryo 2: du -sh ~ 4.8G /home/student cryo 3: df -h ~ Filesystem Size Used Avail Use% Mounted on /dev/hda2 27G 13G 15G 47% / 46

file and Scripts file <files...> looks at the contents of a file and tries to identify it A script is a text file containing a list of commands Giving a text file x (execute) permissions makes it a script The first line of the file specifies the language cryo 1: file ~/chimera/* al2co: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.2.5, dynamically linked (uses shared libs), not stripped chimera: Bourne shell script text happydoc: a python script text itops: Bourne shell script text 47

man and info man displays the manual pages for a command Often terse, but explains all options and error messages info is an interactive program for reading more detailed documentation cryo 1: man ls LS(1) User Commands LS(1) NAME ls - list directory contents SYNOPSIS ls [OPTION]... [FILE]... DESCRIPTION List information about the FILEs --More-48