• Contact
  • About Me
  • Privacy Policy
  • Disclaimer
DefenceDev
  • Home
  • Blog
  • Linux Tutorials
    • Bash Scripting Lessons
    • Commands
    • Networking
    • Bash Scripts
  • Solutions
    • Docker
  • Network Tutorials
    • FortiGate
    • MikroTik
  • Projects
    • AdGuard
    • Immich
    • Nextcloud
    • WordPress
  • Cloud
  • Video Tutorials
    • YouTube Channel
    • MikroTik Videos
  • Web Tools
No Result
View All Result
  • Home
  • Blog
  • Linux Tutorials
    • Bash Scripting Lessons
    • Commands
    • Networking
    • Bash Scripts
  • Solutions
    • Docker
  • Network Tutorials
    • FortiGate
    • MikroTik
  • Projects
    • AdGuard
    • Immich
    • Nextcloud
    • WordPress
  • Cloud
  • Video Tutorials
    • YouTube Channel
    • MikroTik Videos
  • Web Tools
No Result
View All Result
DefenceDev
No Result
View All Result
ADVERTISEMENT
Home Solutions

Ubuntu: Running Commands in Background Using Terminal

neo by neo
September 11, 2025
in Solutions
0
Solutions: Run Command in Background on Ubuntu

Solutions: Run Command in Background on Ubuntu

0
SHARES
106
VIEWS
Share on FacebookShare on Twitter
Table of Contents
  • Run Command in Background
    • Using the nohup command
      • Example of Run Script in Background
      • Example of Run Command in Background
    • Monitor "nohup" Command

Run Command in Background

Running commands in the background on Ubuntu boosts productivity by allowing users to execute long processes without interrupting their work. Whether it’s running a script, processing data, or performing server maintenance, managing background tasks is essential. This article explores methods to run commands in the background, ensuring a smoother workflow. Let’s dive into the best solutions!

Using the nohup command

The nohup command in Ubuntu is used to run a command or a script in the background, even if the user logs out. The name “nohup” stands for “no hang up,” which refers to the practice of disconnecting a process from the terminal.

You can use the nohup command to run processes in the background without interrupting them, even if you close the terminal. By appending & to the command, you instruct the shell to execute it in the background, freeing up your terminal for other tasks.

Example of Run Script in Background

This command starts the script.sh file in the background. Using nohup ensures that the process continues running even after you log out. This method is useful when running long tasks or scripts and prevents them from being terminated when the session ends.

# Example how to execute the command
nohup ./script.sh &

This command runs script.sh in the background, just like before. However, it directs both standard output and error to the output.log file, instead of nohup.out. As the script executes, it writes all output to output.log, keeping the terminal clean. This approach is especially helpful when dealing with commands that generate a lot of output or for monitoring long-running processes.

# Lot output in the file
nohup ./script.sh > output.log &

Example of Run Command in Background

To run the ping command in the background and log its output to a file, you can use the following command:

nohup ping google.com > ping_output.log 2>&1 &
  • nohup: Ensures that the command keeps running after you log out or close the terminal.
  • ping google.com: Pings Google’s DNS server continuously.
  • > ping_output.log: Redirects standard output (stdout) to the ping_output.log file.
  • 2>&1: Redirects standard error (stderr) to the same file as standard output, so any error messages will also be logged.
  • &: Runs the command in the background.

Monitor “nohup” Command

The command ps aux | grep "script.sh" helps you search for a running process associated with a specific script or command:

ps aux | grep "script.sh"

defencedev.com

ADVERTISEMENT

ADVERTISEMENT

About The Author

neo

See author's posts

ADVERTISEMENT
Previous Post

WordPress: Change Port from 433 to 8443

Next Post

Solutions: Find and Delete Log Data or Any Files Older Than 30 Days on Linux

neo

neo

Related Posts

Automatic Windows Service Monitoring and Restart Script
Solutions

Automatic Windows Service Monitoring and Restart Script

Host a Website on Raspberry Pi – Real Benchmark Tests
Solutions

Host a Website on Raspberry Pi – Real Benchmark Tests

My Ultimate Docker Command Cheat Sheet (2025 Edition)
Docker

My Ultimate Docker Commands Cheat Sheet (2025 Edition)

Protect Docker-Hosted Application from HTTP Flood (DDoS) Attacks Using a Bash Script
Docker

Protect Docker-Hosted Application from HTTP Flood (DDoS) Attacks Using a Bash Script

Raspberry Pi Monitoring with Monit: Docker, Temperature, Network & More
Solutions

Raspberry Pi Monitoring with Monit: Docker, Temperature & More

Install WordPress on Raspberry Pi 4 with Docker (Ubuntu 22.04)
Docker

Install WordPress on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Next Post
Solutions: Find and Delete Log Data or Any Files Older Than 30 Days on Linux

Solutions: Find and Delete Log Data or Any Files Older Than 30 Days on Linux

Recommended

Fortinet FortiGate: Check the Routing Table in the CLI

Fortinet FortiGate: Check the Routing Table in the CLI

10+ Useful Linux find Command Examples You Should Know

10+ Useful Linux find Command Examples You Should Know

View & Copy Image Metadata Online – Camera & GPS Info

View & Copy Image Metadata Online – Camera & GPS Info

Online WebP to JPG Converter

Online WebP to JPG Converter

Image Metadata Remover – Clean EXIF and GPS Info Securely

Image Metadata Remover – Clean EXIF and GPS Info Online

Categories

  • Blog
  • Cloud
    • Private
  • Linux Tutorials
    • Bash Scripting Tutorials
    • Commands
    • Networking
  • Network Tutorials
    • FortiGate
    • MikroTik
  • Projects
    • AdGuard
    • Immich
    • Nextcloud
    • WordPress
  • Solutions
    • Docker
  • Video Tutorials
    • MikroTik Videos
  • Web Tools
ADVERTISEMENT

DefenceDev Tutorials

defencedev Logo

Whether you’re just starting or looking to expand your skills, I hope you find useful information and engaging discussions here. Let me take you through my journey and the goals behind this space!

Follow Us

Recent News

View & Copy Image Metadata Online – Camera & GPS Info

View & Copy Image Metadata Online – Camera & GPS Info

Online WebP to JPG Converter

Online WebP to JPG Converter

  • Site Map
  • Privacy Policy
  • Facebook Page
  • Disclaimer
  • Contact
  • About Me

© 2025 defencedev.com - All rights reserved.

No Result
View All Result
  • Home
  • Blog
  • Linux Tutorials
    • Bash Scripting Lessons
    • Commands
    • Networking
    • Bash Scripts
  • Solutions
    • Docker
  • Network Tutorials
    • FortiGate
    • MikroTik
  • Projects
    • AdGuard
    • Immich
    • Nextcloud
    • WordPress
  • Cloud
  • Video Tutorials
    • YouTube Channel
    • MikroTik Videos
  • Web Tools

© 2025 defencedev.com - All rights reserved.