728x90

이 글은 양주종의 코딩스쿨 리눅스(Linux) 기초 강좌 30강 모음 수강하며 정리한 글입니다.

 

22강 파일 분류

(일반 사용자 id: j, pw: j)

(관리자 id: root, pw: r)

 

 

File Classification

-: 일반 파일

d: directory

s: socket

p: named pipe

b: block

c: character

l: symbolic link

 

[root@hj0216 ~]# file /etc
/etc: directory
[root@hj0216 ~]# file /etc/bashrc
/etc/bashrc: ASCII text
[root@hj0216 ~]# file /usr/bin/date
/usr/bin/date: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=4fca2d42de39c5f177d7a21782e344776597ba32, stripped

/usr/bin/date: ELF 64-bit LSB executable, Excutable Linking Format, 64bit 실행(.exe) 파일

 

c언어 소스코드 파일 및 컴파일 파일 확인

[root@hj0216 ~]# vi k.c

#include <stdio.h>
int main(void)
{
        puts("Linux Study \n");
        return 0;
}

[root@hj0216 ~]# gcc k.c -o k
[root@hj0216 ~]# ./k
Linux Study
[root@hj0216 ~]# file k.c
k.c: C source, ASCII text
[root@hj0216 ~]# file k
k: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=5184afee87a2c1e03c5ab28a197f71a816dd0587, not stripped

k.c: C source, C 소스코드 파일

k: ELF 64-bit LSB executable, 64-bit exe 실행 파일

 

File의 종류

[root@hj0216 ~]# ll /dev
crw-------. 1 root root     10, 235  2월  3 22:50 autofs
drwxr-xr-x. 2 root root         160  2월  3 22:50 block
lrwxrwxrwx. 1 root root           3  2월  3 22:50 cdrom -> sr0
brw-rw----. 1 root disk    253,   0  2월  3 22:50 dm-0
srw-rw-rw-. 1 root root           0  2월  3 22:50 log
...

c: character device (입출력 장치: 프린터기, 키보드 등)

[root@hj0216 ~]# file /dev/autofs
/dev/autofs: character special

d: directory

[root@hj0216 ~]# file /dev/block
/dev/block: directory

l: symbolic link

[root@hj0216 ~]# file /dev/cdrom
/dev/cdrom: symbolic link to `sr0'

b: block device (저장 장치: SDA)

[root@hj0216 ~]# file /dev/dm-0
/dev/dm-0: block special

s: socket

: socket을 활용하여 같은 도메인 내에서 연결될 수 있고 프로세스들 사이의 통신을 할 수 있음

[root@hj0216 ~]# file /dev/log
/dev/log: socket

p: named pipe

: 전혀 모르는 프로세스들 사이에서 pipe로 통신을 할 경우, pipe에 이름을 지정해야하며, 이렇게 이름이 지정된 pipe를 named pipe라고 함

[root@hj0216 ~]# find / -type p
/run/systemd/initctl/fifo
[root@hj0216 ~]# ll /run/systemd/initctl/fifo
prw-------. 1 root root 0  2월  3 22:50 /run/systemd/initctl/fifo
[root@hj0216 ~]# file /run/systemd/initctl/fifo
/run/systemd/initctl/fifo: fifo (named pipe)

find / -type p: 최상위 dir(/)에서 type이 p인 file 탐색

 

 

 

➕ IPC: Inter Process Communication, 프로세스간 통신

Process의 경우, 완전히 독립된 실행 객체로써 다른 Process의 영향을 받지 않음

그로인해 서로간 통신이 어려워 Kernel 영역에서 IPC라는 내부 프로세스 간 통신을 제공

Process는 이러한 IPC를 통해 상호 통신을 함

-> IPC의 종류: PIPE, Named PIPE, Message Queue, Shared Memory, Socket 등

1. PIPE: 부모-자식 프로세스간 통신 시 사용

2. Named PIPE: 이름을 가진 PIPE를 통해서 부모-자식 관계가 아닌 프로세스간 통신 시 사용 가능

3. Memory Queue: 컨베이너 벨트 위 물건에 라벨을 붙이면서 동시에 다양한 물건을 다룰 수 있는 것과 같이 큐에 쓸 데이터에 번호를 붙임으로써 여러 개의 프로세스가 동시에 데이터를 쉽게 다룰 수 있음

4. Shared Memory: 프로세스가 공유 메모리 할당을 커널에 요청하면 커널은 해당 프로세스에 메모리 공간을 할당함으로써 이후 어떤 프로세스건 해당 메모리영역에 접근할 수 있음
공유메모리는 중개자가 없이 곧바로 메모리에 접근할 수 있기 때문에 다른 모든 IPC들 중에서 가장 빠르게 작동함

5. Socket: 같은 도메인 내에서 연결될 수 있고, process들간 통신을 가능하게 하는 범용적인 IPC

 

참고 자료

📑 14) named pipe, socket

📑 [운영체제] IPC 프로세스간 통신

 

728x90
728x90

이 글은 남궁성의 정석코딩 [자바의정석-기초편] 수강하며 정리한 글입니다.

 

🟣 기본 환경: IDE: Eclipse, Language: Java

 

 

증감 연산자

전위형(++i): 증가 후 대입

후위형(i++): 대입 후 증가

 

 

비교 연산자

 

숫자 비교 연산자

같음(==), 같지 않음(!=)

 

문자열 비교 연산자

같음(equals())

논리 연산자

그리고(&&), 또는(||), 크거나 같다(>=)

조건 연산자

x > y ? 참일 경우 결과값 : 거짓일 경우 결과값

대입 연산자

lvalue: 왼쪽 피연산자, 저장공간

rvalue: 오른쪽 피연산자

 

 

 

소스 코드

🔗 HJ0216/HJ0216/java-practice

 

 

728x90
728x90

이 글은 양주종의 코딩스쿨 리눅스(Linux) 기초 강좌 30강 모음 수강하며 정리한 글입니다.

 

21강 권한의 이해

(일반 사용자 id: j, pw: j)

(관리자 id: root, pw: r)

 

 

⭐ r: read, 4

⭐ w: write(create, remove, modify), 2

⭐ e: execute,1 

 

dir 목록 조회

[j@hj0216 ~]$ ll /usr/bin/cal
-rwxr-xr-x. 1 root root 37736 10월 31  2018 /usr/bin/cal

-rwxr-xr-x.

 -: file

 rwx: 소유주 권한

 r-x: 소유그룹 권한

 r-x: 타인(others) 권한

1: 하드링크 수

root: 소유주

root: 소유 그룹

37763: file size

10월 31 2018: 변경 시간

 

chmod: chagne mode, 권한 변경

[j@hj0216 ~]$ chmod 644 /usr/bin/cal
chmod: changing permissions of `/usr/bin/cal': 명령을 허용하지 않음

644: 소유주(rw-), 소유그룹(r--), 그 외(r--)

* 일반 사용자 계정에서는 권한 변경 불가

[root@hj0216 ~]# ll /usr/bin/cal
-rwxr-xr-x. 1 root root 37736 10월 31  2018 /usr/bin/cal
[root@hj0216 ~]# chmod 644 /usr/bin/cal
[root@hj0216 ~]# ll /usr/bin/cal
-rw-r--r--. 1 root root 37736 10월 31  2018 /usr/bin/cal

-> root 계정에서는 권한 변경 가능

[root@hj0216 ~]# cal
-bash: /usr/bin/cal: 허가 거부
[j@hj0216 ~]$ cal
-bash: /usr/bin/cal: 허가 거부

권한 변경 후, root 및 일반 사용자 계정 cal 명령어 실행 허가 거부

 

실행 권한 재변경

[root@hj0216 ~]# chmod 744 /usr/bin/cal
[root@hj0216 ~]# cal
      2월 2023
일 월 화 수 목 금 토
          1  2  3  4
 5  6  7  8  9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28
[j@hj0216 ~]$ cal
-bash: /usr/bin/cal: 허가 거부

744: 소유주(rwx), 소유그룹(r--), 그 외(r--)

권한 재변경 후, root 계정 cal 명령어 실행 가능 / 일반 사용자 계정 cal 명령어 실행 허가 거부

 

* 권한 변경을 위한 file path 확인

[j@hj0216 ~]$ which date
/usr/bin/date

[j@hj0216 ~]$ whereis cal
cal: /usr/bin/cal /usr/share/man/man1/cal.1.gz

 

읽기 권한 변경

1. 일반 사용자 /etc/bashrc 읽기 가능

[j@hj0216 ~]$ cat /etc/bashrc
# /etc/bashrc

# System wide functions and aliases
...

2. root 계정에서 일반 사용자의 읽기 권한 제거

[root@hj0216 ~]# ll /etc/bashrc
-rw-r--r--. 1 root root 2853  1월 15 22:57 /etc/bashrc
[root@hj0216 ~]# chmod 700 /etc/bashrc
[root@hj0216 ~]# ll /etc/bashrc
-rwx------. 1 root root 2853  1월 15 22:57 /etc/bashrc

3. 일반 사용자 /etc/bashrc 읽기 허가 거부

[j@hj0216 ~]$ cat /etc/bashrc
cat: /etc/bashrc: 허가 거부

일반 사용자 /etc/bashrc 읽기 전용, 수정 불가

[j@hj0216 ~]$ vi /etc/bashrc
"/etc/bashrc" [읽기 전용] 92L, 2853C
728x90
728x90

이 글은 양주종의 코딩스쿨 리눅스(Linux) 기초 강좌 30강 모음 수강하며 정리한 글입니다.

 

20강 압축(gzip/xz/tar)

(일반 사용자 id: j, pw: j)

(관리자 id: root, pw: r)

 

 

1. dir 내 파일 목록 조회

[j@hj0216 ~/down]$ ls -lh
합계 10M
-rw-rw-r--. 1 j j 9.4M  2월  3 23:02 httpd-2.4.55.tar.gz
-rw-r--r--. 1 j j 655K  2월  3 23:28 y

 

2. 압축(gzip dir_name)

[j@hj0216 ~/down]$ gzip y
[j@hj0216 ~/down]$ ls -lh
합계 9.5M
-rw-rw-r--. 1 j j 9.4M  2월  3 23:02 httpd-2.4.55.tar.gz
-rw-r--r--. 1 j j 133K  2월  3 23:28 y.gz

* dir y: 655K -> 133K

 

3. 압축풀기(gunzip file_name.gz)

[j@hj0216 ~/down]$ gunzip y.gz
[j@hj0216 ~/down]$ ls -lh
합계 10M
-rw-rw-r--. 1 j j 9.4M  2월  3 23:02 httpd-2.4.55.tar.gz
-rw-r--r--. 1 j j 655K  2월  3 23:28 y

 

3. 압축(xy dir_name)

[j@hj0216 ~/down]$ xz y
[j@hj0216 ~/down]$ ll -h
합계 9.5M
-rw-rw-r--. 1 j j 9.4M  2월  3 23:02 httpd-2.4.55.tar.gz
-rw-r--r--. 1 j j  98K  2월  3 23:28 y.xz

* dir y: 655K -> 98K

// gzip보다 압축률이 높으나 압축률이 높을수록 압축시간이 오래 소요됨

 

4. 압축풀기(gunzip file_name.gz)

[j@hj0216 ~/down]$ unxz y.xz
[j@hj0216 ~/down]$ ll -h
합계 10M
-rw-rw-r--. 1 j j 9.4M  2월  3 23:02 httpd-2.4.55.tar.gz
-rw-r--r--. 1 j j 655K  2월  3 23:28 y

 

 

* FTP server에서 다운받은 httpd-2.3.55.tar.gz 압축 및 압축풀기

1. 압축 풀기

[j@hj0216 ~/down]$ ll -h
합계 10M
-rw-rw-r--. 1 j j 9.4M  2월  3 23:02 httpd-2.4.55.tar.gz
-rw-r--r--. 1 j j 655K  2월  3 23:28 y
[j@hj0216 ~/down]$ gunzip httpd-2.4.55.tar.gz
[j@hj0216 ~/down]$ ls -lh
합계 43M
-rw-rw-r--. 1 j j  43M  2월  3 23:02 httpd-2.4.55.tar
-rw-r--r--. 1 j j 655K  2월  3 23:28 y

* tab: 자동완성

 

2. tar 묶음 풀기(tar xf tar_file_name.tar)

[j@hj0216 ~/down]$ tar xf httpd-2.4.55.tar
[j@hj0216 ~/down]$ ls -lh
합계 43M
drwxr-xr-x. 12 j j 4.0K  1월 10 22:38 httpd-2.4.55
-rw-rw-r--.  1 j j  43M  2월  3 23:02 httpd-2.4.55.tar
-rw-r--r--.  1 j j 655K  2월  3 23:28 y

tar xf command를 통해 묶음 파일 해제(-> httpd-2.4.55 dir 생성)

tar: Tape ARchiver, tar은 여러 개의 파일을 하나의 파일로 묶거나 풀 때 사용하는 명령

-x: extract, tar ARchive에서 파일 추출(묶음 풀 때 사용)

-f: 대상 tar ARchive 파일 지정(Default Option)

* 압축 과정: 파일을 하나로 묶기 -> 압축하기

 

cf. 현재 디스크 용량을 특정 dir, file 단위로 확인

[j@hj0216 ~/down]$ du -sh httpd-2.4.55
49M     httpd-2.4.55

du: disk use

-s: summerize, 하위 dir은 합쳐서 전체 용량만 출력

-h: human readable, 파일 용량을 사람이 보기 쉬운 상태로 출력

 

3. tar 묶음 파일 만들기(tar cf tar_file_name.tar)

[j@hj0216 ~/down]$ tar cf h.tar httpd-2.4.55
[j@hj0216 ~/down]$ ls -lh
합계 86M
-rw-rw-r--.  1 j j  43M  2월  3 23:37 h.tar
drwxr-xr-x. 12 j j 4.0K  1월 10 22:38 httpd-2.4.55
-rw-rw-r--.  1 j j  43M  2월  3 23:02 httpd-2.4.55.tar
-rw-r--r--.  1 j j 655K  2월  3 23:28 y

-c: create, tar ARchive 생성, 기존 ARchive에 덮어쓰기(파일 묶을 때 사용)

 

4. tar 파일 압축

[j@hj0216 ~/down]$ gzip h.tar
[j@hj0216 ~/down]$ ls -lh
합계 53M
-rw-rw-r--.  1 j j 9.4M  2월  3 23:37 h.tar.gz
drwxr-xr-x. 12 j j 4.0K  1월 10 22:38 httpd-2.4.55
-rw-rw-r--.  1 j j  43M  2월  3 23:02 httpd-2.4.55.tar
-rw-r--r--.  1 j j 655K  2월  3 23:28 y

 

5. 파일 묶기 및 압축

[j@hj0216 ~/down]$ tar cfz hh.tar.gz httpd-2.4.55
[j@hj0216 ~/down]$ ls -lh
합계 62M
-rw-rw-r--.  1 j j 9.4M  2월  3 23:37 h.tar.gz
-rw-rw-r--.  1 j j 9.4M  2월  3 23:42 hh.tar.gz
drwxr-xr-x. 12 j j 4.0K  1월 10 22:38 httpd-2.4.55
-rw-rw-r--.  1 j j  43M  2월  3 23:02 httpd-2.4.55.tar
-rw-r--r--.  1 j j 655K  2월  3 23:28 y

-z: gzip 압축

httpd-2.4.55 dir을 hh.tar.gz로 압축

 

(압축 해제 후, dir 중복 방지를 위해 기존 dir 삭제: $ rm -rf httpd-2.4.55)

 

6. 파일 압축해제 및 묶음 풀기

[j@hj0216 ~/down]$ tar xfz hh.tar.gz
[j@hj0216 ~/down]$ ls -lh
합계 62M
-rw-rw-r--.  1 j j 9.4M  2월  3 23:37 h.tar.gz
-rw-rw-r--.  1 j j 9.4M  2월  3 23:42 hh.tar.gz
drwxr-xr-x. 12 j j 4.0K  1월 10 22:38 httpd-2.4.55
-rw-rw-r--.  1 j j  43M  2월  3 23:02 httpd-2.4.55.tar
-rw-r--r--.  1 j j 655K  2월  3 23:28 y

 

 

 

참고 자료

📑 Linux 명령어 | 파일 관리 | du 명령어 디스크 용량을 특정 디렉토리/파일

📑 Linux(리눅스) : tar 명령어 옵션 정리 및 사용법

 

728x90
728x90

이 글은 양주종의 코딩스쿨 리눅스(Linux) 기초 강좌 30강 모음 수강하며 정리한 글입니다.

 

19강 ftp client 사용법

(일반 사용자 id: j, pw: j)

(관리자 id: root, pw: r)

 

 

FTP: File Transfer Protocol

: TCP/IP 프로토콜을 가지고 서버와 클라이언트 사이의 파일 전송을 하기 위한 프로토콜

 

FTP 사용을 위한 FTP 설치 확인

[j@hj0216 ~]$ rpm -qa | grep ftp
ftp-0.17-67.el7.x86_64

 

FTP 용어 확인

1. FTP 실행 및 명령어 리스트 반환

[j@hj0216 ~/down]$ ftp
ftp> ?
Commands may be abbreviated.  Commands are:

!               debug           mdir            sendport        site
$               dir             mget            put             size
account         disconnect      mkdir           pwd             status
append          exit            mls             quit            struct
ascii           form            mode            quote           system
bell            get             modtime         recv            sunique
binary          glob            mput            reget           tenex
bye             hash            newer           rstatus         tick
case            help            nmap            rhelp           trace
cd              idle            nlist           rename          type
cdup            image           ntrans          reset           user
chmod           lcd             open            restart         umask
close           ls              prompt          rmdir           verbose
cr              macdef          passive         runique         ?
delete          mdelete         proxy           send

 

2. 명령어 조회

ftp> ? mget
mget            get multiple files
ftp> ? put
put             send one file
ftp> ? mput
mput            send multiple files
ftp> ? ls
ls              list contents of remote directory
ftp> ? open
open            connect to remote ftp

 

Web Browser: ftp.kaist.ac.kr/apache/httpd

 

Linux를 통한 ftp - file download

1. 파일 위치에 따른 dir 경로 이동(기존 경로이동과 유사)

ftp> cd apache
250-Please try to use a mirror if at all possible.  There is a complete list
250-of mirrors available at <http://www.apache.org/mirrors/>, and a script
250-which will attempt to find those close to you at
250-<http://www.apache.org/dyn/closer.cgi>.
250 Directory successfully changed.
ftp> cd httpd
250 Directory successfully changed.
ftp> pwd
257 "/apache/httpd" is the current directory

 

2. 해당 dir 내 list 확인

ftp> ls
227 Entering Passive Mode (103,22,220,133,111,213)
150 Here comes the directory listing.
-rw-rw-r--    1 1000     1000         3883 Jan 17 13:32 Announcement2.4.html
-rw-rw-r--    1 1000     1000         2518 Jan 17 13:32 Announcement2.4.txt
-rw-rw-r--    1 1000     1000       341911 Jan 17 16:15 CHANGES_2.4
-rw-rw-r--    1 1000     1000         7386 Jun 08  2022 CHANGES_2.4.54
-rw-rw-r--    1 1000     1000         7060 Jan 17 16:15 CHANGES_2.4.55
-rw-rw-r--    1 1000     1000            0 Jan 17 16:15 CURRENT-IS-2.4.55
-rw-rw-r--    1 1000     1000          682 Oct 03  2009 HEADER.html
-rw-rw-r--    1 1000     1000         3031 Oct 03  2009 README.html
drwxr-xr-x    4 1000     1000           69 Jun 17  2022 binaries
drwxr-xr-x    2 1000     1000           65 Jun 17  2022 docs
-rw-rw-r--    1 1000     1000      7434530 Jun 08  2022 httpd-2.4.54.tar.bz2
-rw-rw-r--    1 1000     1000      9743277 Jun 08  2022 httpd-2.4.54.tar.gz
-rw-rw-r--    1 1000     1000      7456187 Jan 17 13:32 httpd-2.4.55.tar.bz2
-rw-rw-r--    1 1000     1000      9758888 Jan 17 13:32 httpd-2.4.55.tar.gz
-rw-rw-r--    1 1000     1000        19006 Dec 21  2016 httpd_logo_wide_new.pn
drwxr-xr-x    2 1000     1000          108 Aug 25 13:10 libapreq
drwxr-xr-x    3 1000     1000          193 Jun 17  2022 mod_fcgid
drwxr-xr-x    2 1000     1000          124 Jun 17  2022 mod_ftp
drwxr-xr-x    3 1000     1000           83 Jun 17  2022 patches
226 Directory send OK.

 

3. FTP를 통한 file download

ftp> get httpd-2.4.55.tar.gz
local: httpd-2.4.55.tar.gz remote: httpd-2.4.55.tar.gz
227 Entering Passive Mode (103,22,220,133,231,218)
150 Opening BINARY mode data connection for httpd-2.4.55.tar.gz (9758888 bytes.
226 Transfer complete.
9758888 bytes received in 1.31 secs (7460.72 Kbytes/sec)

 

4. FTP 종료

ftp> by
221 Goodbye.

 

5. Download받은 파일 List 확인

[j@hj0216 ~/down]$ ls
httpd-2.4.55.tar.gz

 

728x90