Using the Unix system. UNIX Introduction

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

Unix Basics. UNIX Introduction. Lecture 14

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

Scripting Languages Course 1. Diana Trandabăț

Introduction to the UNIX command line

Mills HPC Tutorial Series. Linux Basics I

CMPT 300. Operating Systems. Brief Intro to UNIX and C

TNM093 Practical Data Visualization and Virtual Reality Laboratory Platform

Practical Session 0 Introduction to Linux

Introduction to Linux

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

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

FILE MAINTENANCE COMMANDS

Basic C Programming. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

Working with Basic Linux. Daniel Balagué

Carnegie Mellon. Linux Boot Camp. Jack, Matthew, Nishad, Stanley 6 Sep 2016

Unix Tools / Command Line

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

Chapter 1 - Introduction. September 8, 2016

Introduction to the Linux Command Line

CS 261 Recitation 1 Compiling C on UNIX

UNLV Computer Science Department CS 135 Lab Manual

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

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.

Introduction to Linux (Part II) BUPT/QMUL 2018/03/21

Getting Started with UNIX

CISC 220 fall 2011, set 1: Linux basics

A Brief Introduction to Unix

Intermediate Programming, Spring Misha Kazhdan

Laboratory 1 Semester 1 11/12

Exercise 1: Basic Tools

Introduction to Linux Workshop 1

Unix Basics. Systems Programming Concepts

Std: XI CHAPTER-3 LINUX

Lab Working with Linux Command Line

The Directory Structure

Introduction to Unix: Fundamental Commands

Introduction. File System. Note. Achtung!

Linux/Cygwin Practice Computer Architecture

Week 2 Lecture 3. Unix

Introduction of Linux

Chapter-3. Introduction to Unix: Fundamental Commands

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

The Unix Shell & Shell Scripts

Introduction to Linux. Fundamentals of Computer Science

CSE 391 Lecture 1. introduction to Linux/Unix environment

Introduction to UNIX command-line II

INSE Lab 1 Introduction to UNIX Fall 2017

UNIX Quick Reference

Introduction to Supercomputing

Linux Tutorial. Ken-ichi Nomura. 3 rd Magics Materials Software Workshop. Gaithersburg Marriott Washingtonian Center November 11-13, 2018

Development Environment & Linux Guide

Introduction to Linux Environment. Yun-Wen Chen

CHAPTER 1 UNIX FOR NONPROGRAMMERS

Using the Zoo Workstations

Introduction to Linux (Part I) BUPT/QMUL 2018/03/14

A Brief Introduction to the Linux Shell for Data Science

First of all, these notes will cover only a small subset of the available commands and utilities, and will cover most of those in a shallow fashion.

Computer Systems and Architecture

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. Woo-Yeong Jeong Computer Systems Laboratory Sungkyunkwan University

Unit 13. Linux Operating System Debugging Programs

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

Perl and R Scripting for Biologists

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

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

Operating Systems. Copyleft 2005, Binnur Kurt

CSE 15L Winter Midterm :) Review

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

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

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

Introduction to UNIX Command Line

CS370 Operating Systems

Unix and C Program Development SEEM

Unit 10. Linux Operating System

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

CSE 391 Lecture 1. introduction to Linux/Unix environment

Computer Systems and Architecture

Recitation #1 Boot Camp. August 30th, 2016

CMPUT 201: Practical Programming Methodology. Guohui Lin Department of Computing Science University of Alberta September 2018

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

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

Parts of this tutorial has been adapted from M. Stonebank s UNIX Tutorial for Beginners (

Introduction to Cygwin Operating Environment

CENG 334 Computer Networks. Laboratory I Linux Tutorial

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

UNIX Tutorial Two

Introduction: The Unix shell and C programming

Introduction to Linux

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

CSCI 2132 Software Development. Lecture 5: File Permissions

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

CS246 Spring14 Programming Paradigm Notes on Linux

CS 460 Linux Tutorial

CS Fundamentals of Programming II Fall Very Basic UNIX

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

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

Introduction to Linux

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

Command Line Interface The basics

Transcription:

Using the Unix system Navigating the Unix file system Editing with emacs Compiling with gcc UNIX Introduction The UNIX operating system is made up of three parts: the kernel, the shell and the programs The UNIX kernel manages program access to system hardware and software resources The shell acts as an interface between the user and the kernel. 1

Tree Directory Structure Concepts Root directory Current directory Home directory Absolute path Relative path 2

Unix file security Each file has owner and group Permissions set by owner Read, write, execute Owner, group, other Only owner, root can change permissions This privilege cannot be delegated or shared Access Lists and Groups Mode of access: read, write, execute Three classes of users RWX a) owner access 7 1 1 1 RWX b) group access 6 1 1 0 RWX c) public access 1 0 0 1 3

A Sample UNIX Directory Listing Basic Unix Commands (1) n ls list files and directories n ls -a list all files and directories n mkdir name make a directory n cd name change to named directory n cd change to home-directory n cd ~ change to home-directory n cd.. change to parent directory n pwd display current directory path 4

Basic Unix Commands (2) n cp file1 file2 copy file1 and call it file2 n mv file1 file2 move or rename file1 to file2 n rm file remove a file n rmdir directory remove a directory n cat file display a file n more file display a file a page at a time n who list users currently logged in n * match any number of characters n? match one character n man read online manual for a command Basic Unix Commands (3) n command > file redirect standard output to a file n command >> file append standard output to a file n command < file redirect standard input from a file n grep keyword file search a file for keywords grep science science.txt n wc file count number of lines/words/characters in file wc -w science.txt n sort sort data (numerically or alphabetically) sort < biglist (the sorted list will be output to the screen) 5

Basic Unix Commands (4) chmod [options] file change access rights for named file For example, to remove read write and execute permissions on the file biglist for the group and others, type chmod go-rwx biglist This will leave the other permissions unaffected. To give read and write permissions on the file biglist to all, chmod a+rw biglist Text editor EMACS 6

Text Editor emacs Configurable, extensible text editor To start emacs just call it typing emacs Basic editing in emacs is very intuitive use arrows, PG UP and PG DOWN to move cursor use DEL key to delete BACK key to delete backwards typing insert text at the cursor position To edit an existing file type emacs filename Using emacs: keyboard commands We use the following abreviations C is the Control key - between two letters mean both have to be pressed simultaneously Basic commands C-x, C-s - save the file C-x, C-c - exit Emacs 7

Basic emacs Commands Cursor movement C-f (forward one char.) C-b (backward one char.) C-a (begin of line) C-e (end of line) C-n (next line) C-p (prev. line) C-v (page up) alt-v (page down) C-x C-j (jump to line) Deletion C-d (delete one char) alt-d (delete one word) C-k (delete line) Paste Undo C-y (yank) C-/ Load file C-x C-f Cancel C-g Save/Quit C-xC-c (quit w/out saving) C-xC_s (save) C-xC-w (write to a new file) Searching in Emacs C-s : search for a string this search is incremental and goes as you search typing C-s again will search for the next occurrence of the same string to go back to the editing, just press any arrow key after you go back, typing C-s twice resumes the search 8

GCC Compiler Compilation Review Source code Assembly Machine Code object.cpp object.s object.o object.h Output main.s main.o main.cpp 9

What is gcc? Stands for GNU C/C++ Compiler Popular console-based compiler for Unix platforms and others gcc to compile C programs; g++ for C++ gcc file1.c compile and link a C program g++ file1.c compile and link a C++ program output is an executable called a.out gcc file1.c o file1 produce executable file1 As always: there is man gcc Options There are zillions of them, but there are some the most often used ones: To compile: -c Specify output filename: -o <filename> Include debugging symbols: -g Show all (most) warnings: -Wall Be stubborn about standards: -ansi and -pedantic Optimizations: -O, -O* 10

Options: -c gcc performs compilation and assembly of the source file without linking Output is object code files,.o; they can later be linked and form the desired executables Generates one object file per source file keeping the same prefix (before.) of the filename gcc c file1.c Output is file1.o Options: -o <filename> Places resulting file into the filename specified instead of the default one. Can be used with any generated files (object, executables, assembly, etc.) If you have the file called source.c; the defaults are: source.o if -c was specified a.out if executable These can be overridden with the -o option. 11

Options: -g Includes debugging info in the generated object code. This info can later be used in gdb gcc allows to use -g with the optimization turned on (-O) in case there is a need to debug or trace the optimized code. Options: -Wall Shows most of the warnings related to possibly incorrect code. -Wall is a combination of a large common set of the -W options together. These typically include: unused variables possibly uninitialized variables when in use for the first time defaulting return types missing braces and parentheses in certain context that make it ambiguous Always a recommended option to save your bacon from some hidden bugs. Try always using it and avoid having those warnings. 12

Options: -ansi and -pedantic For those who are picky about standard compliance -ansi ensures the code compiled complies with the ANSI C standard -pedantic makes it even more strict These options can be quite annoying for those who don t know C well Options: -O, -O1, -O2, -O3, -O0, -Os Various levels of optimization of the code -O1 to -O3 are degrees of optimization targeted for speed If -O is added, then the code size is considered -O0 means no optimization -Os targets generated code size (forces not to use optimizations resulting in bigger code) 13

Options: -I Tells gcc where to look for include files (.h) Can be any number of these Usually needed when including headers from various-depth directories in non-standard places, eg. #include myheader.h vs. #include../foo/bar/myheader.h For Your Assignments For your assignments, I strongly suggest to always include -Wall and g Optionally, you can try to use -ansi and pedantic, which is a bonus thing towards your grade Do not use any optimization options You won t probably need the rest as well 14

Example For example, if you have the following source files in some project of yours: fileops.h fileops.c process.h process.c parser.h parser.c You could compile every C file and then link the objet files generated, or use a single command for the entire thing. This becomes unfriendly when the number of files increases; hence, use Makefiles! NOTE: you don t NEED to compile.h files explicitly. One by one: Compiling Example gcc -g -Wall -ansi -pedantic -c parser.c gcc -g -Wall -ansi -pedantic -c fileops.c gcc -g -Wall -ansi -pedantic -c process.c This will give you four object files that you need to link and produce an executable: gcc parser.o fileops.o process.o o parser 15

Makefile Example # Simple Makefile with use of gcc could look like this CC=gcc CFLAGS=-g -Wall -ansi -pedantic OBJ:= parser.o process.o fileops.o EXE=parser all: $(EXE) $(EXE): $(OBJ) $(CC) $(OBJ) -o $(EXE) parser.o: parser.h parser.c $(CC) $(CFLAGS) -c parser.c... 16