Linux Command


Shell script 특수문자 | 특수문자 | 의미 | |:———-:|—————————————————————————–| | $0 | The name of the script being executed. (Ex. sh test.sh -> test.sh, sh /workspace/temp/test.sh -> /workspace/temp/test.sh) | | $$ | The process ID of the current shell | | $# | The number of command-line arguments | | $? | The exit status of the last executed command, 쉘에서 최근 실행한 명령어의 종료 상태를 담은 변수 | | $1-$9 | The first nine command-line arguments | | $@ | All command-line arguments as an array, $* 과 비슷하나 $@는 “$1”, …“$N”을 의미 | | $* | All command-line arguments as a single string, 모든 위치 매개변수를 담고 있는 단일 문자열 | | $_ | 마지막 인수를 출력하는 변수를 저장 |


ldd (List Dynamic Dependencies)

# 프로그램이 어떤 라이브러리를 링크하는지
$ ldd /bin/echo
	linux-vdso.so.1 (0x00007ffdcc39b000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fae38000000)
	/lib64/ld-linux-x86-64.so.2 (0x00007fae383d6000)

taskset & sar (System Activity Report)

# 특정 프로세스를 특정 논리 코어에서 실행
taskset -c <logical cpu num> <command>
sudo taskset -c 0 ./inf-loop.py &

# CPU 코어 0의 데이터를 3초마다 5번 수집하는 의미
$ sar -P 0 1 5
Linux 6.2.0-1012-aws (ip-10-20-15-218) 	12/05/2023 	_x86_64_	(4 CPU)
01:04:57 PM     CPU     %user     %nice   %system   %iowait    %steal     %idle
01:04:58 PM       0     91.09      0.00      0.00      0.00      8.91      0.00
01:04:59 PM       0     96.97      0.00      0.00      0.00      3.03      0.00
01:05:00 PM       0     88.12      0.00      0.00      0.00     11.88      0.00
01:05:01 PM       0     87.00      0.00      0.00      0.00     13.00      0.00
01:05:02 PM       0     82.00      0.00      0.00      0.00     18.00      0.00
Average:          0     89.02      0.00      0.00      0.00     10.98      0.00

%user + %nice = 사용자 모드에서 프로세스를 실행하는 시간 %system = 커널이 시스템 콜을 처리한 시간 비율 %idle = 아무것도 하지 않는 아이들 상태 비율

tcpdump

# 특정 작업을 실행 후 3번 정도 수행
tcpdump -i eth0 any port <destination port> -w packetdump.pcap

if

# -eq: equal
if [ "$a" -eq "$b" ]

# -ne: not equal
if [ "$a" -ne "$b" ]

# -z: 문자열이 "null"임. 즉, 길이가 0

# -n: 문자열이 "null"이 아님.
if [[ -n "$KUBELET_EXTRA_ARGS" ]]; then
  cat << EOF > /etc/systemd/system/kubelet.service.d/30-kubelet-extra-args.conf
[Service]
Environment='KUBELET_EXTRA_ARGS=$KUBELET_EXTRA_ARGS'
EOF
fi

openssl

# 인증서 볼 때 
openssl x509 -text -noout -in test.pem

base64

echo $TOKEN | base64 --decode; echo 

efs mount

sudo yum -y update  
sudo yum -y install nfs-utils

mkdir /mount-point
sudo mount -t nfs -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport fs-0810dac727c8700a9.efs.ap-northeast-2.amazonaws.com:/   /mount-point
  • Ref: https://docs.aws.amazon.com/efs/latest/ug/wt1-test.html

iptables

iptables -L -t filter
iptables -L -t nat

ip6tables -L -t filter
ip6tables -L -t nat

while반복문

while true; do
echo "======================================================="
netstat -anop | grep SYN
sleep 1
done

압축하기

tar -cpvf dr.tar dr 

-c 압축 
-p 권한유지 
-v 진행사항 
-f 파일이름변경 

압축풀기

tar -xvf dr.tar 

-x 압축해제 
-v 진행사항 
-f 파일 이름 

Jar 클래스 파일 검색

find . -type f -name '*.jar' | while read LINE;do echo $LINE; jar tvf $LINE | grep "log4j";done 
find . -type f -name '*.jar' | while read LINE;do echo $LINE; jar tvf $LINE;done 

TCPDUMP

tcpdump -i eth0 -w test.pcap 

SCP

scp httpd_imws.conf wasadm@10.43.43.15:/was/jbcs-httpd24-2.4/httpd/conf 
scp -Rp safenet wasadm@10.43.43.15:/was/jboss-eap-7.2/modules/com/safenet 
scp -rp com_kal_cms_war.ear dco3user@10.43.43.23:/home/dco3user 

ChangeOwner

chown wasadmin:wasadmin dr 

# 기존 gid 3030 -> wasadm 변경 
find -group 3030 | while read line ; do chgrp wasadm "$line"; done 
# 기존 uid 3030 -> wasadm 변경 
find -user 3030 | while read line ; do chown wasadm "$line"; done 

Change Mode

chmod 755 

-R 하위폴더 권한까지 변경 (755 rwxr-xr-x)

문자, 라인, 단어 수

ps -ef | grep java | wc -l 

-c 전체 문자 수 출력 
-l 전체 라인 수 출력 
-w 전체 단어 수 출력 

호스트에 장착된 네트워크 인터페이스의 통신 상태를 보여 줌

netstat -ano 

-a 활성화된 모든 TCP 연결 정보를 보여 줌 
-n 출력결과가 숫자형태가 되도록 함 (IP 주소, 포트 번호 등) 
-o 해당 포트를 연 프로세스 ID를 보여줌 
ㅣ…/ 

다운로드

wget https://archive.apache.org/dist/httpd/httpd-2.4.20.tar.gz 

Kill

ps -ef | grep httpd | awk '{print $2}' | xargs kill -9 

ps -ef | grep travelmn | awk '{print $2}' | xargs kill -9 

ps -ef | grep lmms | grep httpd | awk '{print $2}' | xargs kill -9 

Text검색

grep -rin JAVA_OPTS 

-b 검색 결과의 각 행 앞에 검색된 위치의 블록 번호를 표시한다. 검색 내용이 디스크의 어디쯤 있는지 위치를 알아내는데 유용하다. 
-c 검색 결과를 출력하는 대신, 찾아낸 행의 총수를 출력한다.  (count) 
-h 파일 이름을 출력하지 않는다. 
-I 대소문자를 구분 하지 않는다.(대문자와 소문자를 동일하게 취급). (ignore) 
-l 패턴이 존재하는 파일의 이름만 출력한다.(개행문자로 구분) (list file) 
-n 파일 내에서 행 번호를 함께 출력한다. (number) 
-s 에러 메시지 외에는 출력하지 않는다. 종료상태를 검사할 때 유용하게 쓸 수 있다. 
-v 패턴이 존재하지 않는 행만 출력한다. (invert) 
-w 패턴 표현식을 하나의 단어로 취급하여 검색한다. (word) 

Tag: [ linux  command  ]