Introduction to Linux

BCH 519
Spring 2017

Andrew E. Bruno
aebruno2@buffalo.edu

BCH519 Students

Please pick up a USB Key!

    USB Key

Schedule

Outline for this lecture

  • What is Linux?
  • Command Line Boot Camp
  • Edit files
  • Login to CCR

An operating system is a collection of software that manages computer resources

Operating systems

  • Windows
  • Mac OS X
  • UNIX
  • Linux

A very brief history of UNIX...

UNIX

UNIX Features

  • Multi-user, multi-tasking, time-sharing
  • Large number of users to interact concurrently with a single computer
  • Consists of many utility programs or commands
  • Master control program called the kernel
  • Use plain text for storing data
  • Hierarchical file system

UNIX Philosophy

UNIX has many descendents..

Unix History Img Source: https://en.wikipedia.org/wiki/File:Unix_history.svg

Linux

Tux

Linux

  • A "Unix-Like" operating system
  • GNU Project started in 1983 by Richard Stallman, to create "complete UNIX-compatable software system" composed entirely of free software
  • Linux kernel first developed by Linus Torvolds in 1991
  • Together they make the GNU/Linux operating system
  • Free and open source
  • Many flavors: RedHat, Debian, Ubuntu, Porteus..

Why Linux?

  • Center for Computational Research (CCR)
  • Leading academic supercomputing facility
  • Operates a datacenter with hundreds of Linux computers
  • To run jobs at CCR, you need to be familiar with Linux

Let's boot into Linux!

    Slax instructions

Operating systems have user interfaces

  1. GUI - Graphical User Interface
  2. CLI - Command Line Interface
In the Beginning..Was the Command Line
-- Neal Stephenson
Porteus desktop

CLI - Command Line Interface

  • Control the computer with commands
  • "Shell" - a program that accepts commands and performs operation system functions
  • We'll be using a shell called BASH

Anatomy of the shell

  • There's a prompt: [aebruno2@rush:~]$
  • You type in commands
  • Shell executes the commands
  • Prints output to the screen
  • Repeat

How to read the SHELL

Example grep command

Anatomy of a command

  • Basic form: command options arguments
  • command = name of the command
  • options = modify the behavior of the command
  • arguments = expression or filename
  • Commands can be simple: echo, date
  • More complex: find . -type f -name \*.py

Command Line Boot Camp

Simple commands

  • Print todays date:
    
    $ date
    Tue Dec 11 14:42:04 EST 2012
        
  • Echo a string:
    
    $ echo "Hello World"
    Hello World
        

Simple commands

  • What's my username?
    
    $ whoami
    aebruno2
        
  • What computer am I logged into?
    
    $ hostname --fqdn
    k07n14.ccr.buffalo.edu
        

Getting help

  • man page (short for manual page)
  • Usage: man [command name]
    
    $ man echo
    $ man grep
        

Download and print!

GNU Coreutils Cheat Sheet

http://www.catonmat.net/download/gnu-coreutils-cheat-sheet.pdf

Files, Directories, and Paths

  • Basic unit is a File
  • Files are organized in directories (folders)
  • Navigate filesystem using paths

/home/aebruno2/bch519/hello.py

Linux File System

Moving around

  • Print the current working directory: pwd
  • List all files: ls
  • Change working directory: cd
  • Move up a directory (go back): cd ..

$ pwd
/user/aebruno2
$ ls
projects bch519 docs hello-world.txt
$ cd bch519
$ pwd
/user/aebruno2/bch519
$ ls
hello.py test.py README.txt
$ cd ..
$ pwd
/user/aebruno2
    

File Basics

  • Create a file: touch
  • Copy files: cp
  • Rename files: mv
  • Remove files: rm
  • View files: cat,less,more

$ touch hello-world.txt
$ ls
hello-world.txt
$ cp hello-world.txt goodbye-world.txt
$ ls
hello-world.txt goodbye-world.txt
$ mv goodbye-world.txt new-file.txt
$ rm goodbye-world.txt
$ cat hello-world.txt
Hello World!
    

Text Manipulation

  • Search for patterns in file: grep
  • Find differences between files: diff
  • Print first/last n lines: head, tail
  • Count lines, words, characters: wc
  • Print selected parts of file: cut
  • Sort file: sort

$ grep "pattern" my_file
$ diff -u file1 file2
$ head -n 20 my_file
$ tail -n 20 my_file
$ wc -l my_file
$ cut -f 1,3 my_file
$ sort my_file
    

Input/Output redirection

  • > takes output from command and writes it to file
  • >> takes output from command and appends it to file
  • < takes input from file and sends it to command

$ echo "Hello World" > hello.txt
$ cat hello.txt
Hello World
$ echo "Goodbye" >> hello.txt
$ cat < hello.txt
Hello World
Goodbye
$ grep "Hello" hello.txt > results.txt
$ cut -f 1,3 output.txt > columns-1-3.txt
    

Pipes

  • Allows you to "chain" commands together
  • | = pipe
  • | take output from command on left and send as intput to command on right

$ cat my_file.txt | wc -l
$ cat my_file.txt | grep -i "hello"
$ echo "Hello World" | wc -c > num-chars.txt
$ echo "1234" | rev
4321
    

Editing Files

  • Editor: A program for editing text files
  • Most important tool for programmers
  • We will use an editor to author Python programs

Editors

Img Source: http://xkcd.com/378/

GNU nano

GNU nano basics

  • Start: nano <filename>
  • ^ = Ctrl key
  • Save file: ^O
  • Quit: ^X
  • Search: ^W
  • Help: ^G

GNU nano

GNU nano

Accessing computers remotely

  • Login to server
  • Run programs, execute commands, etc.
  • We use SSH: Secure SHell
  • Allows us to connect to remote Linux server using encrypted network channel

How to login to CCR

  • Open terminal program (shell)
  • Run: ssh username@host
  • Enter in password when prompted

$ ssh aebruno2@rush.ccr.buffalo.edu
password:
[aebruno2@rush:~]$ 
    

Copy files to rush

  • Use command: scp
  • Usage: scp [LOCAL file] [REMOTE file]
  • Enter in password when prompted

$ scp myfile.py aebruno2@rush.ccr.buffalo.edu:~/bch519
    

Homework #1

  • Due: 2017-02-14 09:00:00