FreeKB - exec (execute a command)
Linux Commands - exec (execute a command)

The exec command can be used to execute a certain file. For example, to exectue the init file, to restart the system.

~]# exec /sbin/init


The exec command can be used to redirect all commands to a file. In this example, the exec command redirects commands to MyFile.

~]# exec > MyFile


After running the exec command, following commands will not produce any output. For example, the date command does not produce any output.

~]# date


This happens because the output of the date command was written to MyFile. Closing the shell, and then opening the shell again will allow you to view the contents of MyFile. The output of the date command will be in MyFile.

~]# cat MyFile
Fir Apr 14 18:37:07 CDT 2017


Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter 21bb1 in the box below so that we can be sure you are a human.