Upload
others
View
3
Download
0
Embed Size (px)
Citation preview
Linux programming server
(리눅스 프로그래밍 서버)
Contents
1 Secure shell login(보안 쉘 로그인)
2 File system(파일 시스템)
3 File properties(파일 특성)
4 Basic file operations(기본 파일 동작)
5 Directory operations(디렉토리 동작)
6 File viewing(파일 보기)
7 Process control(프로세스 제어)
8 File editing(파일 편집)
9 C program compilation(C 프로그램 컴파일)
Linux programming server(리눅스 프로그래밍 서버) 2
1 Secure shell login(보안 쉘 로그인)
• Programming server(프로그래밍 서버)
• Secure shell login(보안 쉘 로그인)
• Change password and logout(암호 수정
및 로그아웃)
Linux programming server(리눅스 프로그래밍 서버) 3
Programming server(프로그래밍 서버)
• Host: oak.smu.ac.kr
• TCP port: 22022
• OS: Linux (Ubuntu 16.04.6 LTS)
• ID: s2012345 (학번이 202012345인학생의 경우 학번의 앞 20을 제거하고 대신 영문 소문자 s를 넣음)
• 초기 Password: ID와 동일
Linux programming server(리눅스 프로그래밍 서버) 4
Secure shell login(보안 쉘 로그인)
• Linux OS 혹은 Mac OS에서
– Terminal 창을 수행 시킨 후 아래 명령어수행 (줄 친 ID 부분에 자신의 ID 입력)
$ ssh -p 22022 [email protected]
• Windows OS에서
– Tera Term 설치 (http://e.smu.ac.kr -> 본과목 강의실 -> 참고자료 폴더에서 다운로드 후 설치) 및 수행 후 connect 시 아래 정보 입력
• Host, TCP port, ID 및 Password
Linux programming server(리눅스 프로그래밍 서버) 5
Change password and logout(암호 수정 및 로그아웃)
• Programming server의 password를 수정하기 위해서는 명령
어 passwd 수행 (주의: password 입력 시 문자는 보이지 않음)
$ passwd
Changing password for s2012345.
(current) UNIX password: (현재 password 입력)
Enter new UNIX password: (새 password 입력)
Retype new UNIX password: (새 password 다시 입력)
passwd: password updated successfully
• Programming server에서 logout하기 위해서는 명령어
logout 혹은 exit 수행
$ logout
Linux programming server(리눅스 프로그래밍 서버) 6
2 File system(파일 시스템)
• Linux file system(리눅스 파일 시스템)
• File/Directory path(파일/디렉토리 경로)
• Home directory(홈 디렉토리)
• Change current working directory(현재
작업 디렉토리 수정)
Linux programming server(리눅스 프로그래밍 서버) 7
• Linux file system은 root directory(/) 아래에 계층적인 (sub)directory로 구성됨
• 어떤 file은 어떤 directory 내에 존재함
Linux file system(리눅스 파일 시스템)
...
s2012345clang
Linux programming server(리눅스 프로그래밍 서버) 8
File/Directory path(파일/디렉토리 경로)
• Absolute path(절대 경로) – root directory에서 어떤file/directory까지의 경로를 절대적으로 표현 (아래 보기 path)
① /usr/bin/cal
② /etc/motd
③ /home/clang/linux
• Relative path(상대 경로) - current working directory(현재 작업 디렉토리)에서 어떤 file/director까지의 경로를 상대적으로표현. 이때 current working director는 .으로, parent directory(부모 디렉토리)는 ..으로 표현함 (current working director가 /home /s2012345라고 가정하면 아래 보기 path)
① ../../usr/bin/cal
② ../../etc/motd
③ ../clang/linux
Linux programming server(리눅스 프로그래밍 서버) 9
Home directory(홈 디렉토리)
• Home directory란 어떤 ID로 login한 후 처음으로 들어가는 current working directory임
–사용자가 다른 경우 home directory도 다름
• 우리 programming server의 경우 login ID가s2012345이라면 home directory의 절대 경로명은 아래와 같음
/home/s2012345
• 어떤 ID로 login 하였을 때, home directory는 시스템 사용 도중 바뀌지 않으며 ~(tilde)로 표현됨
–사용자가 다른 경우 ~도 다름
Linux programming server(리눅스 프로그래밍 서버) 10
Change current working directory(현재 작업 디렉토리 수정)
• Current working directory를 출력하는 명령어는 pwd임
$ pwd
/home/s2012345
• Current working directory는 시스템 사용 중 명령어 cd를 사용하여 수정할 수 있음
$ cd ../clang/linux
$ pwd
/home/clang/linux
$ cd ~
$ pwd
/home/s2012345
Linux programming server(리눅스 프로그래밍 서버) 11
3 File properties(파일 특성)
• 명령어 stat은 각 file/directory의 아래와 같은 property들을출력함
– size: 크기 (byte 수)
– blocks: 크기 (block 수, 1 block = 4,096 bytes)
– file type: 파일 종류 (regular file, directory, device 등)
– inode: file system 내의 inode 번호
– links: link 수
– access permission: 접근 권한 (read=4, write=2, execute=1)
– uid/gid: user ID 및 group ID
– access time: 최근 읽은 시간
– modify time: 최근 수정한 시간
– change time: 최근 property 수정 시간
Linux programming server(리눅스 프로그래밍 서버) 12
File properties - examples
$ stat /home/clang/linux/dir1
File: '/home/clang/linux/dir1'
Size: 4096 Blocks: 8 IO Block: 4096 directory
Device: 801h/2049d Inode: 9967725 Links: 2
Access: (0755/drwxr-xr-x) Uid: ( 1000/ dshin) Gid: ( 1000/ dshin)
Access: 2019-08-27 22:12:13.170029145 +0900
Modify: 2019-08-27 22:12:13.170029145 +0900
Change: 2019-08-27 22:12:13.170029145 +0900
Birth: -
$ stat /home/clang/linux/dir2/motd
File: '/home/clang/linux/dir2/motd'
Size: 1186 Blocks: 8 IO Block: 4096 regular file
Device: 801h/2049d Inode: 9967723 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 1000/ dshin) Gid: ( 1000/ dshin)
Access: 2019-08-27 22:12:13.170029145 +0900
Modify: 2019-08-27 22:12:13.170029145 +0900
Change: 2019-08-27 22:12:13.170029145 +0900
Birth: -
Linux programming server(리눅스 프로그래밍 서버) 13
4 Basic file operations(기본 파일 동작)
• ls - list files in a directory
• cp - copy a file
• mv - rename or move a file
• rm - remove a file
Linux programming server(리눅스 프로그래밍 서버) 14
ls - list files in a directory - 1/2
• Usage: ls [options] [paths]
• Examples:
$ ls /home/clang/linux
bigfile dir1 dir2 empty fctable fctable.c hello hello.c
$ ls -a /home/clang/linux // all
. .. bigfile dir1 dir2 empty fctable fctable.c hello hello.c .hidden-file
$ ls -l /home/clang/linux // long
total 48
-rw-r--r-- 1 dshin dshin 7115 8월 27 22:12 bigfile
drwxr-xr-x 2 dshin dshin 4096 8월 27 22:12 dir1
drwxr-xr-x 2 dshin dshin 4096 8월 27 22:12 dir2
-rw-r--r-- 1 dshin dshin 0 8월 27 22:12 empty
-rwxr-xr-x 1 dshin dshin 8608 8월 27 22:12 fctable
-rw-r--r-- 1 dshin dshin 430 8월 27 22:12 fctable.c
-rwxr-xr-x 1 dshin dshin 8600 8월 27 22:12 hello
-rw-r--r-- 1 dshin dshin 68 8월 27 22:12 hello.c
Linux programming server(리눅스 프로그래밍 서버) 15
• Examples:
$ ls -Rl /home/clang/linux/dir1 // recursive and long
/home/clang/linux:
total 8
-rw-r--r-- 1 dshin dshin 85 8월 27 22:12 file1
-rw-r--r-- 1 dshin dshin 85 8월 27 22:12 file2
$ ls -Rl /home/clang/linux
/home/clang/linux:
total 48
-rw-r--r-- 1 dshin dshin 7115 8월 27 22:12 bigfile
drwxr-xr-x 2 dshin dshin 4096 8월 27 22:12 dir1
drwxr-xr-x 2 dshin dshin 4096 8월 27 22:12 dir2
-rw-r--r-- 1 dshin dshin 0 8월 27 22:12 empty
-rwxr-xr-x 1 dshin dshin 8608 8월 27 22:12 fctable
-rw-r--r-- 1 dshin dshin 430 8월 27 22:12 fctable.c
-rwxr-xr-x 1 dshin dshin 8600 8월 27 22:12 hello
-rw-r--r-- 1 dshin dshin 68 8월 27 22:12 hello.c
/home/clang/linux/dir1:
total 8
-rw-r--r-- 1 dshin dshin 85 8월 27 22:12 file1
-rw-r--r-- 1 dshin dshin 85 8월 27 22:12 file2
/home/clang/linux/dir2:
total 4
-rw-r--r-- 1 dshin dshin 1186 8월 27 22:12 motd
ls - list files in a directory - 2/2
Linux programming server(리눅스 프로그래밍 서버) 16
cp - copy a file
• Usage: cp [options] files (file | directory)
• Examples:
$ cp /home/clang/linux/dir1/file1 .
$ cp file1 file1.cp
$ ls -l
total 8
-rw-r--r-- 1 s2012345 students 85 9월 3 02:19 file1
-rw-r--r-- 1 s2012345 students 85 9월 3 02:19 file.cp
$ mkdir dir.new
$ cp file1 file1.cp dir.new
$ ls -l dir.new
total 8
-rw-r--r-- 1 s2012345 students 85 9월 3 02:20 file1
-rw-r--r-- 1 s2012345 students 85 9월 3 02:20 file1.cp
Linux programming server(리눅스 프로그래밍 서버) 17
mv - rename or move a file
• Usage: mv [options] source target
• Examples:
$ mv file1 file1.mv
$ ls -l
total 12
drwxr-xr-x 2 s2012345 students 4096 9월 3 02:20 dir.new
-rw-r--r-- 1 s2012345 students 85 9월 3 02:19 file1.cp
-rw-r--r-- 1 s2012345 students 85 9월 3 02:19 file1.mv
$ mv file1.mv dir.new
$ ls -Rl
.:
total 8
drwxr-xr-x 2 s2012345 students 4096 9월 3 02:22 dir.new
-rw-r--r-- 1 s2012345 students 85 9월 3 02:19 file1.cp
./dir.new:
total 12
-rw-r--r-- 1 s2012345 students 85 9월 3 02:20 file1
-rw-r--r-- 1 s2012345 students 85 9월 3 02:20 file1.cp
-rw-r--r-- 1 s2012345 students 85 9월 3 02:19 file1.mv
Linux programming server(리눅스 프로그래밍 서버) 18
rm - remove a file - 1/2
• Usage: rm [options] (files | directories)
• Examples:
$ rm dir.new/file1.cp dir.new/file1.mv
/bin/rm: remove regular empty file 'dir.new/file1.cp'? y
/bin/rm: remove regular empty file 'dir.new/file1.mv'? y
$ ls -Rl
.:
total 8
drwxr-xr-x 2 s2012345 students 4096 9월 3 02:23 dir.new
-rw-r--r-- 1 s2012345 students 85 9월 3 02:19 file1.cp
./dir.new:
total 4
-rw-r--r-- 1 s2012345 students 85 9월 3 02:20 file1
Linux programming server(리눅스 프로그래밍 서버) 19
rm - remove a file - 2/2
• Examples:$ rm -f file1.cp // force
$ ls -l
total 4
drwxr-xr-x 2 s2012345 students 4096 9월 3 02:23 dir.new
$ rm -rf dir.new // recursive and force
$ ls -l
total 0
Linux programming server(리눅스 프로그래밍 서버) 20
5 Directory operations(디렉토리 동작)
• mkdir - make (create) a directory
• rmdir - remove (delete) an empty directory
Linux programming server(리눅스 프로그래밍 서버) 21
mkdir - make (create) a directory
• Usage: mkdir [options] directories• Examples:
$ mkdir dir3$ mkdir dir3/dir4$ mkdir -p dir5/dir6 // parents$ ls -lR.:total 8drwxr-xr-x 3 s2012345 students 4096 9월 3 02:25 dir3drwxr-xr-x 3 s2012345 students 4096 9월 3 02:25 dir5./dir3:total 4drwxr-xr-x 2 s2012345 students 4096 9월 3 02:25 dir4./dir3/dir4:total 0./dir5:total 4drwxr-xr-x 2 s2012345 students 4096 9월 3 02:25 dir6./dir5/dir6:total 0
Linux programming server(리눅스 프로그래밍 서버) 22
rmdir - remove (delete) an empty directory
• Usage: rmdir [options] directories
• Examples:
$ rmdir dir3/dir4
$ rmdir dir3
$ rmdir -p dir5/dir6 // parents
$ ls -Rl
.:
total 0
Linux programming server(리눅스 프로그래밍 서버) 23
6 File viewing(파일 보기)
• cat - view files
• less - view files one page at a time
• head/tail - view the first/last lines of files
참고: text file 만 view할 수 있음Linux programming server(리눅스 프로그래밍 서버) 24
cat - view files
• Usage: cat [options] files
• Examples:$ cat /home/clang/linux/hello.c
#include <stdio.h>
void main(void)
{
printf("hello, world\n");
}
Linux programming server(리눅스 프로그래밍 서버) 25
less - view files one page at a time
• Usage: less [options] files• Examples:
$ less -N /home/clang/linux/bigfile // with line number1 # This is the main Apache server configuration file. It contains the
2 # configuration directives that give the server its instructions.
3 # See http://httpd.apache.org/docs/2.4/ for detailed information about
4 # the directives and /usr/share/doc/apache2/README.Debianabout Debian specific
5 # hints.6 #7 #8 # Summary of how the Apache 2 configuration works in Debian:.../home/clang/linux/bigfile□
참고: 여기서 space (다음 화면), enter (1줄), q (종료) 등을 입력할 수 있음
Linux programming server(리눅스 프로그래밍 서버) 26
head/tail - view the first/last lines of files
• Usage: (head | tail) [options] files
• Examples:
$ head -5 /home/clang/linux/fctable.c // 5 lines
#include <stdio.h>
/* print Fahrenheit-Celsius table
for fahr = 0, 20, ..., 300 */
$ tail -5 /home/clang/linux/fctable.c // 5 lines
celsius = 5 * (fahr-32) / 9;
printf("%d\t%d\n", fahr, celsius);
fahr = fahr + step;
}
}
Linux programming server(리눅스 프로그래밍 서버) 27
7 Process control(프로세스 제어)
• ps - list process
• ^Z - suspend process
• jobs - list suspended process
• fg - run suspended process
Linux programming server(리눅스 프로그래밍 서버) 28
ps - list process
• Usage: ps [options]
• Examples:
$ ps
PID TTY TIME CMD
459 pts/8 00:00:00 ps
29826 pts/8 00:00:02 bash
$ ps -ef // all and full line
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 8월15 ? 00:00:07 /sbin/init splash
root 2 0 0 8월15 ? 00:00:00 [kthreadd]
root 3 2 0 8월15 ? 00:00:00 [ksoftirqd/0]
root 5 2 0 8월15 ? 00:00:00 [kworker/0:0H]
root 7 2 0 8월15 ? 00:00:33 [rcu_sched]
root 8 2 0 8월15 ? 00:00:00 [rcu_bh]
root 9 2 0 8월15 ? 00:00:00 [migration/0]
...
Linux programming server(리눅스 프로그래밍 서버) 29
^Z - suspend process
• Usage: 명령어 수행 후 끝나기 전에 ^Z 입력• Examples:
$ less -N /home/clang/linux/bigfile // with line number1 # This is the main Apache server configuration file. It contains the2 # configuration directives that give the server its instructions.3 # See http://httpd.apache.org/docs/2.4/ for detailed information about
4 # the directives and /usr/share/doc/apache2/README.Debian about Debian specific
5 # hints.6 #7 #8 # Summary of how the Apache 2 configuration works in Debian:.../home/clang/linux/bigfile□^Z
$ psPID TTY TIME CMD474 pts/8 00:00:00 less475 pts/8 00:00:00 ps
29826 pts/8 00:00:02 bash
Linux programming server(리눅스 프로그래밍 서버) 30
jobs - list suspended process
• Usage: jobs
• Examples:
$ jobs
[1]+ Stopped less /home/clang/linux/bigfile
Linux programming server(리눅스 프로그래밍 서버) 31
fg - run suspended process
• Usage: fg
• Examples:
$ fg
# This is the main Apache server configuration file. It contains the
# configuration directives that give the server its instructions.
# See http://httpd.apache.org/docs/2.4/ for detailed information about
# the directives and /usr/share/doc/apache2/README.Debian about Debian specific
# hints.
#
#
# Summary of how the Apache 2 configuration works in Debian:
...
:□
Linux programming server(리눅스 프로그래밍 서버) 32
8 File editing(파일 편집)
• Vim editor
• Emacs editor
Linux programming server(리눅스 프로그래밍 서버) 33
Vim editor
• Usage: vim file
– Go to insert mode: i
• Type text: insert mode에서 입력하면 됨
• Cursor moves: cursor keys
– Go to command mode: ESC key
• Cursor moves: cursor keys
• Save and quit: :wq
• Quit without saving: :q!
• Save: :w
• Save as: :w filename
• Undo: u
• Suspend: ^Z
참고: ^Z는 Control key를 누른 상태에서 Z 입력을 의미함
Linux programming server(리눅스 프로그래밍 서버) 34
Emacs editor
• Usage: emacs file
– Type text: 그냥 입력하면 됨
– Cursor moves: cursor keys
– Save and quit: ^S^S ^X^C
– Quit without saving: ^X^C no
– Save: ^X^S
– Save as: ^X^W
– Undo: ^X u
– Suspend: ^Z
참고: emacs는 insert mode가 없고 항상 command mode임
Linux programming server(리눅스 프로그래밍 서버) 35
9 C program compilation(C 프로그램 컴파일)
• Usage: gcc prog.c -o prog• Usage: gcc prog1.c prog2.c -o prog• Examples:
$ cp /home/clang/linux/hello.c .$ cat hello.c#include <stdio.h>
void main(void){printf("hello, world\n");
}$ gcc hello.c -o hello$ ./hellohello, world
Linux programming server(리눅스 프로그래밍 서버) 36
References
[1] Daniel J. Barrett, Linux Pocket Guide, O'Reilly,
2016.
[2] William Shotts, The Linux Command Line, 2nd
Edition, No Starch Press, 2019.
[3] 이종우, 정영신 번역, 리눅스 커맨드 라인 완벽
입문서, 비제이퍼블릭, 2013.
Linux programming server(리눅스 프로그래밍 서버) 37