Lecture 2 Linux Basic Commands,Shell and Make

Slides:



Advertisements
Similar presentations
Exploring the UNIX File System and File Security
Advertisements

OS Project #2:Random File Access  Random file access: using the lseek() system call to access files in UNIX. zTake arguments from the command line. 
Files. System Calls for File System Accessing files –Open, read, write, lseek, close Creating files –Create, mknod.
1 Advanced programming in UNIX 1 File I/O Hua LiSystems ProgrammingCS2690File I/O.
Linux+ Guide to Linux Certification, Second Edition
CS 311 – Lecture 10 Outline Review open() and close() Difference between fopen() and open() File management system calls – read() – write() – lseek() –
Basic linux shell commands and Makefiles. Log on to engsoft.rutgers.edu Open SSH Secure Shell – Quick Connect Hostname: engsoft.rutgers.edu Username/password:
Linux Linux File System.
Introduction to Linux/UNIX. History UNIX beginnings in 1969 (Linus Torvalds is born!) AT & T Bell Laboratories (Ken Thompson & Dennis Richie) Working.
Linux Shell. 2 Linux Command-Line Interface ■ Linux shells: A shell is a command interpreter that allows you to type commands from the keyboard to interact.
POSIX: Files Introduction to Operating Systems: Discussion 1 Read Solaris System Interface Guide: Ch. 5.1 Basic File I/O.
1. This presentation covers :  User Interface Administration  Files System and Services Management 2.
Chapter 5 Bourne Shells Scripts By C. Shing ITEC Dept Radford University.
Unix Basics Chapter 4.
Introduction to Computer Organization & Systems Topics: Intro to UNIX COMP John Barr.
2INC0 Operating Systems Introduction to Linux
File Permissions. What are the three categories of users that apply to file permissions? Owner (or user) Group All others (public, world, others)
Linux+ Guide to Linux Certification, Second Edition
Vim Editor and Unix Command gcc compiler Computer Networks.
Lecture 2 Linux Basic Commands,Shell and Make September 8, 2015 Kyu Ho Park.
Chapter Two Exploring the UNIX File System and File Security.
Operating Systems Recitation 1, March th, 2002.
Shell Scripting AFNOG IX Rabat, Morocco May 2008.
UNIX Commands. Why UNIX Commands Are Noninteractive Command may take input from the output of another command (filters). May be scheduled to run at specific.
1 Operating Systems Lecture 2 UNIX and Shell Scripts.
UNIX Files File organization and a few primitives.
Introduction to UNIX Road Map: 1. UNIX Structure 2. Components of UNIX 3. Process Structure 4. Shell & Utility Programs 5. Using Files & Directories 6.
Lecture 24CS311 – Operating Systems 1 1 CS311 – Lecture 24 Outline Final Exam Study Guide Note: These lecture notes are not intended replace your notes.
Final Exam Review May 3 rd, 2004 Class Meeting 15.
System Interface Interface that provides services from the OS (Higher than BIOS) Memory Scheduler File/Storage System Inter-process Communication and Network,
Linux+ Guide to Linux Certification, Third Edition
Linux+ Guide to Linux Certification, Third Edition
Lecture 3 Introduction to Unix Systems Programming: Unix File I/O System Calls.
CSCI 330 UNIX and Network Programming Unit VII: I/O Management I.
Makefiles CARYL RAHN. Separate compilation Large programs are generally separated into multiple files, e.g. main.c addmoney.c removemoney.c money.h With.
Lecture 02 File and File system. Topics Describe the layout of a Linux file system Display and set paths Describe the most important files, including.
January 7, 2003Serguei Mokhov, 1 File I/O System Calls Reference COMP 229, 444, 5201 Revision 1.2 Date: July 21, 2004.
Copyright ©: Nahrstedt, Angrave, Abdelzaher1 Tarek Abdelzaher Vikram Adve CS241 Systems Programming System Calls and I/O.
File I/O open close lseek read and write – unbuffered I/O dup and dup2.
1 CS3695 – Network Vulnerability Assessment & Risk Mitigation – Introduction to Unix & Linux.
CSC 660: Advanced Operating SystemsSlide #1 CSC 660: Advanced OS Virtual Filesystem.
OS interface: file and I/O system calls File operations in C/C++? –fopen(), fread(), fwrite(), fclose(), fseek() in C f.open(…), f.close(…) in C++ I/O.
 Prepared by: Eng. Maryam Adel Abdel-Hady
Embedded Software Design Week II Linux Intro Linux Kernel.
1 COMP 3500 Introduction to Operating Systems Project 4 – Processes and System Calls Overview Dr. Xiao Qin Auburn University
File table: a list of opened files Each entry contains: – Index: file descriptors – Pointer to the file in memory – Access mode File descriptor is a positive.
Using System Calls (Unix) Have to tell compiler (if C/C++) where to find the headers, etc. – i.e., the “include” files May have to tell compiler where.
INTRODUCTION TO SHELL SCRIPTING By Byamukama Frank
1 2INC0 Operating Systems practical (part 1) Joris Geurts.
File System Design David E. Culler CS162 – Operating Systems and Systems Programming Lecture 23 October 22, 2014 Reading: A&D a HW 4 out Proj 2 out.
Linux Filesystem Management
By Jonathan Rinfret UNIX/LINUX By Jonathan Rinfret
EE516: Embedded Software Project 1
Commands Basic syntax of shell commands UNIX or shell commands have a basic structure command -options target command comes first (such as cd or ls) any.
Chapter 9 Shell Programming
Lecture 31: Introduction to File System
Linux file system "On a UNIX system, everything is a file;
Part 1: Basic Commands/Utilities
Makefiles Caryl Rahn.
CS314 – Section 5 Recitation 1
Introduction to UNIX.
C Programming Lecture Series
Exploring the UNIX File System and File Security
Operating System Hebrew University Spring 2004
Chapter 10: File-System Interface
Working with Mac OS and Linux
Linux Shell Script Programming
FILE I/O File Descriptors I/O Efficiency File Sharing
Chapter 5 Bourne Shells Scripts
Review.
Presentation transcript:

Lecture 2 Linux Basic Commands,Shell and Make September 6, 2016 Kyu Ho Park

Linux Basics

root 계정 전환 ubuntu@omap:~$ sudo passwd root [sudo] password for ubuntu: temppwd Enter new UNIX password: temppwd (또는 원하는 패스워드) Retype new UNIX password: temppwd (또는 원하는 패스워드를 다시 입력) passwd: password updated successfully ubuntu@omap:~$ su root Password: temppwd (또는 위에서 입력한 패스워드) root@omap:/home/ubuntu#

Linux commands File related: ls , cd, mkdir, rm, df, du, mount, unmount, mkfs touch, chmod, chown, tar, cp, mv, Process related: clear, whoami, whereis, su, pwd

Shell -command interpreter ‘User’ Linux Shell Linux

Shell programming -script : it is a file that contains shell command and it is a shell program. -Creating a Script #!/bin/bash # An example of a shell script that replaces the command ‘ls –l > output.txt’ ls –l > output.txt exit 0

Shell Syntax Variables Conditions Program control: if, elif, for, while, until, case Functions Lists

Project1-Task1

$tree . ├── Algol │ ├── Ch1 │ │ ├── c1p1 │ │ ├── c1p1.c │ │ ├── c1p2 │   │   ├── data │   │   ├── data.txt │   │   ├── ex03-01 │   │   ├── ex03-01.c │   │   ├── ex04-01 │   │   ├── ex04-01.c │   │   ├── ex10-01.c │   │   ├── ex12-01c │   │   ├── ex12-01c.c │   │   ├── ex12-01s │   │   ├── ex12-01s.c │   │   ├── fifo │   │   ├── honor │   │   ├── honor.c │   │   ├── newdata1.txt │   │   ├── newdata.txt │   │   ├── newname.txt │   │   ├── test.txt │   │   └── test.txt.soft -> test.txt │   ├── Ch2 │   │   ├── mem-region │   │   └── mem-region.c │   ├── fileTest │   │   └── data │   ├── infile │   ├── outfile │   ├── pipewr │   ├── pipewr.c │   ├── testWelcom │   ├── testWelcom.c │   └── testWelcom.s ├── clone ├── clone.c ├── DDriver │   ├── Makefile │   ├── P301 │   ├── P301.c │   ├── P303 │   ├── P303.c │   └── test.c ├── express ├── fork ├── fork.c ├── sh1 ├── shQuot ├── traverse └── treesearch

Tree search

Interactive program

Making a script executable

Shell script( commands in a file )

variables

Quoting

if~fi if [ -d $directory ]; then ---- fi if[ -d $directory ] then ---

if~fi -d file //True if the file is a directory -e file //True if the file exists -f file //True if the file is a regular file -x file //True if the file is executable ----

‘if~fi’ control structure if condition then statements else fi

forSample script

for

while while condition do statements done

functions function( ) { statements }

function example

Task 2 Simple C programing Basic Linux System Calls open(),read(),write(),lseek(),close()

Basic Linux System Calls open(),read(),write(),lseek(),close() #include <fcntl.h> #include <sys/types.h> #include <sys/stat.h> int open(const char *path, int oflags); int open(const char *path, int oflags, mode_t mode); Open with oflag=O_CREATE, we must use the three-parameter form with mode. mode: S_IRUSER: Read permission, owner S_IWGRP:Write permission, group S_IXOTH: Execute permission, others oflag={O_RDONLY,O_WRONLY,O_RDWR} ored with{O_APPEND, O_TRUNC, O_CREATE, O_EXCL}

read(), write() read() #include <unistd.h> size_t read(int fildes, void *buf, size_t nbytes); write() size_t write(int fildes, const void *buf, size_t nbytes);

lseek() lseek() #include <unistd.h> #include <sys/types.h> off_t lseek(int fildes, off_t offset, int whence); //lseek() system call sets the read/write pointer of a file descriptor fildes. whence: SEEK_SET: offset is an absolute position, SEEK_CUR:offset is relative to the current position, SEEK_END:offset is relative to the end of the file.

rand( ) rand( ) #include <stdlib.h> #define RAND_MAX 0x7ff rand() //it will generate a number of [0, 0x7ff]

memalign() memalign() allocates size bytes and returns a pointer to the allocated memory. The memory address will be a multiple of boundary, which must be a power of two.

make and makefile

make [-f filename] % make [-f filename] - if you don’t use –f option, the default file is Makefile or makefile. -if there are Makefile and makefile at the same time, Makefile will be selected.

example /*file: test.h*/ /*file: main.c*/ #include <stdio.h> #include “test.h” int main(void) { test1(); test2(); printf(“Hello world!\n”); return 0; } /*file: test.h*/ void test1(void); void test2(void); /*file: test1.c*/ void test1(void) { } /*file: test2.c*/ void test2(void)

Without ‘make’ %gcc –c main.c %gcc –c test1.c %gcc –c test2.c %gcc –o test main.o test1.o test2.o

With ‘make’ -Makefile %vi Makefile test : main.o test1.o test2.o gcc –o test main.o test1.o test2.o main.o : test.h main.c gcc –c main.c test1.o : test.h test1.c gcc –c test1.c test2.o : test.h test2.c gcc –c test2.c %make gcc –c main.c gcc –c test1.c gcc –c test2.c gcc –o test main.o test1.o test2.o

test2.c is modified %vi test2.c /*file:test2.c*/ #include <stdio.h> void test2(void) { printf(“This is test2.c\n”); } %make gcc –c test2.c gcc -0 test main.o test1.o test2.o

Macros in a makefile

Label Makefile2:

make clean

Typical MACRO var. #Which compiler CC =gcc #Option flags CFLAGS = -g –Wall #Program source files SRCS = main.c test1.c test2.c #object files OBJS #Library files LIBS #Library directories LIBDIRS

Implicit rule $@ #Name of the current target $? # List of prerequisites(files the target depends on) #changed more recently than the current target $< #Name of the current prerequisite $* #Name of the prerequisite, without any suffix

Kernel Compile 1.Kernel Configuration to give the information of current H/W, Kernel, Network characteristics to the newly made kernel. -make config, make menuconfig, make xconfig 2.Kernel compile -make bzImage or make zImage( for a small sized kernel) - make( after Linux version 2.6) 3.Kernel install -make install