Download presentation
Presentation is loading. Please wait.
Published byBelinda Jennings Modified over 9 years ago
1
Lecture 2 Linux Basic Commands,Shell and Make September 8, 2015 Kyu Ho Park
2
Computer Engineering Research Laboratory Linux Basics
3
Computer Engineering Research Laboratory 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#
4
Computer Engineering Research Laboratory 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
5
Computer Engineering Research Laboratory Shell -command interpreter ‘User’ Linux Shell
6
Computer Engineering Research Laboratory 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
7
Computer Engineering Research Laboratory Shell Syntax Variables Conditions Program control: if, elif, for, while, until, case Functions Lists
8
Computer Engineering Research Laboratory Project1-Task1
9
Computer Engineering Research Laboratory Tree search 9
10
Computer Engineering Research Laboratory $tree. ├── Algol │ ├── Ch1 │ │ ├── c1p1 │ │ ├── c1p1.c │ │ ├── c1p2 │ │ ├── c1p2.c │ │ ├── c1p3 │ │ ├── c1p3.c │ │ ├── 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 10
11
Computer Engineering Research Laboratory Interactive program
12
Computer Engineering Research Laboratory Making a script executable
13
Computer Engineering Research Laboratory Shell script( commands in a file )
14
Computer Engineering Research Laboratory variables
15
Computer Engineering Research Laboratory Quoting
16
Computer Engineering Research Laboratory if~fi if [ -d $directory ]; then ---- fi if[ -d $directory ] then --- fi
17
Computer Engineering Research Laboratory 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 ----
18
Computer Engineering Research Laboratory ‘if~fi’ control structure if condition then statements else statements fi
19
Computer Engineering Research Laboratory forSample script
20
Computer Engineering Research Laboratory for
21
Computer Engineering Research Laboratory while while condition do statements done
22
Computer Engineering Research Laboratory functions function( ) { statements }
23
Computer Engineering Research Laboratory function example
24
Computer Engineering Research Laboratory Project 2 Simple C programing Basic Linux System Calls open(),read(),write(),lseek(),close() 24
25
Computer Engineering Research Laboratory Basic Linux System Calls open(),read(),write(),lseek(),close() 25 open( ) #include 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}
26
Computer Engineering Research Laboratory read(), write() read() #include size_t read(int fildes, void *buf, size_t nbytes); write() #include size_t write(int fildes, const void *buf, size_t nbytes); 26
27
Computer Engineering Research Laboratory lseek() lseek() #include 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. 27
28
Computer Engineering Research Laboratory rand( ) rand( ) #include #define RAND_MAX 0x7ff rand() //it will generate a number of [0, 0x7ff] 28
29
Computer Engineering Research Laboratory 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. 29
30
Computer Engineering Research Laboratory make and makefile
31
Computer Engineering Research Laboratory 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.
32
Computer Engineering Research Laboratory example /*file: main.c*/ #include #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) { }
33
Computer Engineering Research Laboratory Without ‘make’ %gcc –c main.c %gcc –c test1.c %gcc –c test2.c %gcc –o test main.o test1.o test2.o
34
Computer Engineering Research Laboratory 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
35
Computer Engineering Research Laboratory test2.c is modified %vi test2.c /*file:test2.c*/ #include void test2(void) { printf(“This is test2.c\n”); } %make gcc –c test2.c gcc -0 test main.o test1.o test2.o
36
Computer Engineering Research Laboratory Macros in a makefile
37
Computer Engineering Research Laboratory
38
Label Makefile2:
39
Computer Engineering Research Laboratory make clean
40
Computer Engineering Research Laboratory 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
41
Computer Engineering Research Laboratory
42
Error
43
Computer Engineering Research Laboratory 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
44
Computer Engineering Research Laboratory 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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.