Skip to content

Instantly share code, notes, and snippets.

@novalagung
Last active November 1, 2023 16:45
Show Gist options
  • Save novalagung/447dd598e118ca6ab2c2b2a7ab56b8f5 to your computer and use it in GitHub Desktop.
Save novalagung/447dd598e118ca6ab2c2b2a7ab56b8f5 to your computer and use it in GitHub Desktop.
Linux command cheatsheet, for beginner

Linux command cheatsheet, for beginner

Get executable location of running process by PID

# sudo readlink -f /proc/{PID}/exe
$ sudo readlink -f /proc/479/exe

/tmp/go-build499480868/command-line-arguments/_obj/exe/main

Get PID by port

# sudo lsof -i :{PORT}
$ sudo lsof -i :80

COMMAND   PID USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
acwebseca 479 root   36u  IPv4 0x67f0eb35ab961817      0t0  TCP 192.168.0.81:59231->ec2-52-74-15-96.ap-southeast-1.compute.amazonaws.com:http (ESTABLISHED)

Kill process by port

# sudo kill $(fuser -n tcp fuser -n tcp {PORT} 2> /dev/null
$ sudo kill $(fuser -n tcp fuser -n tcp 80 2> /dev/null

Kill process from the executable

# sudo pkill {EXECUTABLE}
$ sudo pkill /path/of/the/executable/someapp

Run process in background

# {COMMAND} &
$ ./someapp &

Run process in background, and prevent it for stopping even after session ended

By default if you are running an app on background, it'll be killed after the shell session ended. For example you do some ssh then run command which take very long time to finished. When your ssh session ended, your process will be killed.

By using nohup the process will always running even after shell session ended.

# nohup {COMMAND} &
$ nohup ./someapp &
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment