Top-Rated Free Essay
Preview

Hw3 7

Powerful Essays
1263 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Hw3 7
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?
The shell waits for the command to finish executing. You can send the command to the background by using "&". 2.
2. Using sort as a filter, rewrite the following sequence of commands:
$ sort list > temp
$ lpr temp
$ rm temp
$ cat list | sort | lpr
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?
A PID number is an identification number assigned to a command running in the background, which can be used to differentiate between commands. The PS (process status) utility
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.
$ ls section*
b. List the section1, section2, and section3 files only. $ ls section[1-3]
c. List the intro file only. $ ls i*
d. List the section1, section3, ref1, and ref3 files.
a. List all files that begin with section.
$ ls section*
b. List the section1, section2, and section3 files only.
$ ls section[1-3]
c. List the intro file only.
$ ls i*
d. List the section1, section3, ref1, and ref3 files.
$ ls *[13]
5. Refer to the info or man pages to determine which command will
a. Display the number of lines in the standard input that contain the word a or A.
b. Display only the names of the files in the working directory that contain the pattern $(.
c. List the files in the working directory in reverse alphabetical order.
d. Send a list of files in the working directory to the printer, sorted by size.
6. Give a command to
a. Redirect standard output from a sort command to a file named phone_list. Assume the input file is named numbers.
$ sort numbers > phone_list
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 the tr man page.)
$ cat permdemos.c | tr '[{}]' '(())' or
$ tr '[{}]' '(())' < permdemos.c
c. Create a file named book that contains the contents of two other files: part1 and part2.
$ cat part[12] > book
7. The lpr and sort utilities accept input either from a file named on the command line or from standard input.
a. Name two other utilities that function in a similar manner. cat and grep
b. Name a utility that accepts its input only from standard input. tr 8. Give an example of a command that uses grep
a. With both input and output redirected.
$ grep \$Id < *.c > id_list
b. With only input redirected.
$ grep -i suzi < addresses
c. With only output redirected.
$ grep -il memo *.txt > memoranda_files
d. Within a pipe.
$ file /usr/bin/* | grep "Again shell script" | sort -r
In which of the preceding cases is grep used as a filter?
Example d uses grep as a filter.
9. Explain the following error message. Which 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
10. When you use the direct output symbol (>) with a command, the shell creates the output file immediately, before the command is executed. Demonstrate that this true
$ ls aaa ls: aaa: No such file or directory
$ ls xxxxx > aaa ls: xxxxx: No such file or directory
$ ls aaa aaa The first command shows that the file aaa does not exist in the working directory. The second command uses ls to attempt to list a nonexistent file
(xxxxx) and sends the standard output to aaa. The ls command fails and sends an error message to standard error (you see it on the screen). Even though the ls command failed, the empty file named aaa exists. Because the ls command failed, it did not create the file; the shell created it before calling ls.
11. In experimenting with shell variables, Max accidentally deletes his PATH variable. He decides he does not need the PATH variable. Discuss some of the problems he could soon encounter and explain the reasons for these problems. How could he easily return PATH to its original value? if you don't have $PATH in your variable, the shell won't be able to find the exact location of any command you enter at the command prompt.
$PATH to your ~/.bash_profile, assuming you use bash shell.
12. Assume permissions on a file allow you to write to the file but not to delete it. a. Give a command to empty the file without invoking an editor.
$ filename < /dev/null or $ cat /dev/null > filename
b. Explain how you might have permission to modify a file that you cannot delete.
To delete a file you must have write and execute permission for that directory housing file. To write a file, you must have permission for the file and execute permission for the parent directory. When you have write permission only for a file and execute permission only for the directory the file is in, you can modify but not delete the file
13. If you accidentally create a filename that contains a nonprinting character, such as a CONTROL character, how can you remove the file?
Use rm -i ./* it will interactively ask to confirm deletion for every file listed, answer yes when you get to the one you want to delete.
14. Why does the noclobber variable not protect you from overwriting an existing file with cp or mv?
The noclobber variable keeps the shell from overwriting a file and does not work on utilities. Thus it keeps a redirect symbol (>) from allowing the shell to overwrite a file (the shell redirects output) but has no effect when you ask cp or mv to overwrite a file
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.)
When naming a file, you may also have to consider how other (file) systems will treat that file name. A character in a file name may be fine for your system, but it may be an issue for another system.

So, as long as there was the slightest possibility that you may want to be able to access the file easily from an older system, you'd pick only safe character. This may include booting into an old recovery system you kept around. touch "abcd efgh" touch 'abcd efgh' touch abcd\ efgh

are three possibilities, given that you use a Linux shell. Otherwise, it may depend on the specifics of the software (e.g. libreoffice, emacs, firefox...), usually you can do it staghtforwardly when saving a file rmdir 'file name'

16. Create a file named answer and give the following command:
$ > answers.0102 < answer cat
Explain what the command does and why. What is a more conventional way of expressing this command?
$ > answers.0102 < answer cat
Reading the command from left to right, instructs the shell to redirect standard output to answers.0102, redirect standard input to come from answer and execute the .cat utility. More conventionally the same command is expressed as $ cat answers > answers.0102

You May Also Find These Documents Helpful

  • Good Essays

    ECN100 HW2 3

    • 6656 Words
    • 20 Pages

    (1) Draw an indifference curve map with the quantity of pennies are on the horizontal axis…

    • 6656 Words
    • 20 Pages
    Good Essays
  • Satisfactory Essays

    Mha 616 Wk 5 Dq 2

    • 398 Words
    • 2 Pages

    The main concept of the case Valley Practice adopting a new electronic health record and moving away from a paper-based chart which is one of its strategic goal.. This system will help providers to within the three locations to care for their patients using an up to date system where information can be access from anywhere and anytime. Having such a system will allow valley practice to be recognized as a high-tech, high-touch practice that provides high quality care, cost effective patient care.…

    • 398 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    WB6-4

    • 447 Words
    • 2 Pages

    Escoge la categoría más apropiada para los siguientes objetos, lugares y actividades. a. Dormitorio b. Estadio c. Tienda de ropa d. Servicios para la comunidad e. Para ir una distancia corta f. Para ir una distancia larga g. Papelería h. Carnicería Objetos / Actividades / Lugares 1. sandalias • a • b • c (correct answer, your response) • d • e • f • g • h 2. Points earned: 1 out of 1 View exercise 2.…

    • 447 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    NT1430

    • 285 Words
    • 1 Page

    1. Which commands can you use from the command line to send a file to the default printer?…

    • 285 Words
    • 1 Page
    Satisfactory Essays
  • Powerful Essays

    Which of the following symbols instructs the shell to redirect the output of a command to the specified file instead of the screen and overwrite the file?…

    • 2385 Words
    • 10 Pages
    Powerful Essays
  • Good Essays

    To start a job in the foreground, type in the command at the UNIX prompt and hit return. There are two ways to start a job in the background. First, you can choose the command from your root menu or you can type in the command at the UNIX prompt followed by the ampersand…

    • 567 Words
    • 3 Pages
    Good Essays
  • Powerful Essays

    Nt2799 Oral Exam

    • 7416 Words
    • 38 Pages

    a. It appears that you have the wrong printer driver, for the printer you are using. Delete the current printer configuration and install the correct driver. If you do not have the disk with the driver or it is not stored with your operating system, just go on line and download the correct driver.…

    • 7416 Words
    • 38 Pages
    Powerful Essays
  • Powerful Essays

    Unit 3 network discovery

    • 1031 Words
    • 5 Pages

    What does the shell 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?…

    • 1031 Words
    • 5 Pages
    Powerful Essays
  • Good Essays

    DA 22 HW02

    • 659 Words
    • 3 Pages

    Using fast-set alginate allows the tray to be removed from the patient’s mouth sooner, creating more comfort especially if patient has severe gag reflex.…

    • 659 Words
    • 3 Pages
    Good Essays
  • Satisfactory Essays

    Handout 11 HW

    • 586 Words
    • 2 Pages

    Well if he is living at home can afford to live at home to find a new job that pays the same or if…

    • 586 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    unit 3 homework

    • 254 Words
    • 1 Page

    5. Using the command line tools, how would you add the following to print to CUPS?…

    • 254 Words
    • 1 Page
    Satisfactory Essays
  • Satisfactory Essays

    Eng215 Wk3 Dq 1

    • 250 Words
    • 1 Page

    1. How can you imagine an applied research project helping your company? What might such a research project look like, and what kinds of research would be involved?…

    • 250 Words
    • 1 Page
    Satisfactory Essays
  • Satisfactory Essays

    Hcs 335 Wk 3

    • 407 Words
    • 2 Pages

    * Red Cross has to be open to all the different cultures because it is an worldwide organization that helps everyone when disasters hit. When it comes down to their decision-making the Board of Governors, they get together annually to discuss everything that is happening and information that has been brought to their attention from outside sources. Currently they have a Code of Business Ethics and Conduct document that all employees and volunteers must read and sign a document that states they agree with the terms. According to "American Red Cross Code of Business Ethics and Conduct" (2009), “The Red Cross has traditionally demanded and received the highest ethical performance from its employees and volunteers.” They hold everyone to these standards therefore they know there are not any issues, if issues arise the Office of the General Counsel and the Office of Investigations, Compliance, and Ethics look into the issues and further actions may be taken if any foul play has occurred. (American Red Cross Code of Business Ethics and Conduct, 2009) The American Red Cross has the Whistleblower Hotline, this is where people can communicate their concerns with people being unethical and there is an hotline that they can call if need be. There is a standard that they all are held at and if they do not they are held accountable for their actions but the American Red Cross is always looking to hear what people have to say in all aspects of their organization.…

    • 407 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    Wk7Assgn7NixL

    • 2825 Words
    • 13 Pages

    Laureate Education, Inc. (Executive Producer). (2009b). Literacy development in an academically diverse classroom: Virtual Field Experience™: 'Read with ' activity. Baltimore: Author.…

    • 2825 Words
    • 13 Pages
    Good Essays
  • Good Essays

    HRM593 You decide WK 1

    • 913 Words
    • 4 Pages

    Using the analysis from the text book from Christina Morfeld, some of the specific answers point to Karen’s status is that of an employee. Here are some of the determining questions:…

    • 913 Words
    • 4 Pages
    Good Essays

Related Topics