-->
Previous Table of Contents Next


To view the contents of a file, you can again use the more command. Just specify the name of the file you want to look at. In this case, type more output.


Warning:  
Be careful! When you use >, you completely overwrite the previous contents of the file from which you specify to take the output (if that file existed). For example, if we already have a file called output in our directory, its old contents will be completely replaced by the output from ls -l /bin. Linux will not warn you that you are about to do this!

Be particularly careful if you’re not in your usual directory or if you’re logged in as root. You could, for instance, accidentally clobber a Linux program by mistake. It’s a good idea to check whether the output file already exists before using >. In our example, we could have typed ls -l output beforehand. If no information is displayed, the file does not exist.


You can specify that you want to add your output to the end of the file, rather than replace the file’s contents, by using >>. Type who >> output to add the output of the who command to the end of the text already in the file output.

You can examine the results by using either more or less and paging through to the end of the file or by using the Linux command tail, which displays the last few lines of the specified file. In this case, type tail output to see the last few lines of the file output. Try using tail!

Notational Conventions Used to Describe Linux Commands

There is a set of accepted notational conventions used to describe, in a concise and consistent way, the correct syntax for any given Linux command. This specifies what options or parameters you must use, what options or parameters you can or cannot use, and so on. Sometimes this set of conventions is used to give a complete and exhaustive listing of a command’s syntax, showing every possible command and parameter. Sometimes it is used to make a particular example more general and the command’s basic usage clearer. You’ll run into these notations in manuals, man pages, and other sources of information.

If you remember the following five basic rules, you will be able, in principle, to understand the syntax of any Linux or UNIX command.

Six Basic Rules of Linux Notation

1.  Any text standing by itself, and not within [], <>, or {}, must be typed exactly as shown.
2.  Any text within square brackets ([]) is optional. You can type it or not type it. For instance, the syntax ls [-l] means you must type ls (per the first rule), while adding -l is optional but not necessary. Do not type the square brackets themselves! In our example, type ls or ls -l. Do not type ls [-l] .
3.  Angle brackets (<>) and the text within them must be replaced by appropriate text (usually a name or value). The text within the brackets usually indicates the nature of the replacement. For instance, the syntax more <filename> means that you should replace <filename> with the name of the file you want to examine using more. If you want to look at the file output, type more output. Remember, do not use the angle brackets when you actually type the command!
4.  Curly braces ({}) indicate that you must choose one of the values given within the braces. The values are separated by | (which in this case means or, not pipe!). For example, the syntax command -{a|b} means you must enter either command -a or command -b.
5.  An ellipsis () means “and so on.” They are normally used with parameters such as filenames, which is described later.
6.  The sixth basic rule states that the brackets can be combined as necessary. For instance, you don’t have to type a filename with the more command which would be indicated as more [<filename>]. The outer set of square brackets makes the entire parameter optional. If you do decide to use the parameter, replace the inner set of angle brackets with the appropriate value. Because the more command enables one or more filenames to be specified, the syntax becomes more [<filename> …]. The ellipsis means you can have as many <filenames> as you want, such as more output1 output2 output3.


Previous Table of Contents Next