ps

The ps command lists running processes. Using ps without any options causes it to list the processes running in the current shell.
To see every process that is running, use the -e (every process) option:

ps -aux  # 현재 열려있는 작업과 PID를 볼 수 있다.
ps -ef | grep node  # 노드의 상태를 볼 수 있다.

kill

The kill command allows you to terminate a process from the command line. You do this by providing the process ID (PID) of the process to kill. Don’t kill processes willy-nilly. You need to have a good reason to do so. In this example, we’ll pretend the shutter program has locked up.

To find the PID of shutter we’ll use our ps and grep trick from the section about the alias command, above. We can search for the shutter process and obtain its PID as follows:

kill -9 [pid] : #pid값을 지닌 작업을 죽인다.

pkill

pkill [service_name ]  #service명을 지닌 작업을 죽인다.
pkill -f node #모든 노드를 죽인다.

netstat

netstat -tnlp #열려있는 모든 포트를 본다

lsof

lsof -i TCP:[포트번호]  # 특정 포트에서 사용한느 프로그램 확인
lsof -i -P -n | grep LISTEN  # listen 중인 모든 포트 나타냄

fuser

fuser -k -n tcp [포트번호]  # 특정 포트를 사용하는 프로그램 죽이기
fuser 8080/tcp # 포트가 쓰이는지 확인 
fuser -k 8080/tcp # 포트 사용하고 있는 태스크 중지

mkdir

mkdir [폴더명]  #폴더만들기

rm

rm [파일명]  #파일 삭제

rmdir

rmdir [디렉토리명]  #디렉토리삭제

find

Use the find command to track down files that you know exist if you can’t remember where you put them. You must tell find where to start searching from and what it is looking for. In this example, the . matches the current folder and the -name option tells find to look for files with a name that matches the search pattern.

You can use wildcards, where * represents any sequence of characters and ? represents any single character. We’re using ones to match any file name containing the sequence “ones.” This would match words like bones, stones, and lonesome.

find . -name *ones*

histroy

histroy | grep  [찾는 키워드] #내가 입력한 cmd 중 매치하는 것을 찾아줌

service

service --status-all | grep [키워드]  #실행중인 서비스를 보여준다

wget

wget [url] # url을 get으로 request 후 response 수신

ckconfig

ckconfig

which

which [소프트웨어명] # 소프트웨어의 디렉토리를 찾아줌

top

top # 현재 컴퓨터의 메모리 cpu등의 상태를 보여준다

ssh

Use the ssh command to make a connection to a remote Linux computer and log into your account. To make a connection, you must provide your user name and the IP address or domain name of the remote computer. In this example, the user mary is logging into the computer at 192.168.4.23. Once the connection is established, she is asked for her password.

ssh –i CRT11-KeyPair ec2-user@10.11.12.132  # 리눅스에서 리눅스로 ssh가능

alternatives

alternatives --set python /usr/bin/python3.5 # 환경변수와 연결된 실행파일을 변경함

cp [옵션] [원본] [사본]

원본의 위치를 사본으로 복사해준다.

a: 원본 파일의 속성, 링크 정보들을 그대로 유지하면서 복사한다.
b: 복사할 대상이 이미 있을 경우 기존 파일을 백업하고 복사한다.
d: 만약 복사할 원본이 심볼릭 링크일 때 심볼릭 자체를 복사한다.
f: 만약 복사할 대상이 이미 있으면 강제로 지우고 복사한다.
i: 만약 복사할 대상이 이미 있으면 사용자에게 물어본다.
l: 하드링크 형식으로 복사한다.
P: 원본 파일 지정을 경로와 같이했을 경우 그 경로 그대로 복사된다.
p: 파일의 소유자, 그룹, 권한, 시간 정보들이 그대로 보존되어 복사된다.
r: 원본이 파일이면 그냥 복사되고 디렉터리라면 디렉터리 전체가 복사된다.
s: 파일을 심볼릭 링크 형식으로 복사한다. 원본 파일이름을 절대 경로로 지정해야 한다.
u: 복사할 대상이 있을 때 이 파일의 변경 날짜가 같거나 더 최근의 것이면 복사하지 않는다.
v: 복사 상태를 보여준다.
x: 원본과 대상 파일의 파일시스템이 다를 경우에는 복사하지 않는다.
R: 디렉터리를 복사할 경우 그 안에 포함된 모든 하위경로와 파일들을 모두 복사한다.

tail

파일의 마지막 부분을 출력한다.

tail -f # 파일의 마지막 10라인을 실시간으로 계속해서 출력
tail -F # 파일 변동 시 실시간으로 보여주되 로그파일처럼 특정 시간이 지난 후 파일이 변하게 되면 새로운 파일을 오픈하여 보여줌  (다시 명령을 실행할 필요가 없음)
tail -n # n 만큼의 라인을 출력

df

The df command shows the size, used space, and available space on the mounted filesystems of your computer.
 
Two of the most useful options are the -h (human readable) and -x (exclude) options. The human-readable option displays the sizes in Mb or Gb instead of in bytes. The exclude option allows you to tell df to discount filesystems you are not interested in. For example, the squashfs pseudo-filesystems that are created when you install an application with the snap command

df -h -x squashfs 

du

1k블록단위로 사용 용량. 그리고 하위 디렉토리를 볼 수 있다. 여담으로 디스크의 최소단위가 4k이기 때문에 디렉토리중 용량이 4k인것은 빈 디렉토리일 확율이 크다

du

tar

tar -cvf [파일명.tar] [폴더명] #  tar로 압축하기 
tar -xvf [파일명.tar] # tar 압축 풀기
tar -zcvf [파일명.tar.gz] [폴더명] #  tar.gz로 압축하기 
tar -zxvf [파일명.tar.gz] #  tar.gz 압축 풀기 

chmod

To set the permission to be read, write, and execute (7 from our list) for the owner; read and write (6 from our list) for the group; and read and execute (5 from our list) for the others we’d need to use the digits 765 with the chmod command:

chmod -R 765 example.txt # example.txt의 권한을 설정한다

chown

You can use chown to change the owner or group, or both of a file. You must provide the name of the owner and the group, separated by a : character. You will need to use sudo. To retain dave as the owner of the file but to set mary as the group owner, use this command:

sudo chown dave:mary example.txt

diff

The diff command compares two text files and shows the differences between them. There are many options to tailor the display to your requirements.
 
The -y (side by side) option shows the line differences side by side. The -w (width) option lets you specify the maximum line width to use to avoid wraparound lines. The two files are called alpha1.txt and alpha2.txt in this example. The --suppress-common-lines prevents diff from listing the matching lines, letting you focus on the lines which have differences.

diff -y -W 70 alpha1.txt alpha2.txt --suppress-common-lines

finger

The finger command gives you a short dump of information about a user, including the time of the user’s last login, the user’s home directory, and the user account’s full name.

finger

free

The free command gives you a summary of the memory usage with your computer. It does this for both the main Random Access Memory (RAM) and swap memory. The -h (human) option is used to provide human-friendly numbers and units. Without this option, the figures are presented in bytes.

free -h

grep

The grep utility searches for lines which contain a search pattern. When we looked at the alias command, we used grep to search through the output of another program, ps . The grep command can also search the contents of files. Here we’re searching for the word “train” in all text files in the current directory.

grep train *.txt

group

groups dave
groups django-user
groups ec2-user

history

The history command lists the commands you have previously issued on the command line. You can repeat any of the commands from your history by typing an exclamation point ! and the number of the command from the history list.

!188 # execute 188 command in bash history
!! # execute previous command

less

The less command allows you to view files without opening an editor. It’s faster to use, and there’s no chance of you inadvertently modifying the file. With less you can scroll forward and backward through the file using the Up and Down Arrow keys, the PgUp and PgDn keys and the Home and End keys. Press the Q key to quit from less.
 
To view a file provide its name to less as follows:

less views.py

man

The man command displays the “man pages” for a command in less . The man pages are the user manual for that command. Because man uses less to display the man pages, you can use the search capabilities of less.
 
For example, to see the man pages for chown, use the following command:

man chown
man less

passwd

The passwd command lets you change the password for a user. Just type passwd to change your own password.
 
You can also change the password of another user account, but you must use sudo. You will be asked to enter the new password twice.

sudo passwd mary

ping

The ping command lets you verify that you have network connectivity with another network device. It is commonly used to help troubleshoot networking issues. To use ping, provide the IP address or machine name of the other device.

ping 192.168.4.18

w

The w command lists the currently logged in users.

w

reference

+ Recent posts