The nohup Command: Keep Your Processes Running in the Background

The nohup command, short for “no hang up,” is a useful tool in Unix-like systems that allows you to run commands or scripts in the background, even if you log out or close the terminal. This is especially helpful for long-running tasks that need to continue after you disconnect.

How to Use nohup

Here are some common scenarios where nohup is beneficial:

# 1. Oracle Data Pump Export (expdp)
nohup expdp '"/ as sysdba"' DIRECTORY=dump_dir DUMPFILE=export.dmp LOGFILE=export.log &

# 2. Oracle Data Pump Import (impdp)
nohup impdp '"/ as sysdba"' DIRECTORY=dump_dir DUMPFILE=import.dmp LOGFILE=import.log &

# 3. Zipping Files
nohup zip -r archive.zip /path/to/directory > zip.log 2>&1 &

# 4. Running a Shell Script (.sh)
nohup bash script.sh > script.log 2>&1 &

Key Points to Remember

  • &: Runs the command in the background, allowing you to use the terminal for other tasks.
  • > file.log 2>&1: Redirects both standard output and error messages to file.log, capturing all output.
  • nohup.out: If no output redirection is specified, the output is saved to the default nohup.out file.

Why Use nohup?

Using nohup ensures that processes continue running even after you disconnect from the terminal. It’s an essential tool for system administrators and developers handling long-running tasks, providing a reliable way to execute background jobs without constant monitoring.

You might like

Leave a Reply

Your email address will not be published. Required fields are marked *