• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Redirecting Output

Another useful UNIX command is redirection. Re-direction allows the users to store the output of a process to a file (output re-direction). Output Re-direction is a useful feature, that lets you store the output of a process into a file so that it may be used in some way later. For example, you're starting a program and receive an error message; however, it disappears before you can see it. By redirecting the output to a file you are able to view it at your leisure. Input Re-direction allows the user to prepare processes input ready for later use. Think of it this way, when you type the ls (list) command, the Terminal displays a listing of the files and folders in the working directory. When you use the redirect command, the list command can be redirected to another output such as a text file. The redirect command uses the greater than sign to perform the redirect. A single greater than sign (>) instructs UNIX to create a new file, while a double greater than sign (>>) creates a new file.

Redirect Output

Open the Applications folder, double-click the Utilities folder, and then double-click the Terminal icon.

To redirect the ls (list) command to create a file, type the following code on the command line, and then press Return.

ls > listing.txt

A file named listing.txt is created, and the ls (list) command is written to the file.

To redirect the ls (list) command to append the list onto an existing file, type the following code on the command line, and then press Return.

ls >> lists.txt

An existing file named lists.txt is used, and the ls (list) command is appended to the end of the file.

Click the Close button.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint