useful commands

Curated list of useful commands for different use cases

1. Get PID of process

  • Process with the following status:

    • Started with command

    • Listening or established on certain service port

$ pgrep -a <command>
$ ps w | grep <command>
$ lsof -i4 -P -n | grep LISTENING | grep :<port>
$ lsof -i4 -P -n | grep  ESTABLISHED | grep :<port>

# eg.
$ pgrep -a ssh
$ ps w | grep ssh
$ lsof -i4 -P -n | grep LISTENING | grep :22
$ lsof -i4 -P -n | grep  ESTABLISHED | grep :22

2. Process kill signals

 # SIGTERM (15) - graceful stop
 $ kill -s SIGTERM <pid>
 $ kill -SIGTERTM <pid>
 $ kill -15 <pid>
 
 # SIGKILL (9) - force kill 
 $ kill -s SIGKILL <pid>
 $ kill -SIGKILL <pid>
 $ kill -9 <pid>
 
 # SIGINT (2) - ctrl+c
 $ kill -s SIGINT <pid>
 $ kill -SIGINT <pid>
 $ kill -2 <pid>

3. Transfer file(s) between 2 hosts

3.1 Netcat

  • Single file

  • Multiple files with the same extension

3.2 Secure Copy Protocol (scp)

Optionally use the -P flag to specify the port on the remote host to connect to

  • Single file

  • Multiple files with the same extension

3.3 wget + Python3 server

  • Single file

Last updated