Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 30 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
30
Dung lượng
1,71 MB
Nội dung
Exercises 1: What does the shell ordinarily do while a command is executing? What should you do if you do not want to wait for a command to finish before running another command? 2: Using sort as a filter, rewrite the following sequence of commands: $ sort list > temp $ lpr temp $ rm temp 3: What is a PID number? Why are these numbers useful when you run processes in the background? Which utility displays the PID numbers of the commands you are running? 4: Assume that the following files are in the working directory: $ ls intro notesb ref2 section1 section3 section4b notesa ref1 ref3 section2 section4a sentrev Give commands for each of the following, using wildcards to express filenames with as few characters as possible. a. a. List all files that begin with section. b. b. List the section1, section2, and section3 files only. c. c. List the intro file only. d. d. List the section1, section3, ref1, and ref3 files. 5: Refer to the documentation of utilities in Part V or the man pages to determine which commands will a. a. Output the number of lines in the standard input that contain the word a or A. b. b. Output only the names of the files in the working directory that contain the pattern $(. c. c. List the files in the working directory in their reverse alphabetical order. d. d. Send a list of files in the working directory to the printer, sorted by size. 6: Give a command to a. a. Redirect the standard output from a sort command into a file named phone_list. Assume that the input file is named numbers. b. b. Translate all occurrences of the characters [ and { to the character (, and all occurrences of the characters ] and } to the character ) in the file permdemos.c. (Hint: Refer to tr on page 804.) c. c. Create a file named book that contains the contents of two other files: part1 and part2. 7: The lpr and sort utilities accept input either from a file named on the command line or from standard input. a. a. Name two other utilities that function in a similar manner. b. b. Name a utility that accepts its input only from standard input. 8: Give an example of a command that uses grep a. a. With both input and output redirected. b. b. With only input redirected. c. c. With only output redirected. d. d. Within a pipe. In which of the preceding is grep used as a filter? 9: Explain the following error message. What filenames would a subsequent ls display? $ ls abc abd abe abf abg abh $ rm abc ab* rm: cannot remove 'abc': No such file or directory Page 151 ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html < Day Day Up > Page 152 ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html < Day Day Up > Advanced Exercises 10. When you use the redirect output symbol (>) with a command, the shell creates the output file immediately, before the command is executed. Demonstrate that this is true. 11. In experimenting with shell variables, Alex accidentally deletes his PATH variable. He decides that he does not need the PATH variable. Discuss some of the problems he may soon encounter and explain the reasons for these problems. How could he easily return PATH to its original value? 12. Assume that your permissions allow you to write to a file but not to delete it. a. a. Give a command to empty the file without invoking an editor. b. b. Explain how you might have permission to modify a file that you cannot delete. 13. If you accidentally create a filename that contains a nonprinting character, such as a CONTROL character, how can you rename the file? 14. Why does the noclobber variable not protect you from overwriting an existing file with cp or mv? 15. Why do command names and filenames usually not have embedded SPACEs? How would you create a filename containing a SPACE? How would you remove it? (This is a thought exercise, not recommended practice. If you want to experiment, create and work in a directory that contains only your experimental file.) 16. Create a file named answer and give the following command: $ > answers.0102 < answers cat Explain what the command does and why. What is a more conventional way of expressing this command? < Day Day Up > Page 153 ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html Page 154 ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html < Day Day Up > Part II: The Editors CHAPTER 6 THE vim EDITOR CHAPTER 7 THE emacs EDITOR < Day Day Up > Page 155 ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html < Day Day Up > Chapter 6. The vim Editor IN THIS CHAPTER Tutorial: Creating and Editing a File with vim 141 Introduction to vim Features 148 Online Help 149 Command Mode: Moving the Cursor 154 Input Mode 158 Command Mode: Deleting and Changing Text 160 Searching and Substituting 164 Yank, Put, and Delete Commands 171 The General-Purpose Buffer 171 Reading and Writing Files 174 The .vimrc Startup File 176 This chapter begins with a history and description of vi, the original, powerful, sometimes cryptic, interactive, visually oriented text editor. The chapter continues with a tutorial that explains how to use vim (vi improved—a vi clone supplied with or available for most Linux distributions) to create and edit a file. Much of the tutorial and the balance of the chapter apply to vi and other vi clones. Following the tutorial, the chapter delves into the details of many vim commands and explains how to use parameters to customize vim to meet your needs. It concludes with a quick reference/summary of vim commands. The vim home page is www.vim.org. < Day Day Up > Page 156 ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html < Day Day Up > Page 157 ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html History Before vi was developed, the standard UNIX system editor was ed (still available on most Linux systems), a line-oriented editor that made it difficult to see the context of your editing. Next came ex,[1] a superset of ed. The most notable advantage that ex has over ed is a display-editing facility that allows you to work with a full screen of text instead of just a line. While using ex, you can bring up the display-editing facility by giving a vi (Visual mode) command. People used this display-editing facility so extensively that the developers of ex made it possible to start the editor with the display-editing facility already running, without having to start ex and then give a vi command. Appropriately they named the program vi. You can call the Visual mode from ex, and you can go back to ex while you are using vi. Start by running ex; give a vi command to switch to Visual mode, and give a Q command while in Visual mode to use ex. Give a quit command to exit from ex. [1] The ex program is usually a link to vi, which is a version of vim on some systems. vi clones Linux offers a number of versions, or clones, of vi. The most popular vi clones found on Linux are elvis ( elvis.the-little-red-haired-girl.org), nvi (an implementation of the original vi editor, www.bostic.com/vi), vile (dickey.his.com/vile/vile.html), and vim (www.vim.org). Each clone offers additional features beyond those provided with the original vi. The examples in this book are based on vim. Several Linux distributions support multiple versions of vim. For example, Red Hat provides /bin/vi, a minimal build of vim that is compact and faster to load but offers fewer features, and /usr/bin/vim, a full-featured version of vim. If you use one of the clones other than vim, or vi itself, you may notice slight differences from the examples presented in this chapter. The vim editor is compatible with almost all vi commands and runs on many platforms, including Windows, Macintosh, OS/2, UNIX, and Linux. Refer to the vim home page ( www.vim.org) for more information and a very useful Tips section. What vim is not The vim editor is not a text formatting program. It does not justify margins or provide the output formatting features of a sophisticated word processing system such as OpenOffice.org Writer. Rather, vim is a sophisticated text editor meant to be used to write code (C, HTML, Java, and so on), short notes, and input to a text formatting system, such as groff or TRoff. You can use fmt (page 664) to do minimal formatting on a text file that you create with vim. Reading this chapter Because vim is so large and powerful, this chapter describes only some of its features. Nonetheless, if vim is completely new to you, you may find even this limited set of commands overwhelming. The vim editor provides a variety of ways to accomplish any specified editing task. A useful strategy for learning vim is to begin by learning a subset of commands to accomplish basic editing tasks. Then, as you become more comfortable with the editor, you can learn other commands that enable you to do things more quickly and efficiently. The following tutorial section introduces a basic but useful set of vim commands and features that create and edit a file. < Day Day Up > Page 158 ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html Page 159 ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html < Day Day Up > Page 160 ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html . which is a version of vim on some systems. vi clones Linux offers a number of versions, or clones, of vi. The most popular vi clones found on Linux are elvis ( elvis.the-little-red-haired-girl.org),. http://www.processtext.com/abcchm.html History Before vi was developed, the standard UNIX system editor was ed (still available on most Linux systems), a line-oriented editor that made it difficult to see the context of your editing tutorial that explains how to use vim (vi improved—a vi clone supplied with or available for most Linux distributions) to create and edit a file. Much of the tutorial and the balance of the chapter