CS 497C - Homework 3 - Name:_________________ DUE: Wednesday, October 10 (in class) Please show all work on a separate sheet attached to this sheet. (50 points - 5 points for each problem) 1. How do you change the contents of the current line completely in vi? How are d and y different from the Command Mode commands in vi? Ans: 1) Use S or cc. enter the new text and then press [Esc]. 2) They are operators and are used in combination with other commands. 2. How do you noniteractively and globally replace Basic with Java in all lines of a file in vi? How do you delete text from the current line to the beginning of the file? Ans: 1) Use :1,$s/Basic/Java/g. 2) Use d1G. 3. Name three ways of quitting vi and saving the file. Ans: Use the commands :x, :wq or ZZ to save and quit the editor. 4. What does the U command in vi do? When will it fail to work? Ans: U undoes all changes made to the current line since the cursor was moved to the line. This command won't work when the cursor is moved away from the line. 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) Sure, it will; mv can also rename directories. If bar2 exists, then bar1 becomes a subdirectory of bar2. 6. Discuss three ways of knowing your home directory. Ans: 1) Use cd; pwd 2) Use echo $HOME 3) Locate it in the line pertaining to your username in /etc/passwd. 4) Use finger username. 7. When will you be compelled to run a command like this - ./update.sh instead of update.sh? Ans: You need to use ./ before a command name when there is a command of this name in the directories specified in PATH. Preceding a command with ./ ignore PATH totally and executes the command that resides in the current directory. 8. Which commands do you use for printing, removing printing jobs, and checking the number of the printing job in Linux systems which we use in the Computer Science Department? Ans: Use lpr filename to print. Use lprm to remove a job. Use lpq to check the number of the job. 9. How do the df and du commands differ? How do you find out the total disk usage of the current directory tree? Ans: 1) df tells you the free space in the file system, while du shows the consumption of a file or a directory structure. 2) Use the command du -s . to output a single figure containing the number of blocks used by the current directory tree. 10. You have a complete directory structure to send to someone. Which command will you use to archive and compress the directory trees? Ans: Either one of the following ways is working: 1) The zip command can archive directory trees. Use "zip -r dir.zip dir" to archive the directory structure dir before sending it. 2) A directory can also be archived with tar and then compressed with compress or gzip. 3) In Linux, you can use "tar zcvf dir.tar.gz dir".