4

Say you're in a directory and you want to check something in another directory, so you type bash to spawn a new shell so you can cd and check that thing and then type exit to get out and go back to the original shell still in that old directory.

Is there any way to keep both bashes running and switch between the two, sort of like Ctrl+Z + fg/bg?

3

You can use the suspend command to background the child shell and return to the parent shell.

  • suspend & fg & bg will do, but they don't support interactive or ncurses-like processes. – 0xSheepdog Mar 26 '14 at 19:04
  • 1
    @0xSheepdog, you can suspend an interactive ncurses based program just fine. – psusi Mar 26 '14 at 19:49
2

There are several ways to do this:

  1. If you are behind the physical console, just switch to a different TTY.
  2. If you are not behind the console and you are using a graphical interface, just start a new xterm.
  3. If you are SSH-d in or do not like either of the first two, you can:
    • Start screen (old, spaghetti code, but well tested).
    • Start TMUX (A modern screen-like replacement)
    • If the original program does not need input, suspend it (e.g. Controlz) and then tell it to continue running in the background (bg). If you wish you can switch between tasks by suspending the current one and bringing the desired task to the foreground (fg). E.g. use jobs and fg %1, fg %2, ...).
0

Yes, the app/command you should look into is screen. It will let you detach a shell session which continues to execute on its own.

http://www.howtoforge.com/linux_screen

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.