Linux Command 정리 #2

입질쾌감 물때표

################################################################################
현재 TTY 번호 알아내기
################################################################################
$ ps ax | grep $$ | awk ‘{ print $2 }’
$ tty | sed -e “s:/dev/::”

################################################################################
다른 계정의 명령어 진행 상황 보기
################################################################################
$ tail -f /root/.bash_history

################################################################################
전체 터미널 접속 현황보기
################################################################################
$ w
10:41:45 up 1 day, 19:55, 6 users, load average: 0.96, 0.88, 0.76
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
webterro tty7 :0 Mon14 43:55m 36:21 0.96s gnome-session –session=gnome-fallback
webterro pts/0 :0.0 Mon14 17:57m 0.42s 0.42s bash
webterro pts/2 :0.0 10:24 2:25 0.32s 0.23s ssh test@test.org
webterro pts/10 :0.0 Tue12 15:34m 1.47s 1.41s ssh -p 5522 test@192.168.0.150
webterro pts/11 :0 10:34 1.00s 0.30s 0.00s w
webterro pts/12 :0 10:34 6:51 0.08s 0.08s bash

################################################################################
현재 서비스가 OPEN된 LISTEN 상태의 프로세스 번호 알아내기
################################################################################
netstat -tupln

################################################################################
so 라이브러리 의존성 확인하기
################################################################################
find /bin -type f -perm /a+x -exec ldd {} \;

################################################################################
APM 한방 설치
################################################################################
1. 아파치 서버 설치
sudo apt-get install apache2

2. MySQL 인증 모듈 설치
sudo apt-get install libapache2-mod-auth-mysql

3. MySQL 서버/클라이언트 설치
sudo apt-get install mysql-server mysql-client

4. PHP 설치
sudo apt-get install php5 php5-cli curl memcached php5-curl php5-gd php5-memcache php5-mysql php-apc php5-xsl php5-imap libssh2-php libapache2-mod-php5 php5-gd php5-xmlrpc php5-intl

5. 아파치 서버 재시작
sudo /etc/init.d/apache2 restart

6. 아파치 유저 dir 모듈 추가
sudo a2enmod userdir

################################################################################
포트별 프로세스 번호 알아내기
################################################################################
sudo netstat -aep | grep “:80” | awk ‘{print $9}’ | cut -f1 -d “/”
// 포트 커넥션 실시간 보기
sudo netstat -aepn -c 1 | grep 8081

################################################################################
리눅스 및 우분투 버전 알아내기
################################################################################
현재 우분투 버전 알아내기
lsb_release -a

################################################################################
배포판 버전 알아내기
################################################################################
cat /proc/version

################################################################################
하드웨어 각종 정보 보기
################################################################################
# arch show architecture of machine(1) [man]
# cal 2007 show the timetable of 2007 [man]
# cat /proc/cpuinfo show information CPU info [man]
# cat /proc/interrupts show interrupts [man]
# cat /proc/meminfo verify memory use [man]
# cat /proc/swaps show file(s) swap [man]
# cat /proc/version show version of the kernel [man]
# cat /proc/net/dev show network adpters and statistics [man]
# cat /proc/mounts show mounted file system(s) [man]
# clock -w save date changes on BIOS [man]
# date show system date [man]
# date 041217002007.00 set date and time – MonthDayhoursMinutesYear.Seconds [man]
# dmidecode -q show hardware system components – (SMBIOS / DMI) [man]
# hdparm -i /dev/hda displays the characteristics of a hard-disk [man]
# hdparm -tT /dev/sda perform test reading on a hard-disk [man]
# lspci -tv display PCI devices [man]
# lsusb -tv show USB devices [man]
# uname -m show architecture of machine(2) [man]
# uname -r show used kernel version [man]

################################################################################
강제로 PTS 클라이언트 끊기
################################################################################
user1@webterror:~$ w
16:14:43 up 1 day, 3:53, 2 users, load average: 0.33, 0.37, 0.34
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
user1 tty7 Mon12 27:53m 7:38 0.45s gnome-session –
user1 pts/0 :0.0 16:13 3.00s 0.15s 0.00s w

[root@server ~#] skill -KILL -v pts/1
This command will force logout and kill the user in pts/1. and the same user logged in pts/2 will not be logged out.

If need to kill a users all the connected sessions at once
[root@server ~#] skill -KILL -u james (this will kill both pts/1 and pts/2 cessions)

To STOP/PAUSE a user’s activities
[root@server ~# ]skill -STOP -u james

To RESUME a stopped user
[root@server ~#] skill -CONT -u james

################################################################################
포트별 프로세스 번호 알아내기
################################################################################
netstat -l -p

################################################################################
웹 접속 헤더및 response 확인하기
################################################################################
curl -v -X GET test.com

################################################################################
ps 명령어 보는 방법
################################################################################
1. 기능
유닉스는 동시에 여러 개의 프로세서가 동작되기 때문에 사용자가 그것들의 목록과 상태를 점검할 필요가 있다. ps라는 이름은 processor status를 의미한다. ps를 사용하여 프로세서들의 상태를 점검할 수 있다.

2. 문법
# ps [ 옵션 ]

3. 옵션
-l : 자세한 형태의 정보를 출력한다.
-u : 각 프로세서의 사용자 이름과 시작 시간을 보여준다.
-j : 작업 중심 형태로 출력한다.
-s : 시그널 중심 형태로 출력한다.
-v : 가상 메모리 중심 형태로 출력한다.
-m : 메모리 정보를 출력한다.
-a : 다른 사용자들의 프로세서도 보여준다.
-x : 로그인 상태에 있는 동안 아직 완료되지 않은 프로세서들을 보여준다. 유닉스 시 스템은 사용자가 로그아웃하고 난 후에도 임의의 프로세서가 계속 동작하게 할 수 있다. 그러면 그 프로세서는 자신을 실행시킨 셸이 없이도 계속 자신의 일을 수행한다. 이러한 프로세서는 일반적인 ps 명령으로 확인할 수 없다. 이때 -x 옵션을 사용하면 자신의 터미널이 없는 프로세서들을 확인할 수 있다.
-S : 차일드(child) CPU 시간과 메모리 페이지 결함(fault) 정보를 추가 한다.
-c : 커널 task_structure로 부터 명령 이름을 보여준다.
-e : 환경을 보여준다.
-w : 긴(wide) 형태로 출력한다. 한 행 안에 출력이 잘리지 않는다.
-h : 헤더를 출력하지 않는다.
-r : 현재 실행중인 프로세서를 보여준다.
-n : USER 와 WCHAN 을 위해 수치 출력을 지원한다.
4. 사용방법 및 정보

가) 기본적으로 ps는 현재 명령이 내려지는 쉘에서 만들어진 프로세서들의 목록만을 보여준다. ps는 자신이 실행되는 당시, 현재의 쉘에 의해서 수행된 프로세서들을 검사하고 보고한다는 점을 생각하자. 그러면 ps의 출력결과 리스트에 ps 자신이 있는 이유를 쉽게 이해할 수 있을 것이다. 각 필드의 의미는 다음과 같다.

COMMAND : 명령어의 이름
PID : 프로세서 ID, 각 프로세서를 구분하기 위한 고유의 ID
RSS : 프로세서에 의해 사용되는 실제 메모리의 용량(K byte 단위)
USER : 프로세서를 실행시킨 소유자의 계정을 보여준다.
VSZ : 프로세서의 자료와 스텍 크기의 (K byte 단위)
TIME : 현재까지 사용된 CPU의 시간(분,초)
TTY : 프로세서의 제어 터미널(t3=/dev/tty3)
%CPU : 마지막 분동안 프로세서가 사용한 CPU시간의 백분율
START : 프로세서가 시작된 시간
STAT : 프로세서의 상태
이 중 STAT 필드는 몇 가지의 부호를 사용해서 프로세서의 상태를 표시하고 있다. 그것들을 정리해 보면 다음과 같다.
P : 수행 가능/수행 중
T : 일시 정지
D : 디스크 입출력 대기 같은 인터럽트할 수 없는 대기상태
S : 20초 미만의 짧게 잠듦(sleep)
I : 20초 이상의 길게 잠듦
Z : 좀비(zombi) 프로세서
좀비(zomb) 상태라는 것은 프로세서가 사라질 때 시그널 처리의 문제로 완전히 소멸되지 못한 상태를 말한다.
대개는 _aux 옵션을 많이 사용한다. 이 중 필요한 프로세스에 대한 결과만 선택적으로 보고자 한다면 grep 명령을 같이 사용한다.

################################################################################
특정 서비스 포트에 메세지 던지는 방법
################################################################################
echo hello | nc localhost 1234
# Note: “nc” (aka “netcat”) is a simple tool that sends data to a host/port

################################################################################
TCP 메세지 보는 방법
################################################################################
sudo apt-get install tcpflow
tcpflow -i eth0 -C

################################################################################
(콘솔화면)터미널 화면 절전모드 끄기
################################################################################
setterm -blank 0
or
setterm -powersave off
or
setterm -blank 0 -powersave off

################################################################################
Standard Error 출력에 관해서
################################################################################
2 = stderr
1 = stdout

2>/dev/null이라는 뜻은 에러메세지를 보여주지 말라는 의미
1>/dev/null이라는 뜻은 일반출력 메세지를 보여주지 말라는 의미

&1, &2 는 출력버퍼이다. 즉 일단 버퍼에 저장시켜놓으라는 의미이므로

2>&1 이라는 뜻은 에러메세지를 &1번 버퍼로 저장하라는 뜻!!

python manage.py runserver 0.0.0.0:8000 2>/dev/null

################################################################################
각종 하드디스크 등의 장치정보 보기
################################################################################
blkid – locate/print block device attributes

(예)
user1@webterror-desktop:~$ sudo blkid
/dev/sda1: UUID=”EC16BD7616BD41FE” TYPE=”ntfs”
/dev/sda3: UUID=”8b80639c-01b0-43e9-8341-de2770018e2d” TYPE=”swap”
/dev/sda4: UUID=”b45b8474-0aa4-4096-afec-29222646685c” TYPE=”ext4″

################################################################################
USB 라벨 바꾸기
################################################################################
dosfslabel /dev/sdb1 LABEL

################################################################################
ssh 서버 접근 유저별 제한하기
################################################################################
I assume you meant logging in over SSH? Put the following line to /etc/ssh/sshd_config:

PermitRootLogin no
If you want to deny certain users from logging in, put this in the configuration file:

DenyUsers root

################################################################################
rar 압축 풀기
################################################################################
mkdir php-pastebin
unrar x php-pastebin-2.1.rar ~/public_html/root/php-pastebin
This takes the blacklisting approach. Whitelisting is generally preferable. If your company needs to allow the rob and admin users log in on the server, use the following configuration directive:

AllowUsers rob admin

################################################################################
디렉토리 전체 파일 로그 보기
################################################################################
multitail –mergeall -q 1 ‘directory/*’

root@debian-xb110:~# multitail –mergeall /var/log/samba/*

(inotifywait 활용)
inotifywait -m –timefmt ‘%H:%M’ –format ‘%T %w %e %f’ /var/log/apache2/

inotifywait -mrq –format ‘%w%f’ /var/log/apache2/ | while read file; do tail -f $file; done

################################################################################
바로이전 디렉토리로 이동하기
################################################################################
cd –
pushd ~/some_path
pushd /another_path
popd
popd
cd $OLDPWD

################################################################################
특수문자를 포함한 파일 삭제 방법
################################################################################
find ./ -inum 4072489 -delete

################################################################################
ebook 컨버터 툴
################################################################################
apt-get install calibre
@@ 젠투
emerge calibre
ebook-convert a.txt b.epub
ebook-convert KMA1.TXT KMA1.epub –no-default-epub-cover –title=옆으로읽는세상1 –authors=이전훈

################################################################################
Bash에서 명령어를 쳤을때 메세지가 있는지 없는지 여부를 아는 방법
################################################################################
bash에서, 프로그램이 되돌리는 값은 특별한 변수인 $?로 받는다.
다음은 어떻게 프로그램이 되돌리는 값을 받아내느냐를 보여 주는 것이다. 나는 여기에서 dada 라는 디렉토리가 존재하지 않는다고 가정하겠다. 화면에 뭔가 나오지 않는가?
(예제)
root@webterror:/home/ssh_guest/guest1/upload# ls
[은행]스마트폰_지로공통서비스_20140630.hwp a.zip (완료)[CSP]은행연동기본설계서v3.0.0(주민번호제거관련).hwp sample 스마트작업내용.txt xmlMap xmlMap1
root@webterror:/home/ssh_guest/guest1/upload# echo $?
0
root@webterror:/home/ssh_guest/guest1/upload# cd “fdkd”
-su: cd: fdkd: No such file or directory
root@webterror:/home/ssh_guest/guest1/upload# echo $?
1
root@webterror:/home/ssh_guest/guest1/upload#

################################################################################
ssh 패스워드 변경시
################################################################################
ssh -t nixcraft@server1.cyberciti.biz passwd
@@ 삭제시
ssh-keygen -R hostname

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다