brunch

You can make anything
by writing

C.S.Lewis

by Master Seo May 16. 2019

13. 리눅스 마스터-명령어 실습 1

명령어 공부해보자.

서버에 명령을 내리고 결과를 져오는 과정이다.

서버에 명령을 내려보자.


1. 폴더 관리

$ pwd

/home/ec2-user

현재 작업 중인 디렉터리의 위치를 나타낸다.


$ cd..

$ pwd

/home

change dircetory의 약자로 디렉터리를 이동할 때 사용하는 명령어이다.


$ cd  ec2-user

$ pwd

/home/ec2-user


$ mkdir sss

$  cd sss

$  pwd

/home/ec2-user/sss


$ cd..

$ ls -al

-rw-r--r-- 1 ec2-user ec2-user 193  7?? 27  2018. bash_profile

-rw-r--r-- 1 ec2-user ec2-user 231  7?? 27  2018. bashrc

drwx------ 2 ec2-user ec2-user  29  5?? 16 01:50. ssh

drwxrwxr-x 2 ec2-user ec2-user   6  5?? 17 11:42 sss


$  cd sss

$  pwd

/home/ec2-user/sss


$ cd

$ pwd

/home/ec2-user



2. 파일 관리


$ ls

리스트 보기


$ ls -al

-rw-r--r-- 1 ec2-user ec2-user 231  7?? 27  2018. bashrc

drwx------ 2 ec2-user ec2-user  29  5?? 16 01:50. ssh

-rw-r--r-- 1 ec2-user ec2-user  45  5?? 17 11:56 index.html

drwxrwxr-x 2 ec2-user ec2-user   6  5?? 17 11:42 sss


$  touch 1234

빈 파일을 만들 때.


$  vi  222

$  vi  333


$ cp  index.html  index.html-1

파일 복사하기


$ ls -al

-rw-r--r-- 1 ec2-user ec2-user 231  7?? 27  2018. bashrc

drwx------ 2 ec2-user ec2-user  29  5?? 16 01:50. ssh

-rw-r--r-- 1 ec2-user ec2-user  45  5?? 17 11:56 index.html

-rw-r--r-- 1 ec2-user ec2-user  45  5?? 17 11:58 index.html-1


$ cp  index.html   index.html-backup

$ ls -al

-rw-r--r-- 1 ec2-user ec2-user 231  7?? 27  2018. bashrc

drwx------ 2 ec2-user ec2-user  29  5?? 16 01:50. ssh

-rw-r--r-- 1 ec2-user ec2-user  45  5?? 17 11:56 index.html

-rw-r--r-- 1 ec2-user ec2-user  45  5?? 17 11:58 index.html-1

-rw-r--r-- 1 ec2-user ec2-user  45  5?? 17 11:58 index.html-backup



$ mv index.html-backup index.html-backup-2019-0601

$ ls  -al

-rw-r--r-- 1 ec2-user ec2-user 231  7?? 27  2018. bashrc

drwx------ 2 ec2-user ec2-user  29  5?? 16 01:50. ssh

-rw-r--r-- 1 ec2-user ec2-user  45  5?? 17 11:56 index.html

-rw-r--r-- 1 ec2-user ec2-user  45  5?? 17 11:58 index.html-backup-2019-0601

drwxrwxr-x 2 ec2-user ec2-user   6  5?? 17 11:42 sss



$ sudo su -

Last login: Fri May 17 12:02:05 UTC 2019 on pts/0

#

ROOT계정으로 전환 하기


$ history


$ clear


# alias c=clear

# c

alias

명령어의 별명을 만들어 준다.

형식은   alias   x = 명령어


$ unalias c

$ c

-bash: c: command not found


# alias  l='ls -al '

# l

drwxr-x--- 6 root root 4096 5?? 2 10:41.

drwxr-xr-x 24 root root 4096 8?? 28 2014..

-rw------- 1 root root 26122 5?? 2 13:35. bash_history

-rw-r--r-- 1 root root 24 1?? 6 2007. bash_logout


얼리 어스 해제

# unalias l



# which  ls

alias ls='ls --color=tty'

/bin/ls

명령어 위치를 찾거나 연결된 alias를 찾는다.


# which pwd

/bin/pwd


# vi  123

파일 만들기


# file 123
123: ASCII text
파일의 종류와 속성을 나타내는 명령어.


# find   -name   123
./123

#  cd..

# find   -name   123

./root/123
현재 디렉터리에서  하위까지 조건의 파일을 찾아 경로를 표시한다.



# locate 123
/usr/lib/gconv/IBM1123.so
/usr/local/apache2/htdocs/dns/210.116.123.0

파일의 위치를 찾는 명령어.


# cat  123
1

2

3

123

1234

12345
파일의 내용을 확인한다.


# head  -2  123
1
2
파일의 앞부분을 지정한 숫자만큼 출력하는 것.


$ head -2 000 > 001

$ more 001

222

1


# tail  -2  123
4

1234
파일의 끝을 보는 명령어


$ tail -2 000 > 002

$ more 002

3333

5




# grep   adm   /etc/passwd
adm:x:3:4:adm:/var/adm:/sbin/nologin
 /etc아래 내 passwd 파일에서  adm이라는 text를 찾아 보여줘라.

파일에 특정 패턴을 찾아내는 명령어


# wc   123

 6  6 21 123

5라인, 5 단어, 21  알파벳

파일의 라인수, 단어수, 앞 파벳수를 알려주는 명령어.



# more  123
1

2

3

123

1234

12345



# sort  123
1

123

1234

12345

2

3
정렬하는 명령어

# cut -c 1-2   123
1

2

3

12

12

12

파일에서 특정 필드를 추출하는 명령어

앞에 2열만 추출해 보여주기

# cut -c 1-2 123  > aaa

# more aaa

1

2

3

12

12

12


# more 123

1

2

3

123

1234

12345


$ vi 1

$ more 1

1

2

3


$ vi 2

$ more 2

1

22

333


$ diff 1 2

2,3c2,3

< 2

< 3

---

> 22

> 333

두 개의 파일을 비교할 때 사용한다.


# whereis  ping

ping: /bin/ping /usr/share/man/man8/ping.8.gz
파일이 어디에 있는지 찾을 때



# useradd  -d   /test 10   test 10
# su - test 10
계정 추가하기


$ pwd
/test 10

$ touch 555

$ ls -al 555

-rw-rw-r-- 1 test 10 test 10 0 May 20 22:02 555

빈 파일 만들기 touch



$ chmod 400 555

$ ls -al 555

-r-------- 1 test 10 test 10 0 May 20 22:02 555

파일이나 디렉터리 허가권을 변경하는 명령어이다.




2. 계정  관리
$ sudo su -

Last login: Sat Jun  8 07:02:27 UTC 2019 on pts/0

#



# useradd choi11

# exit

logout


$ useradd ses222

useradd: Permission denied.

useradd: cannot lock /etc/passwd; try again later.




# passwd choi11
Changing password for user choi11
New UNIX password:
passwd: all authentication tokens updated successfully.
choi11 계정의 암호 설정하기



# passwd -S test 1
test 1 LK 2019-05-08 0 99999 7 -1 (Password locked.)

계정 test 1 상태를 확인한다.



$ su - root
#
su  (switch user )

root로 변경하기



# more   /etc/default/useradd
# useradd defaults file
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes
사용자 관련 파일



# useradd -D -g 500 -b /home/test -s /bin/sh
# useradd -D
GROUP=500
HOME=/home/test
INACTIVE=-1
EXPIRE=
SHELL=/bin/sh
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes
사용자 생성 디폴트 경로 변경하기



# more  /etc/passwd
test 1:x:505:505::/IDH:/bin/bash
사용자 이름;암호화된 비밀번호;사용자;스룹;설명;사용자 홈 디렉터리;로그인 쉘

# more   /etc/shadow
test 1:$1$FkF6 vjxl$Dq4 o2 hxMYniQx9/Kl8 LFe/:18024:0:99999:7:::
설명 :
사용자명;암호회 된 비밀번호;최근 비밀번호 변경일;비밀번호변경 후 재설정을 위한 대기일 수; 비밀번호 유효기간;비밀번호변경 경고 시간;비밀번호 유예기간;

# more   /etc/login.defs
# Password aging controls:
#
# PASS_MAX_DAYS Maximum number of days a password may be used.
# PASS_MIN_DAYS Minimum number of days allowed between password changes.
# PASS_MIN_LEN Minimum acceptable password length.
# PASS_WARN_AGE Number of days warning given before a password expires.
#
PASS_MAX_DAYS 99999
PASS_MIN_DAYS 0
PASS_MIN_LEN 5
PASS_WARN_AGE 7

사용자 계정 설정과 관련된 기본값을 정의하는 파일.

패스워드 관련 제약 - 보안 관련 관리사항


#userdel  test101
#userdel 계정
/etc/passwd , /etc/shadow , /etc/group 에서 해당 계정 정보가 삭제된다.

# userdel -r  test102
/var/spool/mail 파일과 홈 디렉터리의 내용 모두를 삭제


# chage -l  test103
Last password change : Mar 15, 2019
Password expires : never
Password inactive : never
Account expires : never
Minimum number of days between password change : 0
Maximum number of days between password change : 99999
Number of days of warning before password expires : 7
패스워드 만료기간 수정하는 명령어 chage


# more /etc/group

root:x:0:

bin:x:1:

daemon:x:2:
사용자 그룹에 대해 정의된 파일
그룹명;그룹 비밀번호;그룹번호 GID;그룸 멤버 리스트로 구분한다.

# users
로그인한 사용자 정보를 출력하는 명령어.

# users

ec2-user


# who

현재 시스템에 접속해 있는 사용자들을 조회하는 명령어.
# who

ec2-user pts/0        2019-05-20 21:35 (210.116.1.25)


# echo $PATH
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/jdk1.6.0_45/bin:/root/bin
현재 경로 보기



# export PATH=$PATH:/home
# echo $PATH
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/jdk1.6.0_45/bin:/root/bin:/home
#
경로 추가하기




# man ls
매뉴얼 보기



# info uname

리눅스 명령어 사용법 보기


# whatis ls
ls (1) - list directory contents
ls (1p) - list directory contents
명령어 ls의 기능을 간단히 확인한다.



# whereis shutdown
shutdown: /sbin/shutdown /usr/share/man/man3 p/shutdown.3p.gz /usr/share/man/man2/shutdown.2.gz /usr/share/man/man8/shutdown.8.gz
shutdown 명령어가 있는 위치 확인하기.


# who
top2 pts/14 2019-05-09 19:43 (110.12.80.83)

# who > login
# more login
top2 pts/14 2019-05-09 19:43 (110.12.80.83)

# ps
ps는 운영 중인 명령어 프로세스를 보여주는 것.
프로세스 보기  ps (Process)



# ps -ef  | grep apache
daemon 7667 25307 0 May 04? 00:00:00 /usr/local/apache2/bin/httpd -k start
daemon 9264 25307 0 Apr25? 00:00:02 /usr/local/apache2/bin/httpd -k start

파이프라인

둘 이상의 명령어를 한 번에 뿌려주는 것.




# ping
다른 서버에 응답을 확인하는 명령어
네트워크 통신을 확인하는 명령어 중 하나.


# traceroute
다른 서버까지 경로를 확인하는 명령어.
네트워크 통신을 확인하는 명령어 중 하나.


# nslookup
> www.sbs.co.kr
Server: 168.126.63.1
Address: 168.126.63.1#53
Non-authoritative answer:

# dig www.sbs.co.kr

# host www.sbs.co.kr
www.sbs.co.kr has address 54.192.175.53
www.sbs.co.kr has address 54.192.175.69
www.sbs.co.kr has address 54.192.175.94
www.sbs.co.kr has address 54.192.175.98

# hostname
ns2.serverchk.com
# hostname ns1
서버의 이름 확인하기



# tty
/dev/pts/14
현재 사용하고 있는 단말기 장치의 경로명과 파일명


# wall hello
Broadcast message from root (pts/14) (Thu May 9 20:32:37 2019):
hello
모두 로그인된 사용자들에게 터미널을 통해 메시지를 전달한다.

# write  계정명  ttyname
해당 사용자에게 메시지를 전달한다.

# mesg
write로부터 들어오는 메시지 수신 여부를 확인하고 제어하는 명령어.


# df
하드디스크에 남은 용량을 확인할 때 사용한다.

Filesystem     1K-blocks    Used Available Use% Mounted on

devtmpfs          485696       0    485696   0% /dev

tmpfs             503636       0    503636   0% /dev/shm

tmpfs             503636     392    503244   1% /run

tmpfs             503636       0    503636   0% /sys/fs/cgroup

/dev/xvda1       8376300 1255136   7121164  15% /

tmpfs             100728       0    100728   0% /run/user/1000


# du
Disk Usage의 약자로 디렉터리 별 디스크 사용량을 확인하는 명령어

# more   /etc/fstab

UUID=94 de 7 db5-d3 f1-476b-8f11-0787eb 567c32     /           xfs    defaults, noatime  1   1
파일 시스템 정보를 저장하고 있는 파일


# env
HOSTNAME=ns2.serverchk.com
SHELL=/bin/bash
TERM=vt100
HISTSIZE=1000
환경변수를 확인하는 명령어.



# ps
PID TTY TIME CMD
14001 pts/14 00:00:00 su
14002 pts/14 00:00:00 bash
14129 pts/14 00:00:00 nslookup
14142 pts/14 00:00:00 csh
14292 pts/14 00:00:00 ps
프로세스 식별번호, 터미널 번호, 총 CPU 사용시간, 실행 명령어.



# ps -ef  | grep httpd
daemon 7667 25307 0 May 04? 00:00:00 /usr/local/apache2/bin/httpd -k start
daemon 9264 25307 0 Apr25? 00:00:02 /usr/local/apache2/bin/httpd -k start
daemon 9976 25307 0 Apr25? 00:00:02 /usr/local/apache2/bin/httpd -k start
특정 프로세스의 상태 정보를 확인할 수 있다.



# kill   -9    프로세스 id
프로세스 강제 종료

# killall  -l
HUP INT QUIT ILL TRAP ABRT IOT BUS FPE KILL USR1 SEGV USR2 PIPE ALRM TERM
STKFLT CHLD CONT STOP TSTP TTIN TTOU URG XCPU XFSZ VTALRM PROF WINCH IO PWR SYS
UNUSED
같은 프로세스를 한 번에 종료시킬 때 사용한다.



# pstree

실행 중인 프로세스를 트리구조로 나타낸다.

# jobs
작업이 중지된 상태, 백그라운드로 진행 중인 상태 등을 표시한다.

# bg

백그라운드 명령

# fg
백그라운드와 포그라운드 상태로 전환

# top
운영상태를 실시간으로 모니터링하거나 프로세스 상태를 확인할 수 있다.

서버 상태를 확인하는 명령어.


# cd /var//log

# more messages

시스템 로그 보기



# tail -f /var/log/messages

명령어의 마지막 행을 기준으로 지정한 생까지 파일 내용을 출력한다.

로그의 맨 마지막 파일 보기



# more /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
주기적으로 반복되는 일을 자동적으로 실행될 수 있도록 설정한다.


# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly

# vi  ss
파일 편집기

pico
편집기

emacs
편집기

# rpm
Redhat Package Manager

레드햇 사에서 만들어낸 패키지 관리 툴이다.
새로운  프로그램(패키지)을 설치, 삭제할 때 사용한다.

# yum
네트워크를 통해 기존 RPM파일의 업데이트 자동 수행을 한다.

# ftp

-bash: ftp: command not found

# yum install ftp


# dpkg
데비안 리눅스의 저 레벨 패키지 관리 툴이다.

# apt-get

Advances Packageing Tool get
데비안 리눅스의 저 레벨 패키지 관리 툴이다.

# aptitude
우분투 리눅스 관리 툴

유틸리티


# compress , uncompress
.Z 로 압축된다.

# gzip , gunzip
.gz로 압축된다.

# bzip2 , bunzip2
.bz2로 압축된다.

# cal
시스템 캘린더 보는 명령어

# date
Mon May 20 22:37:38 UTC 2019

날짜 보거나 변경하는 명령어


# clear
화면의 내용을 깨끗이 해주는 명령어.




시스템  장치와 디스크 파티션 관리


# mount와 umount
마운트는 특정 디바이스를 특정 디렉터리처럼 사용하기 위해 장치와 디렉터리를 연결한다.

# eject
cd-rom을 해제하고 장착하는 명령어.

# fdisk
새로운 파티션을 생성하거나 기존의 파티션을 삭제하는 명령어.

# mkfs
리눅스 파일 시스템을 생성한다.

# mke2 fs
ext2, ext3, ext4 타입의 리눅스 파일 시스템을 생성하는 명령어

# fsck
파일 시스템을 점검해주고 복구해주는 명령어,

# e2 fsck
ext2, ext3, ext4 타입의 리눅스 파일 시스템을 복구해주는 명령어





프린터 관련 명령어
BSD계열
lpr, lpq, lpm, lpc
System V 계정 : lp , lpstat , cancel

# lpr : 프린터 작업을 요청한다.
lpq : 프론터 큐에 있는 작업 목록을 출력한다.

#  lprm
프린터 큐에 대기 중인 작업을 삭제한다.

# lpc
라인 프런터 컨트롤, 프린터나 프린터 큐를 제어한다.

# Lp : 프린터 작업 요청
LPstat
프린터 큐 상태를 확인한다.

# Cancel
작업을 취소한다.


사운드 관련 명령어.

# alsactl
ALSA사운트 가크를 제어한다.

alsamixer
커서 라이브러리 기반의 오디오 프로그램

cdparanoia 오디오 CD 음악파일 추출한다.

sane-find-scanner : SISC 스캐너와 USB 스캐너 관련 장치 파일을 찾아주는 명령어.

scanimage : 이미지를 스캔한다.

scanadf : 자동 문서 공금 장치의 여러 사진은 스캔한다.

xcam
GUI 기반의 평판 스캐너나 카메라로부터 이미지를 스켄한다.

시스템 초기화


# shutdown
시스템을 종료하거나 재부팅하는 명령어


# init
shutdown명령어와 동일한 명령어.

# reboot

Connection to ec2-54-180-25-233.ap-northeast-2.compute.amazonaws.com closed by remote host.

Connection to ec2-54-180-25-233.ap-northeast-2.compute.amazonaws.com closed.
시스템을 리부팅하는 명령어.

# halt
시스템을 중지하는 명령어.



디음은 배운 명령어를 사용하여  모바일 홈페이지를 만들어 보자

https://brunch.co.kr/@topasvga/557



감사합니다.


매거진의 이전글 12.리눅스 마스터-실습환경 구축
작품 선택
키워드 선택 0 / 3 0
댓글여부
afliean
브런치는 최신 브라우저에 최적화 되어있습니다. IE chrome safari