Suspending in Bash: Quickly switch between running processes in bash

Suspending in Bash: Quickly switch between running processes in bash Thumbnail image

This is just a quick post, but if you've ever been doing something in the terminal, for example you were editing a file (vim somefile.txt), but you wanted to return back to the main command line, then you can do the following:

Press ctrl + z - this will suspend the current job (current process) - although sometimes, such as in Vim in insert mode, it won't always work. You should return to the main command line. Do whatever you want to do. Then to get back to that process type fg (for foreground).

To see all suspended processes, use the jobs command.

If you want to go back into a specific job then get it's ID (from the jobs command), and type fg 123, where 123 is that ID.

An alternative is to use screen (and it is always a good idea to use screen if you are connection is a bit dodgy and you're connecting via ssh to another server, so you can pick up where you left off if your connection dies.)

If you want to start a program and push it directly into the background, then you can do ./someScriptOrProgram.sh & (add a ampersand to the end of it).

Subscribe to my spam free newsletter for other Laravel updates like this

I never spam, and only email when I have a good in-depth post published on my site (mostly about Laravel). You can also follow me on social media to get updates.

webdevetc profile pic
webdevetc

I'm a late 20's web developer, specialising in Laravel, but work with other PHP frameworks and associated technologies (such as JS). I mostly write about PHP here. Contact me here. Need to hire or work with a contract PHP software developer in London, UK (or freelance)? Contact me and check my availability.

Leave a Comment