Skip to main content

Linux Background Commands: Using &, jobs, bg, and fg

HardReset.InfoDecember 16, 20254 min38 views
5 connections·10 entities in this video→

Running Commands in the Background

  • πŸ’‘ To run a command in the background on Linux, append an ampersand (&) to the command.
  • πŸš€ For example, sleep 1000 & will run the sleep command for 1000 seconds in the background, and you will receive the Process ID (PID).

Managing Background Jobs

  • πŸ” The jobs command is used to list all processes currently running in the background.
  • ⏸️ A foreground process can be suspended by pressing Ctrl+Z.
  • ❌ Pressing Ctrl+C will stop a foreground process entirely.

Moving Processes Between Foreground and Background

  • πŸ“€ To move a stopped job to the background, use the bg command followed by the job number (e.g., bg %2).
  • πŸ“₯ To bring a background job back to the foreground, use the fg command followed by the job number (e.g., fg %1).

Use Cases and Alternatives

  • ⏱️ Running commands in the background is particularly useful for long-running scripts or algorithms that take several minutes to complete, preventing the terminal from being occupied.
  • πŸ”— For persistent background jobs that should continue even after the terminal is closed, consider alternatives like nohup, disown, screen, or tmux.
Knowledge graph10 entities Β· 5 connections

How they connect

An interactive map of every person, idea, and reference from this conversation. Hover to trace connections, click to explore.

Hover Β· drag to explore
10 entities
Chapters2 moments

Key Moments

Transcript16 segments

Full Transcript

Topics14 themes

What’s Discussed

LinuxBackground ProcessesTerminal CommandsAmpersand (&)jobs commandbg commandfg commandProcess ID (PID)Ctrl+ZCtrl+Cnohupdisownscreentmux
Smart Objects10 Β· 5 links
ProductsΒ· 3
ConceptsΒ· 7