ECS 40
Name ___________________________________________________
ECS 40 HW #1 (28 points) Due at the beginning of class on January 22nd Winter 2016
1. What is the difference between a built-in command and a utility?
2. How can you make a script executable?
3. Write a UNIX command line to print out the first four lines of the C header files in the current directory.
4. Write a UNIX command line to print the 4th and 5th lines of the file test.cpp.
5. Write a UNIX command line to print the number of words in the file test.h.
6. Write a UNIX command line to sort the lines of poetry based on the second words in each line.
7. (4 points) Assume the following files are in the working directory. Write UNIX command lines using ls to accomplish
the following. For a), b), and d) you may not use the full names of any of the files.
$ ls
intro
notesa
notesb
ref1
ref2
ref3
section1
section2
section3
section4a
section4b
a. List the names of all files that begin with section.
b. List the names of the files section1, section2, and section3.
c. List the name of the intro file only.
d. List the names of only the files section1, section3, ref1, and ref3.
8. Write a UNIX command line to list all of the lines in the C++ files in the current directory that begin with “//”. C++
files end with “.cc”, “.cpp”, or “.h”.
9. Write a UNIX command line that will list the names of files in the current directory and its subdirectories that contain
the phrase #include stdio.h.
10. Write a UNIX command line that will archive the contents of the directories named 10, 40, and 110 into a file named
ECSf02.tar.Z that is also compressed by the compress utility.
11. What does the shell ordinarily do while a command is executing?
12. What should you do if you don’t want to wait for a command to finish before running another command?
13. What command line will redirect the standard output from the sort command into a file called phone_list? Assume the
input file is called numbers.
14. Describe two ways you can create a file called book that contains the contents of two other files, part1 and part2.
15. Rewrite the following sequence of commands using sort as a filter:
$ sort list > temp
$ lpr temp
$ rm temp
16. What is a PID number? Why are they useful when you run processes in the background?
17. Why don’t command names and file names usually have embedded spaces?
If you wanted to create a file name containing a space, how would do it?
18. Create a file called answers and give the following command: $ > answers.txt < answers cat Explain what the command does. What is the more traditional way of accomplishing the same thing? How can the shell recognize that cat is the command name (that is, argument zero) even though it does not come first on the command line? 19. Why can't the noclobber variable protect you from overwriting an existing file with cp or mv? 20. Under what circumstances would you use a symbolic link instead of a hard link? What are the drawbacks of using a symbolic link? 21. Write a UNIX command line that will display all of the lines, and their line numbers, that contain ECS 40 in the C++ files in the current directory. Note that all C++ files end with .cpp. 22. (2 points) Write a UNIX command line that will print the number of processes that root has running on this machine. This uses pipes and is tricky. Test your answer! 23. (2 points) Write a UNIX command line that will list the lines and the names of the files in the current directory and its subdirectories that contain the phrase Author Adam Drozdek