Ch 5 Review Questions of A Practical Guide to Fedora and Red Hat Enterprise Linux 7th edition

Ace your homework & exams now with Quizwiz!

9b. Explain the following error message. Which filenames would a subsequent *ls* command display?

$ *ls* abc abd abe abf abg abh

10. When you use the redirect output symbol (>) with a command, the shell creates the output file immediately, before the command is executed. Demonstrate that this is 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 3 (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.

2. Using sort as a filter, rewrite the following sequence of commands: $ sort list > temp $ lpr temp $ rm temp

*$ cat list | sort | lpr*

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?

*Reading the command line from left to right*, -it 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*

15b. How would you create a filename containing a SPACE?

-From a command line, -when you want to refer to a file whose name contains an embedded SPACE, -you must quote the SPACE. -A SPACE is a special character to the shell; -it typically separates tokens or words on the command line.

11b.In experimenting w/variables, Max accidentally deletes his *PATH* variable. He decides he does not need the *PATH* variable. b.) How could he easily return *PATH* to its original value?

-Max can attempt to LOCATE the *ls command* using "whereis": *$ whereis ls* *bash: whereis: No such file or directory* -A simple way to return PATH to its original value is to log out and then logback in.

11a. In experimenting w/variables, Max accidentally deletes his *PATH* variable. He decides he does not need the *PATH* variable. a.) Discuss some of the problems he could soon encounter and explain the reasons for these problems. b.) How could he easily return *PATH* to its original value?

-PATH variable is a very crucial, useful and most frequently used variable. -It can cause several problems if this variable got changed incorrectly or got deleted -Because the shell has no way to find them, no commands or utilities, except builtins, will work: *$ ls* *bash: ls: No such file or directory* -The inability to run commands without specifying their pathnames makes the shell more difficult to use.

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.

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 sleeps while a command is executing in the foreground. -When you want to keep working while a command is running, -run a command in the background by ending the command line with an *ampersand* (&).

13. If you accidentally create a filename that contains a nonprinting character, such as a CONTROL character, how can you REMOVE the file?

-Use some unique characteristic of the filename -along with wildcard characters -to specify the file. -Confirm the ambiguous file reference works -by using *echo* before you attempt to use it with *rm*. -For example, assume you want to remove the file named abCONTROL-Txyz. The following commands test an ambiguous file reference to make sure it does not refer to any other files and then remove the file using the reference: *$ echo ab?xyz* *abxyz* *$ rm ab?xyz*

15a. Why do command names and filenames usually not have embedded SPACEs?

Because it is tedious to refer to this type of file, most filenames do not include SPACEs

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?

PID stands for process identification. A PID number uniquely identifies the process running a command. When you run a command in the background, you can use its PID number as an argument to kill to stop the command from running. The ps utility displays PID numbers.

9a. Explain the following error message. Which filenames would a subsequent *ls* command display?

When *rm* utility is executed, it prepares a list of files and folders in target directory. In this case the Current Working Directory as the *target directory name* is not mentioned explicitly. Once the list is built, it starts deleting the files which matches the pattern mentioned in the command line.

15c. How would you remove it? (This is a thought exercise, not recommended practice. If you want to experiment, create a file and work in a directory that contains only your experimental file.)

You can remove a file whose name contains a SPACE by quoting the SPACE: *$ rm dumb\ filename* or *$ rm "dumb filename"*

6. Give a command to a. Redirect the standard output from a sort command into a file named phone_list. Assume that the input file is named numbers. 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.) c. Create a file named book that contains the contents of two other files: part1 and part2.

a. $ sort numbers > phone_list b. $ cat permdemos.c | tr '[{}]' '(())' or $ tr '[{}]' '(())' < permdemos.c c. $ 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. b. Name a utility that accepts its input only from standard input.

a. *cat*, *grep*, and *uniq* NOTES about *grep*: Command: *grep* Usage: *grep* [option] PATTERN [FILE] Example using file: $ *grep* hello file1 Example using Standard Input: $ cat file | *grep* hello b. *tr* and *xargs*

8. Give an example of a command that uses grep a. With both input and output redirected. b. With only input redirected. c. With only output redirected. d. Within a pipe.

a. $ grep \$Id < *.c > id_list b. $ grep -i suzi < addresses c. $ grep -il memo *.txt memoranda_files d. $ file /usr/bin/* | grep "Again shell script" | sort -r In which of the preceding is grep used as a filter? Example d uses grep as a filter

4. Assume that the following files are in the working directory: $ ls intro notesa notesb ref1 ref2 ref3 section1 section2 section3 section4a section4b sentrev Give commands for each of the following, using wildcards to express filenames with as few characters as possible. a. List all files that begin with section. b. List the section1, section2, and section3 files only. c. List the intro file only. d. List the section1, section3, ref1, and ref3 files.

a. Command that List all files that begin with section: *$ ls section** b. Command that List the section1, section2, and section3 files only: *$ ls section[1-3]* c. Command that List the intro file only: *$ ls i** d. Command that List the section1, section3, ref1, and ref3 files: *$ ls *[13]*

12. Assume that your permissions allow you to write to a file but not to delete it. a. *Give a command to EMPTY the file WITHOUT invoking an editor*: b. Explain how you might have permission to modify a file that you cannot delete.

a.) *$ filename < /dev/null* or *$ cat /dev/null > filename* b.) -To delete a file, you must have write and execute permission for the directory housing the file. -To write to a file, you must have write 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

5a. Refer to the *info* or *man* pages to determine which command will: a. Display the number of lines in its standard input that contain the word, "*a*" or "*A*"

a.) To output the number of lines in the standard input that contains "a" or "A", use the command: $ command | grep -wci a In the above command, reading the file 'list' and output the content to standard output which is being feed to '*grep*'. The content is being further filtered by '*grep*' using regular expression '[aA]' which matches if a line has 'a' or 'A' in it. Finally, '*-c*' parameter is being used to count such instances which passes '*grep*' criteria. Below is a screenshot which demonstrates the above commands

5b. Refer to the *info* or *man* pages to determine which command will: b. Display only the names of the files in the working directory that contain the pattern, "*$(*"

b. *$ ls *$\(** -Display only the names of the files in the working directory that contain the pattern $(. $ ls *$\(*

5c. Refer to the *info* or *man* pages to determine which command will: c. List the files in the working directory in reverse alphabetical order

c. *$ ls -r*

5d. Refer to the *info* or *man* pages to determine which command will: d. Send a list of files in the working directory to the printer, sorted by size.

d. *$ ls -S | lpr*


Related study sets

Biology Exam 4: evolution of plants and animals pt.2

View Set

CHAPT. 45 & 46 ENDOCRINE DIABETES (PREP U)

View Set

Unsupervised Learning and K means Clustering

View Set

World War I Begins 5:World War I and the Russian Revolution

View Set

Info Sec Exam 2 Prep (Questions)

View Set

HESI/Saunders: Pharmacology and IV Therapies Exam

View Set

Google Technical Support Fundamentals, Week 3

View Set