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

Solutions: Run Command in Background on Ubuntu

neo by neo
May 27, 2025
in Solutions
0
Solutions: Run Command in Background on Ubuntu

Solutions: Run Command in Background on Ubuntu

0
SHARES
83
VIEWS
Share on FacebookShare on Twitter
ADVERTISEMENT

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.

ADVERTISEMENT

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:

ADVERTISEMENT
ADVERTISEMENT
ps aux | grep "script.sh"

defencedev.com

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

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

Follow Us

  • Trending
  • Comments
  • Latest
MikroTik: Export Configuration in Text File

MikroTik: Export Configuration in Text File

Fortinet FortiGate: Static Route Configuration via GUI and CLI

Fortinet FortiGate: Static Route Configuration via GUI and CLI

Immich: Installation on Ubuntu 22.04

Immich: Installation on Ubuntu 22.04

Fortinet FortiGate Upgrade Path Tool

Fortinet FortiGate Upgrade Path Tool

NextCloud: Port Forwarding - Essential Ports for Smooth Functionality

NextCloud: Port Forwarding – Essential Ports for Smooth Functionality and Remote Access

Organizing and Managing Photos with Immich: Features I Use

Organizing and Managing Photos with Immich: Features I Use

Install Ubuntu 22.04 on Oracle VM Virtual Box

Install Ubuntu 22.04 on Oracle VM Virtual Box

Linux Directories: cd (Change Directory), pwd (Print Working Directory), mkdir (Make Directory)

Linux Directories: cd (Change Directory), pwd (Print Working Directory), mkdir (Make Directory)

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

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

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

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

Install Nginx Proxy Manager on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nginx Proxy Manager on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Docker on Raspberry Pi 4 with Ubuntu 22.04

Install Docker on Raspberry Pi 4 with Ubuntu 22.04

Recent News

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

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

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

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

Install Nginx Proxy Manager on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nginx Proxy Manager on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Docker on Raspberry Pi 4 with Ubuntu 22.04

Install Docker on Raspberry Pi 4 with Ubuntu 22.04

MikroTik: Check Your Wireless Password

MikroTik: Check Your Wireless Password

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

Browse by Category

  • 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

Recent News

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

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

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

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

  • 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
  • Solutions
    • Docker
  • Network Tutorials
    • FortiGate
    • MikroTik
  • Projects
    • AdGuard
    • Immich
    • Nextcloud
    • WordPress
  • Cloud
  • Video Tutorials
    • YouTube Channel
    • MikroTik Videos

© 2025 defencedev.com - All rights reserved.