UNIX Basics. UNIX Basics CIS 218 Oakton Community College

Similar documents
Introduction: What is Unix?

Table of contents. Our goal. Notes. Notes. Notes. Summer June 29, Our goal is to see how we can use Unix as a tool for developing programs

acmteam/unix.pdf How to manage your account (user ID, password, shell); How to compile C, C++, and Java programs;

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

Shell Programming Systems Skills in C and Unix

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

Chapter-3. Introduction to Unix: Fundamental Commands

Introduction to UNIX command-line

Lecture 3. Unix. Question? b. The world s best restaurant. c. Being in the top three happiest countries in the world.

Computer Systems and Architecture

Introduction to Unix: Fundamental Commands

CS246 Spring14 Programming Paradigm Notes on Linux

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

Introduction to Linux

Unix Introduction to UNIX

Computer Systems and Architecture

Perl and R Scripting for Biologists

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

Introduction to UNIX command-line II

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

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

Linux for Beginners. Windows users should download putty or bitvise:

5/20/2007. Touring Essential Programs

5/8/2012. Exploring Utilities Chapter 5

Introduction to Linux Part 1. Anita Orendt and Wim Cardoen Center for High Performance Computing 24 May 2017

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

Introduction to Linux

Introduction to Linux Organizing Files

Files and Directories

CSCI 2132 Software Development. Lecture 4: Files and Directories

Useful Unix Commands Cheat Sheet

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

Files

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.

EECS 470 Lab 5. Linux Shell Scripting. Friday, 1 st February, 2018

Basic Linux (Bash) Commands

Week 2 Lecture 3. Unix

CST Algonquin College 2

Essential Unix (and Linux) for the Oracle DBA. Revision no.: PPT/2K403/02

Introduction to Linux

Today. Operating System Evolution. CSCI 4061 Introduction to Operating Systems. Gen 1: Mono-programming ( ) OS Evolution Unix Overview

Unix Handouts. Shantanu N Kulkarni

Introduction. Let s start with the first set of slides

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

Introduction. File System. Note. Achtung!

Mills HPC Tutorial Series. Linux Basics I

Command-line interpreters

UNIX Kernel. UNIX History

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

Welcome to Linux. Lecture 1.1

Unix as a Platform Exercises + Solutions. Course Code: OS 01 UNXPLAT

Today. Operating System Evolution. CSCI 4061 Introduction to Operating Systems. Gen 1: Mono-programming ( ) OS Evolution Unix Overview

Chapter 1 - Introduction. September 8, 2016

Processes. Shell Commands. a Command Line Interface accepts typed (textual) inputs and provides textual outputs. Synonyms:

IMPORTANT: Logging Off LOGGING IN

An Introduction to Unix Power Tools

CISC 220 fall 2011, set 1: Linux basics

Shells and Shell Programming

Lecture # 2 Introduction to UNIX (Part 2)

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

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

Set 1 MCQ Which command is used to sort the lines of data in a file in reverse order A) sort B) sh C) st D) sort -r

Introduction to Linux

Unix Tools / Command Line

EECS2301. Lab 1 Winter 2016

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

Linux Command Line Primer. By: Scott Marshall

UNIX Quick Reference

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

CS 25200: Systems Programming. Lecture 11: *nix Commands and Shell Internals

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

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

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

Linux & Shell Programming 2014

Introduction to Linux

CS 307: UNIX PROGRAMMING ENVIRONMENT KATAS FOR EXAM 2

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

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

Scripting Languages Course 1. Diana Trandabăț

Introduction to Linux. Roman Cheplyaka

Lab 2: Linux/Unix shell

Unix as a Platform Exercises. Course Code: OS-01-UNXPLAT

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

A Brief Introduction to the Linux Shell for Data Science

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

CSE 391 Lecture 1. introduction to Linux/Unix environment

Introduction to Linux

Shells and Shell Programming

Introduction to Linux Workshop 1

Virtual Machine. Linux flavor : Debian. Everything (except slides) preinstalled for you.

System Programming. Introduction to Unix

Answers to AWK problems. Shell-Programming. Future: Using loops to automate tasks. Download and Install: Python (Windows only.) R

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

Unix System Architecture, File System, and Shell Commands

Introduction to Linux

Short Read Sequencing Analysis Workshop

Std: XI CHAPTER-3 LINUX

Where can UNIX be used? Getting to the terminal. Where are you? most important/useful commands & examples. Real Unix computers

Transcription:

UNIX Basics UNIX Basics CIS 218 Oakton Community College

History UNIX was invented in 1969 at AT&T Bell Labs Ken Thompson and Dennis Ritchie are credited as the original architects and developers of C. Written in the C programming language in 1973 Resold under UNIX System License (USL) Current USL version SystemV R4 Different commercial flavors: Solaris (Sun), AIX (IBM), Irix (SGI), HPUX (Hewlett Packard), SCO Academic version BSD (Mac OS X base) UNIX Variants LINUX, UNIX ports Android, MAC OSX

UNIX Unix Design Design Modularity Each part of the Unix system is a system unto itself printing, networking, mail, file management, accounting, etc. Many Unix systems can be run in different modes. This allow for a certain set of modules to be run based on usage (workstation, server). UNIX utilities are independently developed packages

UNIX Layers

UNIX Versus DOS/Windows UNIX everything is a file UNIX is case sensitive, DOS is not UNIX searches $PATH for executables, DOS starts in current directory, then PATH. UNIX is multi-user, DOS is not. Windows is (kind of) UNIX GUI sits on top of the OS - same as Windows thru ME). This changed After NT. UNIX directory has one starting point root /. Windows has multiple A:, C:, D: etc.

UNIX Versus DOS/Windows DOS UNIX Command Description CD pwd Display current directory CD \ cd / Moves to the root directory CD.. cd.. Moves up one level in the directory structure CD path cd path Sets the current directory to a new directory CHKDSK du Displays disk usage CLS clear Clear the screen COMMAND sh, csh.. Start a new shell (command processor) COMP cmp Compares two files and shows the difference COPY cp Copy a file DATE date Displays the date DEL or ERASE rm Deletes a file DELTREE rm -r Deletes a directory tree ( CAREFUL!!! ) DIR ls -l Lists the directory in a long format DIR /W ls Lists the directory in a short format ECHO echo Displays a message or a variable EXIT exit End a shell FC diff Displays differences between two files FIND grep Displays lines matching a given pattern HELP man Display information about a command MD or MKDIR mkdir Creates a directory MORE more Displays text a page at a time MOVE mv Moves a file PRINT lpr Prints a file RD or RMDIR rmdir Removes a directory REN mv Renames a file SET set Sets a variable to a given value SORT sort Sorts a data TIME date Displays the time TYPE cat Displays a file

Shells Shell sh original interface to UNIX Bourne Shell added some desirable features but has different syntax for some things Newer Bourne Shell variants are Korn Shell (ksh) and Born Again Shell (bash) C Shell C program language syntax, tcsh, Perl Program Extract and Reporting Language Some systems allow user to chose which shell you prefer with chsh. The full path to the shell must be given

The Shell When you log in to interact with UNIX, you see a shell prompt ($ or %) A word is a text string separated by white space space, Tab or IFS The shell is a program that runs constantly and executes the commands you give it A command is the first word on a line. All following words are command line parameters Commands terminators: <LF> Enter or Return, ;,, >

UNIX command line You interact with the Unix by entering commands thru thee shell. The line is parsed as text sepaated by whitspace caracters into words or tokens. The first word is always a command. The basic form of any Unix command is: Command Option(s) Argument(s) Most commands provide integral help or on-line Manual (man page) Options or flags modify the way that a command works. They usually consist of a hyphen followed by a single letter.

Unix file types (ls l) d: Directory - holds other files or directories. -: Normal Files Text files - text that is human readable. Binary files - executable files l: Link - allows space efficient copying of files/directories. Symbolic or soft - may span file systems. Hard - is indistinguishable from the original file/directory..: Hidden File - any file that begins with a. (dot). c,b: Character or Block Special Files hardware interface. virtual files pipes, semaphores, sockets.

Files and Directories UNIX uses a single hierarchy to store files beginning with root / Files are a named collection of bytes juliana Project File1 File2 File3 Directories contain other files (or not)

Basic Directory Terms Home directory (~ ) - top of your file tree: Root directory (/ ) - top of a file tree: Current directory (.) - directory you re in now (pwd) Dot (.) - current directory Dot-dot (..) - parent of current directory Path - Where to find file or directory Absolute path: /fs/scd/home0/juliana/myfile Relative path:./myfile Standard files STDIN, STDOUT, STDERR

Managing Files and Directories cd - change directories (built into shell) pwd present working directory mkdir - creates a directory rmdir - removes a directory (must be empty first) rm myfile1 - remove a file rm -fr - removes directory and everything below touch <filename> - creates an empty file cat <filename> - displays a file on screen more <filename> - to see a screenful at a time mv myfile1 myfile2 - renames (moveas) a file

Tar and Compress - Tar stands for tape archive but is more often used to gather files into one bundle. Equivalent of a ZIP file, without the compression. - cd to the directory above the one you want to archive tar cvf - diry_name > diry.tar - To list the archive, use tar -xvf diry.tar - To untar the archive, use tar -xvf diry.tar - Compressed files take up less space. To compress a tar file, use compress diry.tar or gzip diry.tar - To uncompress, use uncompress diry.tar.z or gunzip diry.tar.gz - Note equivalent gzip commands: zcat, zgrep, zmore, zdiff

File Permissions You own your files and directories user-group-other read/write/execute permissions -rw-r--r-- 1 jsmith staff 164870 27 Feb 17:58 6.bmp -rw-r--r-- 1 jsmith staff 164870 27 Feb 17:57 5.bmp + to add, - to remove alphabetic permissions r=4, w=2, x=1 so rwx: 4+2+1=7 for numeric chmod command changes permissions chmod 604 6.bmp chmod g-rw 6.bmp -rw----r-- 1 jsmith staff 164870 27 Feb 17:58 6.bmp

File Permissions Access rights on files. r : indicates read permission (or otherwise), that is, the presence or absence of permission to read and copy the file w : indicates write permission (or otherwise), that is, the permission (or otherwise) to change a file x : indicates execution permission (or otherwise), that is, the permission to execute a file, where appropriate Access rights on directories. r : allows users to list files in the directory; w : allows users to delete files from the directory or move files into it; x : allows users the right to access files in the directory (e.g. cd into directory), read files in the directory provided you have read permission on the individual files.

File Permissions Symbol Meaning u user g group o other a all r read w write (and delete) x execute (and access directory) + add permission - take away permission

User Commands for Files What s in my directory? ls db5-24 nwade.txt schumacher5-19.txt kirsh5-12.txt nwade5-13a.txt sheu5-20.txt ls -alt -rw-r--r-- 1 jsmith staff 712 24 May 09:12 db5-24 -rw-r--r-- 1 jsmith staff 1660 12 May 12:12 kirsh5-12.txt -rw-r--r-- 1 jsmith staff 3610 11 May 08:16 ming.txt -rw-r--r-- 1 jsmith staff 2444 10 May 16:53 mingrep Wildcard - * stands for any (# of) character(s) Wildcard -? stands for any single character [abcde ] selection set, any single character within the brackets

User Commands for Files wc - word, line, character, and byte count echo - echo characters back (print) sort - sort lines of a text file uniq remove consecutive duplicats lines cut/paste/join manipulate data by physical location in a record or file sed stream editor, vi commands in a batch file awk string manipulation tr translate from one character to another strings review a binary file for text od examine a file for binary contents head, tail display begin and end of a file cat copy to stdout cp copy a file

Finding and Searching diff find differences between two text files find - a tricky but useful command find. -name myfile -print find. -name *name* print exec cmd {} \; grep - stands for general regular expression print Search all files for a pattern: grep -i lightning system * grep -v lightning system * grep -c gee whiz *

Wildcard characters Wildcard characters can be used to represent many other characters in listing filenames. Use them whenever you need to define a string of characters, such as a filename, for use with a command. Useful wildcards are: * matches any characters, zero or more.? match any single character. [...] matches any character in the enclosed list or range. Examples: ls *.txt # Lists all the files in the current directory # that have the extension.txt. cat memo? # Concatenate files that start with memo # and are followed by any one character. rm part[1-3] # Remove files: part1, part2 and part3

Input/Output (I/O) and Redirection By default, a terminal keyboard is the standard input file (STDIN) from which to read in information Terminal is also the standard output file (STDOUT) to which information is sent from the command. Input can be given from the command line, or from a file: a.out < inputfile Output goes to your screen, or you can redirect it to a file: echo hi there > out.file To append, use >> echo hi back at you >> out.file here document for inline stdin << EOF Use the tee filename command to redirect out put to both STDOUT and a file.

Input/Output (I/O) and Redirection <& m Duplicates standard input from file descriptor m [n] >& m Duplicates standard output or file descriptor n if specified from file descriptor m i.e. 2>&1 [n] <&- Closes standard input or file descriptor n if specified [n] >&- Closes standard output or file descriptor n if specified. or pipe (prior slide) is also redirection. It redirects STDOUT from the preceding command to STDIN of the following command. The general term for the following command is called a filter as it modifies or filters the output of the preceding command..

Pipes You can string commands together into a single command using pipes ( ) ps grep juliana - what am I running now Save the results in a file: who wc > usercount Used with file manipulation commands as filters who wc - count how many users on the system

System Info Commands System Uptime uptime What time is it? date Where is a command? which ls whereis ls How do I use a command? man ls

System Info Commands Where am I? pwd - print working directory cwd - current working directory Who am I? whoami Who is on the system? What s running? who, w ps ef, -aux

More Useful Commands, cont. passwd - change password chsh change default shell lpr - print a file (printer at OCC) history - (C shell builtin) - list of previous commands alias - create a pseudonym or shorthand for a command (behaves differently for C versus Bourne shell)

Editing - vi Front end to ed Universal among UNIX and it s variants vi somefilename (copies file into memory buffer) Three modes command mode, text mode(esc), operator line(:) determines how keystrokes are interpreted by vi

Editing vi (commands) i insert text x delete a character r replace a character R replace text yy p copy a line dd delete a line /text locate text / - repeat last find <Enter> or <Return> - ends a line :wq save results and quit (:wq! force overwrite of file) :q - quit (no save) Navigation: arrow keys or HJKL