• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

exec Command Examples in Linux

by admin

The exec command is used to execute another command, replacing the current shell process with this new program’s process (no new process is created). This can be useful when you want to prevent the user from returning to the parent process if an error is encountered. For example, you may want to terminate a privileged shell if a command fails.

You can also use the exec command without a command as an argument to redirect all output in the shell to a file. This is commonly used in scripts to suppress stdout at the CLI and instead send it only to one or more files. For example:

#!/bin/bash
exec > out.txt
pwd
ls -al

The current working directory and directory listing will output to out.txt and not the CLI.

exec Command Examples

1. Replace with the specified command using the current environment variables:

# exec command -with -flags

2. Replace with the specified command, clearing environment variables:

# exec -c command -with -flags

3. Replace with the specified command and login using the default shell:

# exec -l command -with -flags

4. Replace with the specified command and change the process name:

# exec -a process_name command -with -flags

Filed Under: Linux

Some more articles you might also be interested in …

  1. pivpn Command Examples in Linux
  2. CentOS / RHEL : How to find UUID of a device or filesystem
  3. CentOS / RHEL LVM : Backing Up Volume Group Metadata
  4. How to Ignore/Disable Specific auditd Logging Entries
  5. lpr Command Examples in Linux
  6. deluser: command not found
  7. 10pt loadable: Metric (TFM) file not found
  8. SSSD Service Failing with “SSSD is already running” in CentOS/RHEL 7
  9. tcpdump: command not found
  10. How to install and Configure VNC (TigerVNC) server in CentOS / RHEL 7

You May Also Like

Primary Sidebar

Recent Posts

  • protonvpn-cli Command Examples in Linux
  • protonvpn-cli connect Command Examples
  • procs Command Examples in Linux
  • prlimit: command not found

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright