Question

Use the following example to answer the question that follow: $ ls –l | lpr &...

  1. Use the following example to answer the question that follow:

$ ls –l | lpr &

[2] 23092

$

  1. What is the “|” called in the above command and what does it do?

  1. What are the [2] and number 23092 called?   
  1. What command could be used to kill this background job before completion?
  1. Use the following example to answer the question that follow:

$ [ -f ~/fileManager/debugFiles/debugLog.txt ] && cp ~/fileManager/debugFiles/debugLog.txt ~/lab9 || echo “failed to copy debugLog.txt to ~/lab9”

  1. What is the test command checking for?

  1. What action occurs if the test command check is true?   
  1. What action occurs if the test command check is false?
0 0
Add a comment Improve this question Transcribed image text
Answer #1

I am numbering the sub-questions of this question from 1 to 6.

  1. "|" in the given command is called a pipe operator. It is one of the chaining operators in Linux. Using this operator, the output of the first command acts as an input to the second command.  
    • In the command given the question, the first command 'ls -l ' performs the operation of listing all the files in the directory in the long listing format (ls command for listing, and -l option specifies long listing format). The output of this command forms the input to the command 'lpr'.
    • 'lpr' command is a much more user-friendly command for printing than the 'cat' command in linux, which we use often for printing. Other advantages of lpr command - it allows us to queue the print jobs. It also allows to access printer device without being the superuser.
    • & is called the Ampersand operator whose function is to make the command run in the background. So the lpr command runs in the background.
  2. [2] is the job ID and 23092 is the process ID.
  3. 'kill' command can be used to forcibly terminate a process by sending an appropriate terminate signal to the process. The default signal for kill is 'TERM'. For stubborn processes that refuses to die with a plain kill command, kill -9 can be used which is a sure kill.
    • A single process can be killed using the command 'kill Process_ID'.
    • To kill all the processes, killall command can be used.
  4. The test command is checking for the existence of the file : ~/fileManager/debugFiles/debugLog.txt. The operators used here are && followed by ||. This combination of operators is called AND-OR operator. It acts as an 'if-else' statement.
  5. The test command as mentioned above, checks for the existence of the given file. If the command check is true, ie., if the file exists, then it is copied to the ~/lab9 file.
    • cp command copies source file which is the first argument for the command: '~/fileManager/debugFiles/debugLog.txt.' to the destination file - '~/lab9', the second argument.
  6. If the test command check is false, it means that the given file doesn't exist. In this case, the command to the right of || operator is executed, which is the echo command. The echo command is used to display the line of text that is passed as an argument. Therefore, if the test command check fails in the question, 'failed to copy debugLog.txt to ~/lab9' is printed.
Add a comment
Know the answer?
Add Answer to:
Use the following example to answer the question that follow: $ ls –l | lpr &...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT