Terminal Tip: Close windows after clean exit
A quick setting change may help reduce window clutter for OS X Terminal users.
If you regularly script tasks in the Terminal, you might find at times that handling windows can be a burden. While an unused Terminal window can quickly be closed by pressing Command-W or clicking the red button at the top of the window, if you run numerous scripts then you may be left with a number of windows to close.
One way you can better manage these windows is to change the default Terminal behavior for when a terminal shell exits. By default, the Terminal will keep the window open and display the text "[process completed]," leaving you with a nonfunctional window that you have to close manually. However, if you change this behavior you can run commands and scripts in ways that will close the window when done.
To do this, go to the Terminal's preferences, then to the Settings section, and select the "Shell" tab. Then, change the shell exiting behavior to "Close the window" or preferably to "Close if the shell exited cleanly."
With this setting in place, if the shell exits, then the window will close as well. This way, you can run commands or scripts and when the script or command is finished then the terminal window will close. For example, if you want to run the command "top" to get a view of the system resources being used, then you can do so by running the following command:
With this command, the "top" program will run and show you the system's process list, but when you quit "top," the shell will then exit and the window will immediately close. You can similarly apply "; exit" to the end of any script you run to close the shell and Terminal window when finished.
You can also manually close windows by simply typing "exit," instead of pressing Command-W, which may be slightly easier or simply just an alternative to use in some contexts.