Featured image of post 리눅스 명령어

리눅스 명령어

유용한 리눅스 명령어들을 정리해 보자

Network

tcpdump

tcpdump prints out a description of the contents of packets on a network interface. https://www.tcpdump.org/manpages/tcpdump.1.html

tcpdump dst 192.168.11.11 and port 22
tcpdump -i eno1 host 192.168.11.11
tcpdump host 192.168.11.11 and tcp port 443 -w tcpdump.log
tcpdump -r tcpdump.log

nc

nc scans TCP and UDP connections
https://linux.die.net/man/1/nc

nc -zv 192.168.123.123 443
=> Connection to 192.168.123.123 443 port [tcp/*] succeeded!

arping

arping sends ARP request to a neighbor host.
https://man7.org/linux/man-pages/man8/arping.8.html

sudo arping 192.168.123.123
=> 60 bytes from a1:b2:c3:d4:e5:f6 (192.168.123.123) ...

ETC

top

top displays system info as well as a list of processes or threads currently managed by the Linux Kernel.
https://man7.org/linux/man-pages/man1/top.1.html

top -p <pid> -H

tee

tee reads from standard input and writes to standard output and files.
https://man7.org/linux/man-pages/man1/tee.1.html

echo "hello" | tee OUTFILE
cat OUTFILE | tee NEWFILE
echo "hello" | tee -a OUTFILE
echo "hello" | tee -a OUTFILE /dev/null

Why use tee?
-> It might be thought that echo, cat is sufficient. But, They can’t write into root files.

# "permission denied" occured.
sudo echo "Hello" >> /root/test.txt
# It works successfully.
echo "Hello" | sudo tee -a /root/test.txt

lsof

lsof lists file information about files opened by processes.
https://man7.org/linux/man-pages/man8/lsof.8.html

sudo lsof -a -p 1234567 -d cwd

COMMAND     PID USER  FD TYPE DEVICE SIZE/OFF   NODE NAME
python3 1234567 test cwd  DIR   8,2    4096  5656565 /home/test/test-server

screen

screen multiplexes a physical terminal to each virtual terminal.
https://linux.die.net/man/1/screen

When a long-running task on a remote machine is performed, It helps that the SSH session is terminated and the work is corrupted or lost.

# Create a new session
screen -S test
# Detach the session
ctrl-a + d
screen -ls
# Resume a detached screen session.
screen -r test
# Exit with the session termination.
exit

pstree

pstree displays a tree of process.
https://man7.org/linux/man-pages/man1/pstree.1.html

screen -S test
./test-app &
ctrl-a + d
screen -ls
pstree -p 1234567

lsblk

lsblk lists information about all available or the specified block devices.
https://man7.org/linux/man-pages/man8/lsblk.8.html

lsblk -o name,rota,size,mountpoint

mount

mount serves to attach the file system on some device to the specific directory.
https://linux.die.net/man/8/mount

mount /dev/sda /backup
unmount /dev/sda
df -h