Introduction to UNIX (Based on slides by Michael Siegenthaler)

Slides:



Advertisements
Similar presentations
Learning Unix/Linux Bioinformatics Orientation 2008 Eric Bishop.
Advertisements

Introduction to UNIX Cornell University CS 316 – Fall 2006 Slides by Michael Siegenthaler.
Unix. Outline Commands Environment Variables Basic Commands CommandMeaning lslist files and directories ls -alist all files and directories mkdirmake.
NETW-240 Shells Last Update Copyright Kenneth M. Chipps Ph.D. 1.
©Colin Jamison 2004 Introduction to Linux Colin Jamison.
Cosc 4750 Getting Started in UNIX Don’t be afraid of the prompt, in linux it can be your best friend. In some cases, the only way to do certain things.
Introduction to UNIX Cornell University CS 316 – Fall 2007 Slides by Jed Liu (Based on slides by Michael Siegenthaler)
T UTORIAL OF U NIX C OMMAND & SHELL SCRIPT S 5027 Professor: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015.
Lecture 02CS311 – Operating Systems 1 1 CS311 – Lecture 02 Outline UNIX/Linux features – Redirection – pipes – Terminating a command – Running program.
LINUX COMMAND LINE INTERFACE Lab 3 EECS 448 Dr Fengjun Li and Meenakshi Mishra.
7/17/2009 rwjBROOKDALE COMMUNITY COLLEGE1 Unix Comp-145 C HAPTER 2.
Linux Commands LINUX COMMANDS.
CS 141 Labs are mandatory. Attendance will be taken in each lab. Make account on moodle. Projects will be submitted via moodle.
Using Macs and Unix Nancy Griffeth January 6, 2014 Funding for this workshop was provided by the program “Computational Modeling and Analysis of Complex.
Introduction to Linux Workshop February Introduction Rob Lane & The HPC Support Team Research Computing Services CUIT.
Unix Primer. Unix Shell The shell is a command programming language that provides an interface to the UNIX operating system. The shell is a “regular”
Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell.
1 Lecture 2 Working with Files and Directories COP 3344 Introduction to UNIX.
Lesson 1. PC vs. Multi-user System  Personal Computer – each user gets his/her own processor (or multicore processor).  Multi-user system – The processor,
Essential Unix at ACEnet Joey Bernard, Computational Research Consultant.
Unix Basics Chapter 4.
Basic unix commands that everyone should know (Even if you have a mac) Slightly more advanced:
CS 6560 Operating System Design Lecture 3:Tour of GNU/Linux.
The Shell Chapter 7. Overview The Command Line Standard IO Redirection Pipes Running a Program in the Background Killing (a process!)
System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007 Reference:  chapter 1, The Unix Programming Environment, Kernighan & Pike, ISBN.
Additional UNIX Commands. 222 Lecture Overview  Multiple commands and job control  More useful UNIX utilities.
Session 2 Wharton Summer Tech Camp Basic Unix. Agenda Cover basic UNIX commands and useful functions.
INTRODUCTION TO LINUX Jacob Chan. GNU/Linux Consists of Linux kernel, GNU utilities, and open source and commercial applications Works like Unix –Multi-user.
Unix/Linux cs3353. The Shell The shell is a program that acts as the interface between the user and the kernel. –The shell is fully programmable and will.
Lesson 2-Touring Essential Programs. Overview Development of UNIX and Linux. Commands to execute utilities. Communicating instructions to the shell. Navigating.
Linux file system "On a UNIX system, everything is a file; if something is not a file, it is a process." Sorts of files (on a Linux system) Directories:
Lecture 24CS311 – Operating Systems 1 1 CS311 – Lecture 24 Outline Final Exam Study Guide Note: These lecture notes are not intended replace your notes.
Introduction to Programming Using C An Introduction to Operating Systems.
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 2a – A Unix Command Sampler (Courtesy of David Notkin, CSE 303)
Linux Commands C151 Multi-User Operating Systems.
1 Lecture 2 Working with Files and Directories COP 3353 Introduction to UNIX.
1 Introduction to Unix. 2 What is UNIX?  UNIX is an Operating System (OS).  An operating system is a control program that helps the user communicate.
A Brief Overview of Unix Brandon Bohrer. Topics What is Unix? – Quick introduction Documentation – Where to get it, how to use it Text Editors – Know.
1 CS3695 – Network Vulnerability Assessment & Risk Mitigation – Introduction to Unix & Linux.
Lecture 1: Introduction, Basic UNIX Advanced Programming Techniques.
Introduction to Linux Workshop February 15, 2016.
File Management commands cat Cat command cat cal.txt cat command displays the contents of a file here cal.txt on screen (or standard out).
Linux Tutorial Lesson Two *Getting Help in Linux *Data movement and manipulation *Relative and Absolute path *Processes Note: see chapter 1,2,3 from Linux.
Learning Unix/Linux Based on slides from: Eric Bishop.
INTRODUCTION TO SHELL SCRIPTING By Byamukama Frank
UNIX To do work for the class, you will be using the Unix operating system. Once connected to the system, you will be presented with a login screen. Once.
Tutorial of Unix Command & shell scriptS 5027
Chapter 11 Command-Line Master Class
Linux 101 Training Module Linux Basics.
Linux Commands Help HANDS ON TRAINING Author: Muhammad Laique
Part 1: Basic Commands/Utilities
Some Linux Commands.
C151 Multi-User Operating Systems
CSE 374 Programming Concepts & Tools
INTRODUCTION TO UNIX: The Shell Command Interface
Tutorial of Unix Command & shell scriptS 5027
Basic UNIX OLC Training.
Introduction to UNIX.
Tutorial of Unix Command & shell scriptS 5027
CS 60 Discussion Review.
Tutorial of Unix Command & shell scriptS 5027
Tutorial Unix Command & Makefile CIS 5027
Linux Shell Script Programming
CSE 303 Concepts and Tools for Software Development
Linux Commands LINUX COMMANDS.
January 26th, 2004 Class Meeting 2
LPI Linux Certification
Presentation transcript:

Introduction to UNIX (Based on slides by Michael Siegenthaler)

Why Bother? Most programmers who learn UNIX end up finding it useful Provides powerful command-line interface –Many simple tasks are easier to accomplish –Possible to script repetitive operations Widely used in research and industry, and runs most of the servers on the Internet

UNIX Philosophy Multiuser / multitasking Toolbox approach –Combine multiple simple commands instead of using a single complex application Designed by programmers for programmers

Shelling into CSUG From Windows –PuTTY –Cygwin From MacOS, open a terminal and type –ssh

Transferring Files Use WinSCP

Command Line Environment Shell is the command line interpreter –Just another program –Bourne shell ( bash ) –C Shell ( csh ) Default shell in CSUG is tcsh This talk uses bash –Switch to bash: exec bash

Running Commands Commands follow the form: –command –Options modify the command –Arguments indicate what file to operate on Get help by typing man command Example: ~]$ ls -l /usr total 301 drwxr-xr-x 2 root root Oct 18 08:43 bin/ drwxr-xr-x 2 root root 4096 Aug etc/ drwxr-xr-x 2 root root 4096 Aug games/ drwxr-xr-x 117 root root Sep 12 20:40 include/...

Plumbing I/O Redirection >Redirect standard output to file >>Append standard output to file <Get input from file Pipes (|) are used to take the output of one program and use it as input to another e.g. du -sk /home/* | sort -nr | head -10 > disk_hogs.txt

Practical Tips Use less to view output that will not fit on your screen e.g. ls -lR | less Use grep to filter output, and wc to count lines e.g. ps aux | grep “vim” | wc -l Use && to run multiple commands in sequence e.g../configure && make && make install

File System Case sensitive! Moving around, working with directories cd Change working directory pwd Print working directory ls -la List all files in working directory mkdir Make directory rmdir Remove directory cp Copy file mv Move or rename file rm Delete a file Searching e.g. find -name Makefile

How to understand the File System /]$ ls / amd bin boot courses dev etc home initrd lib lib64 localdisk lost+found media misc mnt opt proc root sbin selinux srv sys tmp usr var /]$ ls /courses cs3110 cs3410 cs3410stf cs4411 /]$ ls /courses/cs3410 mipsel-linux README /]$ ls /courses/cs3410/mipsel-linux/ bin include info lib libexec man mipsel-linux share ~]$ ls /amd/daffodil/a/ ab397 al644 bc352 cek37 cs722 db493 dtt6 gey2 hs465 jjs87 js368 kk67 mjp63 ng292 pae26 rh335 rw347 sr533 tbw32 xl ~]$ ls /amd/daffodil/a/da279/ for.c for.c~ for.s hello.c hello.s

Viewing File Contents Use cat or less : $ cat hw1.c # use cat for short files #include “test-include.h” _start() { } $ less hw1.s # use less for long files You can also use vi or emacs!

Comparing Files Use diff : $ cat file1 Hello! This is the contents of file1. Goodbye. $ cat file2 Hello! This is the contents of file2. Goodbye. $ diff –u file1 file2 --- file :25: file :25: ,3 +1,3 Hello! -This is the contents of file1. +This is the contents of file2. Goodbye.

How to use gcc /tmp]$ ls hello.c /tmp]$ gcc -o hello hello.c /tmp]$ ls hellohello.c /tmp]$./hello Hello World!

How to use mipsel-linux-gcc To create the.o file: /courses/cs3410/mipsel-linux/bin/mipsel- linux-gcc -c foo.c - Object file is created and saved in foo.c To create the.s file: /courses/cs3410/mipsel-linux/bin/mipsel- linux-gcc -S foo.c - MIPS Assembly Code is created and saved in foo.s - You can actually run these instructions in your Processors!

Plumbing Running multiple commands in sequence –Use semicolon (;) to run commands unconditionally –Use double ampersand (&&) to run commands only until the first error occurs Use parentheses to group a sequence and redirect output e.g. (date && ls) > logfile Not the same as: date && ls > logfile

Wildcards Shorthand for referencing multiple existing files on the command line –*any number of characters –?exactly one character –[abc]any one of a, b, or c –[!abc]any character except a, b, or c Examples ls -l *.c lpr [Mm]akefile

File System Permissions Permissions can be specified for –Owner –Group –All Permissions are –Read –Write –Execute Example: -rwxr-xr-x 1 msiegen ta Sep 21 17:04 disassemble -rw-r msiegen ta 329 Sep 21 17:04 main.c The disassembler may be executed by anyone on the system, but the source file may only be read by people in the ta group. Both files may only be edited by the user msiegen.

File System Permissions For a directory, “read” means being able to list its contents, “execute” means being able to access files within the directory –Unless the files have more restrictive permissions Use chmod to add or remove permissions (rwx) for user, group, and others (ugo): chmod ugo+x Let anyone execute chmod go-w Prevent non-owner form writing Or, specify absolute permissions in octal –4=r, 2=w, 1=x –e.g. 755=rwxr-xr-x, 640=rw-r----- e.g. chmod 755 filename

Job Control Use & after a command to place job in background Manage jobs: –jobsList jobs –fg %1Bring job 1 to foreground –bg %2Run job 2 in background –kill %3Terminate job 3 –^Z(control+Z) suspend foreground job –^C(control+C) terminate foreground job

Job Control Example ~]$ sleep 800 & [1] ~]$ sleep 400 & [2] ~]$ jobs [1]- Running sleep 800 & [2]+ Running sleep 400 & ~]$ kill %1 ~]$ jobs [1]- Terminated sleep 800 [2]+ Running sleep 400 & ~]$ fg %2 sleep 400 ^Z [2]+ Stopped sleep 400 ~]$ bg %2 [2]+ sleep 400 &

Environment Variables Display all variables by typing env Set a variable, example: NETID=abc123; export NETID (bourne shell) setenv NETID abc123 (c-shell) Use a variable in a command, example: echo $NETID Environment variables are used to control various behaviours of the shell, as well as pass global information to other programs that are started from within the shell The variable $PATH is used to locate programs that are run

Beyond a Single User ps aux List all running processes who ; w Show who else is logged in top Show CPU, memory usage (useful for finding out why a system is soooo slow, and who to blame)

Some Useful Commands fileDetermine the type of a file sortSort lines in a text stream uniqEliminate duplicate lines wcCount bytes, words, or lines calDisplay a calendar grepFilter a text stream sedSearch and replace on text stream awk(Slightly) more advanced scripting

Advanced Topics Shell scripting –Anything which can be done from the command line, can be scripted Regular expressions –Fancier version of wildcards –Allows complex matching and search and replace operations on text –Suppored by grep, awk, and many scripting/programming languages

Further Reading Manual (man) pages O’Reilly Books –Free access on campus: –Or from home through the Safari Tech Books link at: