CS 497C - Homework 4 - Name:_________________ DUE: Monday, October 22 (in class) Please show all work on a separate sheet attached to this sheet. (50 points - 5 points for each problem) + (5 bonus points) 1. How do you save a file using the same name in emacs? How do you save a file using a different name in emacs? How can you quit emacs? How can you recover an auto-saved file in the event of a system crash in emacs? Ans: 1) [Ctrl-x][Ctrl-s] 2) [Ctrl-x][Ctrl-w] 3) [Ctrl-x][Ctrl-c] 4) [Alt-x]recover-file[Enter], then enter the filename to be recover. 2. How do you delete 10 lines in emacs? How do you undo and redo the editing with the same key in emacs? Ans: 1) [Alt-10][Ctrl-k] or [Esc]10[Ctrl-k] or [Ctrl-u]10[Ctrl-k] 2) [Ctrl--] or [Ctrl-_] or [Ctrl-x]u. 3. How do you mark a region, copy it, and put it in the new location in emacs? How do you delete text from the current line to the beginning of the file in emacs? Ans: 1) Mark the beginning of the region by [Ctrl-Spacebar] or [Ctrl-@] and move the cursor to the end of the region. Copy it by [Alt-w]. Put it by [Ctrl-y]. 2) Use [Ctrl-Spacebar] or [Ctrl-@] to mark the current line, move to the beginning of the file with [Alt-<] and then use [Ctrl-w] to delete it. 4. How do you non-interactively and globally replace Basic with Java in emacs? How can you edit a second file without leaving emacs and then toggle between two files? Ans: 1) Type [Alt-x]replace-string[Enter]. Then enter Basic at the first prompt and Java at the second. 2) Use [Ctrl-x][Ctrl-f] to read the second file and use [Ctrl-x]b to toggle between two files; Or use [Ctrl-x]2 to open a second window, use [Ctrl-x][Ctrl-f] to open the second file, and use [Ctrl-x]o to switch between the windows. 5. Can you create a file whose filename is . or ..? Will mv bar1 bar2 work if bar1 and bar2 are directories? Give both questions a short explanation. Ans: 1) No, . represents the current directory and .. represents the parent directory. 2) Yes, it will; mv can also rename directories. If bar2 exists, then bar1 becomes a subdirectory of bar2. 6. How can you show a complete listing of all files, directories, and those files and directories under these directories in your home directory? How will you list the files of the parent directory? Ans: 1) Use ls -R or ls -aR or ls -lR 2) Use ls .. or ls -a .. or ls -l .. 7. Show two ways to assign the read and write permission to the owner and the read permission to the group and others. Ans: 1) chmod u=rw,go=r file 2) chmod 644 file 8. Which file attributes change when you copy a file from another user account? Ans: 1) The file's owner changes to the user who copys this file. 2) Last modification and access time changes to the time of copy. 3) If the two users are in different groups, the file's group changes. 4) File permissions change to the default permission of the user who copy this file. 9. What are the two main disadvantages of the hard link? How do you overcome these problems? Ans: 1) A hard link can't (a) link files in two file systems (b) link directories. 2) Use symbolic link to overcome these problems. 10. Use the find command to move all files with the html extension (i.e. *.html) from the current directory to the htdocs directory under the parent directory? Ans: find . -name "*.html" -exec mv {} ../htdocs \; 11. Change your current directory to /dev and use ls -Fax. You'll see some files ending with = and |. What are those files? (5 Bonus Points) Ans: The files ending with = are AF_UNIX address family sockets. The files ending with | are FIFO files.