Multi-tasking from the Unix shell (vim and mysql cli users, crowd around)

So, you are venturing into the cool crowd by playing with vim.  You are a developer that is used to GUI editors and are not really a shell kind of guy/girl.  Or, maybe you have been using vim for a while and are just used to closing out a file before moving onto the next one.
Having a background in Linux due to my past experience as a Sr. Oracle DBA in Linux environments, I became a Linux command line guru fast.  Using vim as a text editor is very powerful, but what would be even more powerful is being able to switch from file to file quickly and easily.  Below, I’m going to give a visual how-to on multi-tasking in a Unix Shell environment.

Typically developers have 2 things open while working.  Loads of files and mysql.
First step, let’s open up a file in vim.  (vim app/controllers/contact_controller.php)
After it is open hit “Ctrl + z” on your keyboard.  This will throw the process in the background

From here, let’s open up mysql (mysql -u user -p) and once we have logged in and gotten to the CLI, let’s hit “Ctrl + z” and throw that process in the the background

You will notice the numbers before the processes (1 & 2).  So, now we have these processes in the background.   Now what?  Ok, so let’s first learn how we can actually see what we have already placed in the background.  From the command line, type “jobs” and hit enter.

So, “jobs” gives you a list of background processes.  In this case processes 1 and 2.  So, now we need to know how to access those processes so we can continue what we were doing.   Type “fg ”  (ie. fg 2)  and press enter.

Isn’t this fun.  Just think about when you get used to it, it will be just as fast, if not faster then “Alt + Tab”.  From here you can run as many processes as you want.  Just follow all of the steps…Ctrl + z to throw a process into the background and fg to get back in.  Simple as that.
I think you will find multi-tasking in Unix is a very simple and productive thing.
Share This