Additional Features of the Terminal Application


You've already gained some experience with the Terminal application, which allows you to access the command line from the Linux desktop. Before we proceed with the other topics in this chapter, there are a few extra tips about the Terminal application that you might find useful.

Using Multiple Tabs in the Terminal Application

You might remember that while you're using the command line at the console, multiple virtual consoles are provided so that you can enjoy the benefits of running many command-line applications at once. You can enjoy similar benefits by launching multiple instances of the terminal application at once or by creating multiple tabs inside the terminal application, each of which contains a command line of its own. You can open a new command line in a new tab by choosing File, New Tab, Default. A terminal window with three running command prompts, each in its own tab, is shown in Figure 26.1.

Figure 26.1. The terminal application with three running command prompts, each in its own tab.


In the KDE's terminal application, you can open a new tab by choosing Session, New Shell.

The command lines in each tab are completely autonomous; each has its own current working directory and its own list of jobs, and all can be busy simultaneously if you run particularly involved commands that take some time to complete.

To close a tab and exit the command line (shell) that is running in it, click the tab to make it active and enter the word exit at the command line. The tab disappears.

Launching Desktop Applications with the Terminal

Launching desktop applications from the command line in a terminal window is both possible and common. Although the menus and icons on the menubar are usually more convenient ways to launch desktop applications, sometimes being able to type the name of an application at the command line to start it is usefulfor example, if you want to be able to supply a command-line argument, as you'll shortly see.

To use the command line to launch an application whose name you already know, enter its name at the command line. For example, recall the gedit text editor that you learned to use in Chapter 5, "Working with Files on the Desktop." To launch gedit from a terminal window, enter gedit at the command prompt:

 [you@workstation20 ~]$ gedit 

In fact, you can also supply the name of the file you want to edit as an argument to the command, as is the case with command-line editors such as emacs and vi. For example, to load the file myfile.tex into the gedit text editor, type gedit followed by the name of the file you want to load into the editor:

 [you@workstation20 ~]$ gedit myfile.tex 

Entering a command like this one causes the gedit editor to start and load the file you have supplied as an argument. If the file does not already exist, gedit opens with an empty file using the name you supplied, as shown in Figure 26.2.

Figure 26.2. The gedit editor was launched at the command line in the terminal window; myfile.tex was given as an argument.


Although a list of the number of applications that can be started from the command line is beyond the scope of a book like this one (there are hundreds, even thousands of them), you can explore Linux desktop applications yourself from the command line by getting directory listings (using ls) of many of the desktop application commands in the following paths:

  • /usr/X11R6/bin

  • /usr/bin/g*

  • /usr/bin/k*

Note that not all the commands in these listings are desktop applications; many, however, are. Note also that any desktop application you start via a menu can also be started via the command line if you know the name of the application in the file system. One way to find this information is to use the process list (like the one generated by the ps command) discussed in Chapters 28, "Command-Line System Administration," and , "Desktop System Administration."

Using Job Control Techniques at the Terminal Command Line

You might notice that as you start application windows like gedit using the command line in this way, you are unable to enter further commands in the terminal window. The reason is that gedit acts as the foreground job in the terminal window. Only after you exit gedit does the command prompt return.

Did You Forget Some Command-Line Techniques?

For a command-line refresher, including such concepts as foreground jobs and background jobs, return to Chapter 5, "Working with Files on the Desktop," Chapter 19, "Performing Basic Shell Tasks," and Chapter 20, "Creating, Editing, and Saving Text Files."


In fact, you can start an application like gedit in the background, so that you instantly have access to the command line again when gedit starts, by appending the ampersand (&) to the end of the command:

 [you@workstation20 ~]$ gedit myfile.tex & [1] 9779 [you@workstation20 ~]$ 

Calling gedit as a background job this way instantly displays a job number (in this case, 1) and a process id number (in this case, 9779) and then returns you to the command prompt. Although the gedit window opens and you can edit myfile.tex, you also have access to the command line in the terminal window because gedit is running in the background.

All the command-line job control techniques that you learned in "Keeping Your Shell Programs Under Control" in Chapter 20, "Creating, Editing, and Saving Text Files," can be used from a command line in a terminal window as well, including the following:

  • The Ctrl+Z keystroke in the terminal window from which the application was started to suspend the foreground job and restore the command prompt

  • The bg and fg commands in the terminal window from which the application window was started to move existing jobs to the foreground or background

  • The kill command in the terminal window to end a running job

  • The ampersand (&) at the end of a command to start the command in the background, keeping the command prompt available for additional work while the command you have called runs and finishes

The only difference between job control at the command line in a terminal window and job control at a console command line is that in a terminal window, many of your running jobs can be application windows, meaning that you can interact with them even while they are in the background by clicking your mouse pointer within their borders.

Using nohup to Keep Jobs Running

If you start a number of jobs in a terminal window and then close the window or exit the shell, all the jobs in that shell exit as well. This can be an undesired side effect. Often when you start a desktop application in the background, you want the desktop application to remain even if the shell where it was started exits.

Using the nohup command, you can indicate that a command should not exit if the shell in which it was started exits or is closed. For example, to launch a gedit window in the background, which remains open even if you close the terminal window used to start it, enter the following:

 [you@workstation20 ~]$ nohup gedit & 

When you use nohup, a file called nohup.out is created in your home directory. This plaintext file displays any error messages or warnings that the application normally displays to the terminal window from which it was started. You can safely delete this file after your applications have been closed.

Accessing Desktop Files from the Command Line

Because some users find themselves storing or copying the documents they often work with to the actual desktop, it is helpful to know how to access those files using the command line as well. Specifically, it is important to know the path to files that are stored on the desktop.

Files on the desktop are stored in ~/Desktop. For example, to create an empty file called emptyfile.txt on your desktop using the touch command you learned in Chapter 6, "Working with Files in the Shell," enter the following at a command line:

 [you@workstation20 ~]$ touch ~/Desktop/emptyfile.txt [you@workstation20 ~]$ 

Entering this command creates a file called emptyfile.txt on your desktop, as shown in Figure 26.3.

Figure 26.3. The touch command entered in the terminal window created emptyfile.txt on the desktop.


Files and directories that are stored on the desktop can be accessed using any of the command-line file management techniques you learned in earlier chapters.



    SAMS Teach Yourself Red Hat(r) Fedora(tm) 4 Linux(r) All in One
    Cisco ASA and PIX Firewall Handbook
    ISBN: N/A
    EAN: 2147483647
    Year: 2006
    Pages: 311
    Authors: David Hucaby

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net