Showing posts with label commands. Show all posts
Showing posts with label commands. Show all posts

Monday, May 2, 2016

Yum

특정 저장소 파일만 출력


$ yum --disablerepo="*" --enablerepo="vozlt-base" list available

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Available Packages
debugmode.x86_64                     1:9.03.31-2.el6.vozlt                   vozlt-base
mysql-bench.x86_64                   1:5.6.15-1.el6.vozlt                    vozlt-base
mysql-embedded.x86_64                1:5.6.15-1.el6.vozlt                    vozlt-base
mysql-embedded-devel.x86_64          1:5.6.15-1.el6.vozlt                    vozlt-base
mysql-test.x86_64                    1:5.6.15-1.el6.vozlt                    vozlt-base


Vim

커서 이동


e 
    Move to the end of a word.

w 
    Move forward to the beginning of a word.

3w 
    Move forward three words.

W 
    Move forward a WORD (any non-whitespace characters).

b 
    Move backward to the beginning of a word.

3b 
    Move backward three words.

$ 
    Move to the end of the line.

0 
    Move to the beginning of the line.

^ 
    Move to the first non-blank character of the line.

) 
    Jump forward one sentence.

( 
    Jump backward one sentence.

} 
    Jump forward one paragraph.

{ 
    Jump backward one paragraph.

H 
    Jump to the top of the screen.

M 
    Jump to the middle of the screen.

L 
    Jump to the bottom of the screen.

10<PageUp> or 10<CTRL-B>
    Move 10 pages up.

5<PageDown> or 5<CTRL-F>
    Move 5 pages down.

G 
    Jump to end of file.

1G 
    Jump to beginning of file (same as gg).

50G 
    Jump to line 50.

'm 
    Jump to the beginning of the line of mark m.

`m 
    Jump to the cursor position of mark m.

''
    Return to the line where the cursor was before the latest jump.
    (Two single quotes.)

``
    Return to the cursor position before the latest jump (undo the jump).
    (Two back ticks. This is above the Tab key on some keyboards.)

 % 
    Jump to corresponding item, e.g. from an open brace to its matching closing brace.

기타


# 패턴 치환
# \1 : 첫번째 패턴일치 변수
%s/^\([0-9]\)/#\1/g
%s/\(.*\)/\1/g


# 옆창
vi -c "20vs ./"
shift + o  # 선택파일 열기


# 파일전체 경로라면 맨앞 글자에서
Ctrl + w + f


# SYNTAX 색깔 없애기
set syntax=off


# syntax 색깔 바꾸기
set filetype=php


# Ctrl + v
수직 선택 모드


# v 모드에서
> 탭삽입


# 함수 원형 알아내기
[i


# 변수 선언부로 이동
gd


# 소스를 정렬 (전체 선택은 v -> G)
v로 블록 지정후 = 누르기


# 마킹
m[임의의 알파벳]


# 마킹 이동
'[마킹한 알파벳]
`[마킹한 알파벳]


# 파일에 암호 걸기
:X


# 파일 암호 풀기
set key=


# fold 끄기
set foldlevel=1



# 한번 적은 패턴 붙여넣기 연속하기
기록 -> ESC -> .


# 대소문자 변환하기
u or U


# 대소문자 구분 안하고 검색하기
set ic
set noic


#선택부분 치환하기
v로 선택 -> Shift+: s///g
:'<,'>s/test/tttt/g


# Folding
http://wiki.kldp.org/wiki.php/ViEditorTips
zE 는 모든 fold 를 제거 


# color 바꾸기
:colorscheme [tab]
:colorscheme [ctrl+d]


# cursor가 위치한 파일 열기
ctrl + w + f


# Tab function
새탭열기 => :tabnew
탭탐색기 => :Texplorer (:Te)
탭 이동(다음) => :gt
탭 이동(이전) => :gT


#Split function
수직나누기 => :sp
수평나누기 => :vs
창 이동    => ctrl+ww OR ctrl+w[h/j/k/l] (vim 이동 명령)
창 최대화  => ctrl+w_
창 사이즈 변경 => 20ctrl+w_


# MARKING
m + MARK
    GLOBAL => [A-Z]
    LOCAL  => [a-z]
    Auto   => [0-9]


# omnifunc
" onmifunc use per file types
" ctrl+x ctrl+o or ctrl+n ctrl+p
"
filetype plugin indent on
set omnifunc=ccomplete#Complete 
set omnifunc=htmlcomplete#Complete 
set omnifunc=csscomplete#Complete
set omnifunc=phpcomplete#Complete
set omnifunc=javascriptcomplete#Complete

complete => CTRL n + p
prototype => CTRL x + o


# Paren
" Highlighting matching parens configuration
" pi_paren options:
"    :NoMatchParen
"    :DoMatchParen
"    :help pi_paren.txt
" pi_paren off
"let loaded_matchparen = 1

기타




TimeZone

CentOS 6


TimeZone 설정하기

$ vi /etc/sysconfig/clock

ZONE#Asia/Seoul

$ tzdata-update

TimeZone 파일들

/etc/localtime
/etc/sysconfig/clock
/usr/share/zoneinfo/Asia/Seoul

CentOS 7


TimeZone 리스트

$ timedatectl list-timezones

TimeZone 설정하기

$ timedatectl set-timezone Asia/Seoul

TimeZone 확인

$ timedatectl

      Local time: 목 2016-01-14 00:13:43 KST
  Universal time: 수 2016-01-13 15:13:43 UTC
        RTC time: 수 2016-01-13 15:13:44
        Timezone: Asia/Seoul (KST, +0900)
     NTP enabled: n/a
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a


Ssh

ssh key 로그인


[Client] ssh-keygen 으로 key 생성하기(dsa|rsa)

$ ssh-keygen -t rsa -f ~/.ssh/example_rsa

.
Enter passphrase (empty for no passphrase):  [Enter]
Enter same passphrase again: [Enter]

[Client] key 생성 확인

$ ls -al ~/.ssh/example_rsa*

-rw------- 1 root root 668 2013-03-19 16:03 example_rsa
-rw-r--r-- 1 root root 604 2013-03-19 16:03 example_rsa.pub

[Client] key 등록

$ vi ~/.ssh/config

IdentityFile     ~/.ssh/example_rsa

$ chmod 644 ~/.ssh/config

[Client->Server] key 복사(Server로)

$ scp ~/.ssh/example_rsa.pub root@example.com:~/.ssh/authorized_keys
$ ssh root@example.com "chmod 700 ~/.ssh"
$ ssh root@example.com "chmod 644 ~/.ssh/authorized_keys"

[Client->Server] key 로그인 확인

$ ssh root@example.com

Last login: Tue Mar 19 16:32:21 2013 from 10.10.10.11
[root@example ~]# 

ssh 파일 전송


scp(Upload)

$ scp -r /home root@example.com:/home/

scp(Download)

$ scp -r root@example.com:/home /home/

ssh(Upload)

$ tar cp /home | ssh root@example.com "tar xvp -C /home/"

ssh(Download)

$ ssh root@example.com "tar cp /home" | tar xvp -C /home/

ssh 호스트키 체크 비활성화


$ ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=quiet root@example.com

UserKnownHostsFile=/dev/null
known_hosts 파일을 남기지 않도록 설정

StrictHostKeyChecking=no
host key check 를 하지 않도록 설정

LogLevel=quiet
경고 메시지 출력 되지 않도록 설정(Warning: Permanently added…)

sshpass 를 이용한 패스워드 입력 자동화


sshpass 설치
$ yum install sshpass

sshpass 실행
$ sshpass -pPASSWORD ssh root@example.com id

uid=0(root) gid=0(root) groups=0(root)

기타


한줄로

config 생성
$ echo "IdentityFile ~/.ssh/example_rsa" >> ~/.ssh/config

authorized_keys 생성
$ read skey < ~/.ssh/example_rsa.pub; ssh root@example.com "mkdir ~/.ssh;echo $skey >> ~/.ssh/authorized_keys"



Tmux

기본 사용법


new session

$ tmux new -s [session_name]

detach

CTRL + b + d

session list

$ tmux ls

attach

$ tmux attach -t [session_name]

new window

CTRL + b + c

kill window

CTRL + d

kill session

$ tmux kill-session -t [session_name]

move window

CTRL + b + [0-9]
CTRL + b + n | p | l | f
CTRL + b + w

move cursor

CTRL + b + [

view keys

CTRL + b + ?



Screen

실행 옵션


새로운 세션을 연다.

$ screen -S [session_name]

detach 해논 세션으로 접속 한다.

$ screen -r [session_name]

screen SockDir 리스트 출력

$ screen -list

실행후 옵션


상태표시

CTRL + a w

 * : 현재 있는 창에 표시된다.
 - : 처음 시작된 창에 표시된다. (0번이겠지~)

기본사용

CTRL + a d
detach mode 데몬식으로 띠워두고 빠져나온다!

CTRL + a w
현재 스크린의 창수와 현재 있는 창의 위치 표시!

CTRL + a c
새창을 띄운다.

CTRL + a a
바로 전 창으로 이동

CTRL + a [number]
지정한 번호의 창으로 이동

CTRL + a "
모든 윈도우를 선택 할 수 있도록 표시한다.

CTRL + a A
현재창의 제목을 변경

창나누기

CTRL + a S
창을 두개로 나눈다. (s는 대문자다. 즉 Shift +s 이다.)

CTRL + a TAB
갈라진 두창간의 이동 (이동후 새창이 이미 있다면 이동한 프레임에 그창을 띄울수 있다. CTRL +a [number] 이렇게.. )

CTRL + a x
한창 삭제

CTRL + a c
나누어진 창에 터미날을 띠운다. (그 이전에는 터미날은 뜨지 않고 창만 나눠질 뿐이다. )

CTRL + a [number]
지정한 번호의 창을 현재 커서창에 띄운다.
만일 두개를 나누었고 밑에 새창이 있는데 밑의 창 번호를 지정하면 아래와 위가 동일한 반응을 할것이다.

CTRL + Q
다 나가고 하나만 긴다.

CTRL + a + :resize min
현재장의 높이를 최소 사이즈로 한다.



Friday, April 29, 2016

Ps

프로세스 리스트 전체 출력

$ ps -efl --forest

F S UID        PID  PPID  C PRI  NI ADDR SZ WCHAN  STIME TTY          TIME CMD
5 S root      1002     1  0  80   0 - 16029 poll_s Jul18 ?        00:00:17 /usr/sbin/sshd
4 S root     24159  1002  0  80   0 - 23957 unix_s Aug02 ?        00:00:00  \_ sshd: vozlt [priv]
5 S vozlt    24161 24159  0  80   0 - 24257 poll_s Aug02 ?        00:00:43      \_ sshd: vozlt@pts/0
0 S vozlt    24162 24161  0  80   0 - 27083 wait   Aug02 pts/0    00:00:00          \_ -bash
0 S vozlt      481 24162  0  80   0 - 29686 pause  11:06 pts/0    00:00:00              \_ screen -r vozlt0
5 S ntp       1010     1  0  80   0 -  7540 poll_s Jul18 ?        00:00:09 ntpd -u ntp:ntp -p /var/run/ntpd.pid -g
4 S root      1725     1  0  80   0 - 19682 ep_pol Jul18 ?        00:00:12 /usr/libexec/postfix/master
4 S postfix   1734  1725  0  80   0 - 19744 ep_pol Jul18 ?        00:00:01  \_ qmgr -l -t fifo -u
4 S postfix   2003  1725  0  80   0 - 20236 ep_pol 16:29 ?        00:00:00  \_ pickup -l -t fifo -u

옵션 설명

  • –forest
    • 프로세스 트리 형식으로 출력

프로세스 리스트 출력(쓰레드)

$ ps -eflL

F S UID        PID  PPID   LWP  C NLWP PRI  NI ADDR SZ WCHAN  STIME TTY          TIME CMD
5 S root       913     1   913  0    4  80   0 - 62368 poll_s Jul18 ?        00:00:00 /sbin/rsyslogd -i /var/run/syslogd.pid -c 5
1 S root       913     1   914  0    4  80   0 - 62368 futex_ Jul18 ?        00:00:06 /sbin/rsyslogd -i /var/run/syslogd.pid -c 5
1 S root       913     1   916  0    4  80   0 - 62368 poll_s Jul18 ?        00:00:06 /sbin/rsyslogd -i /var/run/syslogd.pid -c 5
5 S root       913     1   917  0    4  80   0 - 62368 syslog Jul18 ?        00:00:00 /sbin/rsyslogd -i /var/run/syslogd.pid -c 5

프로세스 사용자 정의 출력

$ ps -eo user,pid,ppid,pcpu,pmem,tty,vsz,rss,size,bsdtime,stime,cmd --sort=-vsz,-rss,-pcpu

USER       PID  PPID %CPU %MEM TT          VSZ   RSS    SZ   TIME STIME CMD
nobody   10245 21161  0.0  7.5 ?        442236 77436 47804   0:51 Aug20 php-fpm: pool www
nobody   10145 21161  0.0  7.4 ?        442028 76276 47580   0:55 Aug20 php-fpm: pool www
root     21161     1  0.0  1.1 ?        404392 11236 12032   1:23 Aug07 php-fpm: master process (/etc/php.d/php-fpm.ini)
root       913     1  0.0  0.4 ?        249472  4708 228212   0:12 Jul18 /sbin/rsyslogd -i /var/run/syslogd.pid -c 5

출력 필드별 설명

코드        헤더        설명

user        USER        사용자이름
pid         PID         프로세스ID
ppid        PPID        부모프로세스ID
pcpu        %CPU        CPU 사용률
pmem        %MEM        물리적 메모리 사용률
tty         TT          터미널
vsz         VSZ         가상 메모리 크기(단위: KB)
rss         RSS         물리 메모리 크기(단위: KB)
size        SZ          스왑 공간 크기(실제 페이지 영역에 쓸 공간이 없다면 옮겨지게되는:/proc/${PID}/status:VmData+VmStk)
bsdtime     TIME        누적된 CPU 시간(user + system)
stime       STIME       프로세스 시작 시간
cmd         CMD         인자를 포함하는 명령

옵션 설명

  • –sort=-vsz,-rss,-pcpu
    • 가상메모리크기,물리메모리크기,CPU사용률이 큰 것부터 출력한다.

기타

pmap

$ pmap -x {PIDS}



Wednesday, April 27, 2016

Iptables

PREROUTING, OUPUT, POSTROUTING

enter image description here

외부에서 {IP:PORT} 로 오는 패킷을 {IP:PORT} 로

10.10.10.44:80 로 오는 모든 패킷을 16.16.16.16:8080 으로 보내기

$ iptables -A PREROUTING -t nat -p tcp -m tcp -i eth2 -d 10.10.10.44 --dport 80 -j DNAT --to 16.16.16.16:8080

로컬에서 {IP:PORT} 로 오는 패킷을 {IP:PORT} 로

10.10.10.44:80 로 오는 모든 패킷을 16.16.16.16:8080 으로 보내기

$ iptables -A OUTPUT -t nat -p tcp -m tcp -i eth2 -d 10.10.10.44 --dport 80 -j DNAT --to 16.16.16.16:8080

참고

NAT - Network Address Translation



Date

Date 명령어

오늘 날짜 구하기

$ date +'%Y-%m-%d %H:%M:%S'

2013-08-07 16:56:12

하루전 날짜 구하기

$ date --date="-1 day" +'%Y-%m-%d %H:%M:%S'

2013-08-06 16:56:12

하루후 날짜 구하기

$ date --date="+1 day" +'%Y-%m-%d %H:%M:%S'

2013-08-08 16:56:12

마지막 지나간 요일에 대한 날짜 구하기

$ date --date="last Friday" +'%Y-%m-%d %H:%M:%S'

2013-08-02 16:56:12

돌아오는 요일에 대한 날짜 구하기

$ date --date="next Friday" +'%Y-%m-%d %H:%M:%S'

2013-08-09 16:56:12

Unix epoch time 구하기(seconds since 1970-01-01 00:00:00 UTC)

$ date +'%s'

1375863160


Crontab

Crontab 사용하기

명령 실행

$ crontab -e

작성

* * * * * $HOME/bin/minute.job

필드별 설명

------    --------  ---------------------------------------------------
필  드    의  미    범  위
------    --------  ---------------------------------------------------
첫번째    분        0-59
두번째    시        0-23
세번째    일        0-31
네번째    월        1-12
다섯번째  요일      0-7 (0 또는 7=일요일, 1=월, 2=화,...)
여섯번째  명령어    실행할 명령을 한줄로 쓴다.
------    --------  ---------------------------------------------------