Gentoo Wiki


Warning: If there are files in /etc that need updating, powering the computer off right after the emerge (without updating them) may result in serious problems upon the next boot! Take special care about sys-apps/baselayout, as it (sometimes) changes crucial init scripts!


Basic Idea

To powerdown your computer after emerge completes type

emerge PACKAGE && poweroff

(Replace PACKAGE with the name of package to compile and poweroff with any command you want to execute after emerge completes)

With KDE

If you are using KDE, it may be a good idea to have kde logout first before the shutdown process begins. To do this, type:

 emerge PACKAGE && kdeinit_shutdown && poweroff

Emerge Is Already Running

One way

If emerge is already running, hit ctrl-z. The process will be paused

[1]+  Stopped                 emerge kdebase-meta

Now type

bg && wait && poweroff

bg resumes executing of emerge in the background.

wait waits for last command sent to background to terminate. When emerge finishes with success poweroff command will be executed.

Another Way

You can accomplish the same thing by pausing the process with ctrl-z as described above and then typing this:

 fg; poweroff


 fg && poweroff

This continues the paused process and after this process finishes it continues the next command (poweroff) ...

It is important to notice that '&&' will only continue with the next command, if the first command completed successfully. && is the logical AND operator of the shell. By using ';' the next command will be executed no matter what happend earlier. ';' is only a command seperator.

A variant of this can be used to play a sound when emerge is done.

 fg; aplay whateversoundfile

The fg variant is a little more straight forward probably.

Countdown Until Poweroff

If you want to have a chance to stop the shutdown add sleep command

 bg && wait && sleep 60 && poweroff

Computer wil be shut after one minute unless you hit ctrl-c.

Or you may want to use shutdown:

 bg && wait && shutdown -h +1

This will notify all logged-in users that the system is going down, and halt your computer one minute (in this case) after your emerge process finished, unless you call

 shutdown -c

Remote compiling and shutdown

Maybe you want to compile some application remotely and then shutdown/reboot. If you are connected to a remote computer, you can simply run:

nohup /bin/bash -c "emerge kdebase-meta && poweroff" &

After that, you can disconnect and the compilation process will continue in the background. All output will be redirected to file nohup.out. If the file nohup.out cannot be created in the current directory, it will use $HOME/nohup.out.

You can also redirect output to a different file:

nohup /bin/bash -c "emerge kdebase-meta && poweroff" > compilation.log &

An alternative to nohup is to use the screen command.

Retrieved from ""

Last modified: Thu, 21 Aug 2008 03:47:00 +0000 Hits: 15,010