SSH Command in Linux with examples

Processes and services commands in Linux

See what is running, stop what is stuck, and manage background services.

#ps

List processes

Syntaxps [options]
  • ps aux

    Every process, with owner, CPU and memory

  • ps aux | grep nginx

    Find one program

  • ps -ef --forest

    Show a parent-and-child tree

#top

Live process monitor

Syntaxtop
  • top

    Live list; press q to quit, M to sort by memory, P by CPU

#htop

Friendlier live monitor

Syntaxhtop
  • htop

    Coloured view; use F9 to kill, F6 to sort

TipInstall with sudo apt install htop (or your package manager).

#kill

Stop a process by number

Syntaxkill [-signal] PID
  • kill 1234

    Politely ask process 1234 to stop

  • kill -9 1234

    Force it to stop (last resort)

  • kill -HUP 1234

    Ask a service to reload its settings

#pkill / killall

Stop processes by name

Syntaxpkill name | killall name
  • pkill -f "python app.py"

    Stop processes whose command matches

  • killall node

    Stop every process called node

#pgrep

Find a process number

Syntaxpgrep [-a] name
  • pgrep -a nginx

    Show PIDs and full commands

#jobs / bg / fg

Background jobs in your shell

Syntaxcommand & | jobs | bg | fg
  • sleep 300 &

    Start a command in the background

  • jobs

    List your background jobs

  • fg %1

    Bring job 1 to the front

TipPress Ctrl+Z to pause the running command, then bg to continue it in the background.

#nohup

Keep running after you log out

Syntaxnohup command &
  • nohup ./long-task.sh > out.log 2>&1 &

    Survives closing the SSH session

#nice / renice

Change priority

Syntaxnice -n N command | renice N -p PID
  • nice -n 10 ./backup.sh

    Start with lower priority

  • sudo renice -n 5 -p 1234

    Change a running process

#systemctl

Manage services

Syntaxsystemctl action service
  • systemctl status nginx

    Is it running? Shows recent log lines too

  • sudo systemctl restart nginx

    Stop and start

  • sudo systemctl reload nginx

    Re-read settings without dropping connections

  • sudo systemctl enable --now nginx

    Start now and at every boot

  • systemctl list-units --failed

    See what has failed

#journalctl

Read service logs

Syntaxjournalctl [options]
  • sudo journalctl -u nginx

    Logs of one service

  • sudo journalctl -u nginx -f

    Follow the log live

  • sudo journalctl --since "1 hour ago"

    Recent entries

  • sudo journalctl -p err -b

    Errors since the last boot

TipWithout sudo you only see your own messages, unless your user is in the adm or systemd-journal group.

#crontab

Scheduled jobs

Syntaxcrontab [-e | -l]
  • crontab -e

    Edit your jobs

  • crontab -l

    List your jobs

  • 0 2 * * * /home/deploy/backup.sh

    A line you can add: run every day at 02:00

TipThe five fields are minute, hour, day of month, month, day of week.

#screen / tmux

Sessions that survive a dropped connection

Syntaxtmux | screen
  • tmux new -s work

    Start a named session

  • tmux attach -t work

    Come back to it after reconnecting

  • tmux ls

    List sessions

TipInside tmux, press Ctrl+B and then D to detach and leave everything running.

Run these commands with SSH Command

SSH Command is a desktop app for Mac, Windows and Linux that puts a real terminal, SFTP file panes, a sudo switch and a searchable Linux command finder in one window. Type what you want to do, and send the command to your server with one click.

Download free Windows commands with examples SFTP & FTP client