Section 3.13. Creating a File


[Page 54 (continued)]

3.13. Creating a File

I already had an idea of what the first draft of my song's lyrics would look like, so I decided to store them in a file called "heart." Ordinarily, I would use a Linux editor such as vim or emacs to create the file, but this is a beginner's chapter, so I used a simpler utility called cat to achieve the same result. Figure 3-13 describes how cat works.

Figure 3-13. Description of the cat command.

Utility: cat -n { fileName }*

The cat utility takes its input from standard input or from a list of files and displays them to standard output. The -n option adds line numbers to the output. cat is short for "concatenate," which means "to connect in a series of links."


By default, the standard input of a process is the keyboard and the standard output is the screen. We can send the standard output of a process to a file instead of the screen by making use of a shell facility called output redirection. If you follow a command by a > character and the name of a file, the output from the command is saved to the file. If the file doesn't already exist, it is created; otherwise, its previous contents are overwritten. Right now, use this feature without worrying how it works; Chapter 5, "The Linux Shells," explains it all in detail. To create the first draft of my lyrics, I entered the following text at the shell prompt:


[Page 55]

$ cat > heart    ...store keyboard input a the file 'heart'. I hear her breathing, I'm surrounded by the sound. Floating in this secret place, I never shall be found. ^D  ...tell cat that the end-of-input has been reached. $ _ 





Linux for Programmers and Users
Linux for Programmers and Users
ISBN: 0131857487
EAN: 2147483647
Year: 2007
Pages: 339

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