+ All Categories
Home > Documents > Linux Command

Linux Command

Date post: 14-Jan-2016
Category:
Upload: butch
View: 63 times
Download: 1 times
Share this document with a friend
Description:
Linux Command. Simple linux cmds. ls List information about FILEs, by default the current directory. pwd Print Working Directory cd Change Directory - change the current working directory to a specific Folder. Simple linux cmds. cp Copy one or more files to another location mv - PowerPoint PPT Presentation
21
1 Linux Command
Transcript
Page 1: Linux Command

1

Linux Command

Page 2: Linux Command

Advanced Compiler Laboratory 2

Simple linux cmds

ls List information about FILEs, by default the cur

rent directory. pwd

Print Working Directory cd

Change Directory - change the current working directory to a specific Folder.

Page 3: Linux Command

Advanced Compiler Laboratory 3

Simple linux cmds

cp Copy one or more files to another location

mv Move or rename files or directories.

rm Remove files (delete/unlink)

touch Change file timestamps, change the access and/or m

odification times of the specified files.

Page 4: Linux Command

Advanced Compiler Laboratory 4

Simple linux cmds

mkdir Create new folder(s), if they do not already exi

st. rmdir

Remove folder(s), if they are empty. cat

Display the contents of a file (concatenate)

Page 5: Linux Command

Advanced Compiler Laboratory 5

Simple linux cmds

passwd Modify a user password.

chmod Change access permissions

History Command Line history

man Display helpful information about commands.

Page 6: Linux Command

Advanced Compiler Laboratory 6

make

Definition make is utility to maintain groups of

programs

Object If some file is modified, make detects it

and update files related with modified one.

It can use to command based programs

Page 7: Linux Command

Advanced Compiler Laboratory 7

make basic rules

3 components target, dependency, command

file format file name: Makefile format :

target: dependency[tab] comand

Page 8: Linux Command

Advanced Compiler Laboratory 8

make example

make 를 사용하지 않을때 $gcc –c main.c $gcc –c add.c $gcc –c sub.c $gcc –o test main.o add.o sub.o

혹은 , gcc –o test main.c add.c sub.c

Page 9: Linux Command

Advanced Compiler Laboratory 9

make example

test : main.o add.o sub.ogcc –o test main.o add.o sub.o

main.o: addsub.h main.cgcc –c main.c

add.o: add.cgcc –c add.c

sub.o: sub.cgcc –c sub.c

command 앞에는 반드시 [tab] 을 사용할 것

Page 10: Linux Command

Advanced Compiler Laboratory 10

make example

어느 때 어떤 target 이 다시 컴파일 될 것인가 ? main.c 가 바뀌었을 경우

add.c 혹은 sub.c 가 바뀌었을 경우

addsub.h 가 바뀌었을 경우

Page 11: Linux Command

Advanced Compiler Laboratory 11

label

clean:rm *.o test

레이블로 사용될 때는 의존관계 부분이 없어도 된다 .

실행 방법 make clean

Page 12: Linux Command

Advanced Compiler Laboratory 12

macro

CC=gccSRC=main.c add.c sub.cmain: ${SRC}

${CC} –o test ${SRC}

Page 13: Linux Command

Advanced Compiler Laboratory 13

미리 정해져 있는 매크로

make –p 를 통하여 모든 값들을 확인 가능 ASFLAGS = <- as 명령어의 옵션 세팅 AS = as CFLAGS = <- gcc 의 옵션 세팅 CC = cc (= gcc) CPPFLAGS = <- g++ 의 옵션 CXX = g++ LDLFAGS = <- ld 의 옵션 세팅 LD = ld LFLAGS = <- lex 의 옵션 세팅 LEX = lex YFLAGS = <- yacc 의 옵션 세팅 YACC = yacc

Page 14: Linux Command

Advanced Compiler Laboratory 14

확장자 규칙

확장자 규칙 target 에 확장자 규칙을 적용 확장자를 보고 그에 따라 적절한 연산을 수행시키는

규칙 .SUFFIX 매크로

make 파일에서 주의 깊게 처리할 파일들의 확장자 등록

.c.o .c 를 확장자로 가지는 파일을 .o 를 확장자로 갖는

파일로 바꾸는 규칙을 직접 정의

Page 15: Linux Command

Advanced Compiler Laboratory 15

확장자 규칙의 예

.SUFFIXES : .c .o OBJECTS = main.o add.o sub.o CC = gcc CFLAGS = -g -c TARGET = test $(TARGET) : $(OBJECTS) $(CC) -o $(TARGET) $(OBJECTS) .c.o : $(CC) $(CFLAGS) $< clean : rm -rf $(OBJECTS) $(TARGET) core main.o : addsub.h main.c add.o : addsub.h add.c sub.o : addsub.h sub.c

Page 16: Linux Command

Advanced Compiler Laboratory 16

확장자 규칙의 예

CC=gccOBJS= main.o add.o sub.otest3:${OBJS}

${CC} –o $@ ${OBJS} .c.o:

gcc –c $<

Page 17: Linux Command

Advanced Compiler Laboratory 17

매크로 치환

$(MACRO_NAME:OLD=NEW) SRC=main.c OBJ=$(SRC:.c=.o)

참고 : 긴 명령어를 여러 라인으로 표현시 \ 사용OBJS = shape.o \

pen.o\marker.o

Page 18: Linux Command

Advanced Compiler Laboratory 18

Example

만들었던 Makefile 을 macro 와 확장자 규칙을 이용하여 다시 바꾸어 보자 .

Page 19: Linux Command

Advanced Compiler Laboratory 19

의존 관계 생성

gccmakedep 어떤 파일의 의존 관계를 자동으로 조사해서

Makefile 의 뒷부분에 자동으로 붙여주는 유틸리티 .SUFFIXES : .c .o

CFLAGS = -O2 -g OBJS = main.o add.o sub.oSRCS = $(OBJS:.o=.c) test : $(OBJS) $(CC) -o test $(OBJS) dep : gccmakedep $(SRCS)

Page 20: Linux Command

Advanced Compiler Laboratory 20

Recursive Make

파일들이 여러 directory 에 나누어져 있고 각 sub-directory 에 makefile 이 존재 한다면 ?

subsystem:cd subdir;$(MAKE)

subsystem:$(MAKE) –C subdir

Page 21: Linux Command

Advanced Compiler Laboratory 21

Example

Recursive Makefile 을 작성해 보자 .


Recommended