In terminal I just type firefox
and then Firefox starts, but I can not return to
command mode anymore.
How can I come back to command mode?
I have already tried :q
or exit
, but neither work.
In terminal I just type firefox
and then Firefox starts, but I can not return to
command mode anymore.
How can I come back to command mode?
I have already tried :q
or exit
, but neither work.
When you run a program from a shell (e.g. firefox
) it will be executed "in foreground". When the program will finish you will have back the possibility to execute another command.
Another way to execute a command is "in background". If you put this symbol &
after the command it will be executed asynchronously (in background) and you will have the possibility to execute other commands from the same shell/terminal. Excerpt from man bash
:
When bash starts a job asynchronously (in the background), it prints a line
that looks like:
[1] 25647
indicating that this job is job number 1 and that the process ID of the
last process in the pipeline associated with this job is 25647.
When you start the second jobs it will answer with [2] NewPid
and so on. With the built-in command jobs
you will have all the list.
When you run a command "in foreground" and you want to suspend it (not to stop definitively) you can press CTRL+Z. The shell will answer you in a similar way (e.g.)
[1]+ Stopped firefox
To continue the precedent job you can write %1 &
(the same number you read from the terminal). You can also do it with bg %1
. It will execute the job 1 in background and give you the prompt back, ready to accept new commands.
You may find interesting the article Linux: Start Command In Background
cabal
to first update
then after it finishes I want it to install package x
.
– Owen
Dec 29 '21 at 06:36
apt
, you can always do something like apt update && apt install PackageX
where you execute the 1st command (here not in background) and then the second command (apt install PackageX) only if the 1st one exits without errors (&&
). To be honest for your example it should be enough ;
, but it is better to install only if the update went ok (then &&
).
– Hastur
Dec 29 '21 at 10:41
command mode
, you mean the interactive shell, then no. You have runfirefox
in such a way so that the terminal will show its output. You can press^C
to sendSIGINT
tofirefox
. Doing so will get you back to the interactive shell, but it will killfirefox
. Instead, you can runfirefox
in the background (à lafirefox &
), and you should already be back to the interactive shell once the process has forked off. – HalosGhost Jul 18 '14 at 21:27firefox &
is the right way. If you forget it you can do CRTL-Z to suspend it and after%1 &
to execute it in background. – Hastur Jul 18 '14 at 21:54