cist 2431

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

A user has requested that each time she presents credentials to log in, a particular entry be written to a log file. This action will only apply to her, and she is using the bash shell. Which of the following configuration files is the BEST to modify to enable this action?

.profile explained: The .profile file exists within the user's home directory and is executed upon each login. Modifying this script will enable this action for only this user.

Anna, a system administrator, wants to set a global variable that can be used each time she logs in. Currently, she has to set the variable each time a terminal is opened. Which of the following files would need to be modified to make a global variable persistent? (Choose TWO.)

/etc/profile & ~./bash_profile explained: ~./bash_profile and /etc/profile can be modified to add the global variable declaration. Each time Anna logs on, the variable will be set. ~./bash_history stores the command history. ~./bash_logout is used to perform cleanup when exiting a bash shell.

All users at your site are using the bash shell. You want to set a variable that will apply to every user and always have the same value. Which of the following shell configuration files should you place this variable in?

/etc/profile explained: The /etc/profile file runs for all users. Variables in this files are set for every user. The .bash_profile file is located in a user's home directory and runs only for that specified user. The .login file is located in a user's home directory and runs only for that specified user. The .bashrc file is located in a user's home directory and runs only for that specified user.

Which of the following commands configures the shell to retain 300 recently used commands in the ~/.bash_history file for multiple shell sessions?

HISTFILESIZE=300 explained: The HISTFILESIZE=300 command sets the number of past commands remembered between multiple sessions and stored in the ~/.bash_history file.

Which environment variable affects the number of past commands stored in memory in the current shell session?

HISTSIZE explained: The HISTSIZE environment variable specifies the number of past commands stored in memory in the current shell session. The HISTFILESIZE shell variable holds the number of past commands remembered between sessions

Which command operator pipes the output of one command as the input of another command?

I explanation: The pipe (|) operator directs the output of one command into the input of another command.

Which of the following statements BEST describes the PATH environment variable?

It contains the directory prefixes used to search for programs and files. explained: The PATH environment variable contains the directory prefixes used to search for programs and files. Use a colon to separate multiple directories in the PATH variable. The HISTFILE shell variable specifies the filename where past commands are stored. The PS1 shell variable specifies the characters the shell prompt that indicates either a normal user ($) or root user (#). The PWD environment variable contains the path of the current (or present) working directory.

You want the directory /sbin/special to be include in the PATH environment variable. You also want to keep all the current directory entries currently in the PATH variable. Which of the following commands would you use?

PATH=$PATH:/sbin/special explained: A colon separates entries in the PATH statement. The PATH=$PATH:/sbin/special command appends a colon (:) and the /sbin/special directory to the existing PATH ($PATH). The PATH=$PATH:$/sbin/special command corrupts the PATH variable by append a dollar sign ($) and the /sbin/special directory to it. The PATH=/sbin/special command replaces the current PATH with only the /sbin/special directory. The ampersand (&) in the PATH=PATH&/sbin/special command causes the PATH=PATH command to be run in a child process and then the /sbin/special command to run. While this command is interpreted by the bash shell, it does not modify the PATH variable.

Which of the following describes the effects of the ls -l /usr/bin >> /tmp/list.txt command?

The contents of the /usr/bin directory are written to a file named /tmp/list.txt. Previous file contents are kept, and the new information is added at the end of the file. explanation: The >> operator redirects the output of a command to a file, appending the new information to the end of the file. The file contents are not overwritten. The new information is not added to the beginning of the file. The contents of the /usr/bin directory are not written to the screen.

Which of the following commands stores the output of the ls -a command in a shell variable named allfiles?

allfiles=$(ls -a) explanation: allfiles=$(ls -a) stores the output from the ls -a command in the shell variable allfiles. This is command substitution. allfiles=$((ls -a)) stores the value of zero in the variable allfiles. allfiles="exec ls -a" stores the exec ls -a string in the variable allfiles. allfiles="ls -a" stores the ls -a string in the variable allfiles. allfiles=${ls -a} utilizes command expansion and does not produce a command output.

Which of the following commands sorts the contents of the wordlist1 and wordlist2 files and sends the result to standard output?

cat /usr/wordlist1 /usr/wordlist2 | sort explanation: The pipe operator (|) in the cat /usr/wordlist1 /usr/wordlist2 | sort command sends the output from the cat command (a list of the contents of the wordlist1 and wordlist2 files) as input to the sort command. The sort command sorts the input and sends the result to standard output (usually the screen). The cat /usr/wordlist1 > /usr/wordlist2 construct overwrites the contents of the wordlist2 file with the contents of the wordflist1 file. The cat /usr/wordlist1 | /usr/wordlist2 | sort command returns an error since the /user/wordlist file is not an executable file. The cat /usr/wordlist1 >> /usr/wordlist2 | tee command appends the contents of the wordlist1 file to the contents of the wordflist2 file. The tee command requires a filename as an argument.

Which of the following commands sorts the combined contents of the wordlist1 and wordlist2 files and sends the results to both the screen and a file named sortedwordlist?

cat /usr/wordlist1 /usr/wordlist2 | sort | tee sortedwordlist explanation: The cat /usr/wordlist1 /usr/wordlist2 | sort | tee sortedwordlist command sorts the combined contents of the wordlist1 and wordlist2 files and sends the results to both the screen and a file named sortedwordlist. The cat /usr/wordlist1 /usr/wordlist2 | tee sortedwordlist command does not perform a sort. The cat /usr/wordlist1 /usr/wordlist2 | sort sortedwordlist command attempts to sort a file named sortedwordlist that, most likely, does not exist. The cat /usr/wordlist1 >> /usr/wordlist2 | sort sortedwordlist command will append the contents of the wordlist1 file to the wordlist2 file and will attempt to sort a file named sortedwordlist that, most likely, does not exist.

Which of the following commands gives the same results as cat < turbo?

cat turbo explanation: Using the turbo file as an argument of the cat command causes the turbo file to be used as input. The < operator results in the same action. The contents of the turbo file are redirected to the cat command as input. The 1> turbo construct writes the output of the cat command to the turbo file. The 2> turbo construct writes any errors generated by the cat command to the turbo file. The &> turbo construct writes both the output of the cat command and any errors generated by the cat command to the turbo file

Which of the following commands copies the entire /temp directory with all of its files, sub-directories, and files in the sub-directories to the /home/gshant directory. (Select TWO. Each answer represents an independent solution.)

cp -r /temp /home/gshant cp -R /temp /home/gshant explained: The cp -r and cp -R command copies directories and files recursively. It also leaves the source contents intact. The cp command without the -r or -R option only copies the specified file or directory. The cp -s command creates a symbolic link instead of copying the file or directory. The cp -q command displays an error because there is no -q option

Tom, a shell script developer, knows that the date +%A command gives the current local weekday name (Sunday, Monday, Tuesday, ...). Which of the following commands will copy the authentication log file, /var/log/auth.log, to a new file with a filename that includes the current local weekday name?

cp /var/log/auth.log ~/auth$(date +%A).log explanation: The $(date +%A) operator performs a command substitution so that the new filename will include the current local weekday name. The ${date +%A}.log operator attempts to substitute the contents of a variable. The tee command is used to write output to both stdout and to a file. The xargs command is used to divide large amounts of streamed output into smaller chunks to be used as arguments for another command.

You want to view the number of commands your bash shell is set to save by examining the current HISTSIZE environment variable. You don't want to have to scroll through all the environment variables. Which of the following commands is the BEST way to determine the current value of the HISTSIZE variable?

echo $HISTSIZE explained: The echo $HISTSIZE command returns the value for the HISTSIZE environment variable.

Which of the following commands shows the value of the LANG environmental variable currently set for the language the operating system uses?

echo $LANG explained: The echo command displays the results of an expression. An expression formed with a dollar sign ($) followed by a variable name results in the assigned valued of the variable. The echo LANG command gives the results "LANG" without translating the variable to its assigned value. The echo %LANG command gives the results "%LANG" without translating the variable to its assigned value. The percent (%) character is used for substitutions in Windows command line scripts. The echo %LANG% command gives the results "%LANG%" without translating the variable to its assigned value. The percent (%) character is used for substitutions in Windows command line scripts.

Two users should have identical settings, yet one is having problems with the display on his screen, and you suspect there is a difference in their environment variables. Which of the following commands displays all of the environment variables?

env explained: The env command displays a list of all the environment variables and their values.

You need to set the COMP variable to the value 1745. Which of the following commands sets the variable so it is inherited by subsequent child shells?

export COMP=1745 explained: The export COMP=1745 command creates the COMP variable, assigns it the value of 1745, and sets the export attribute to make it an environment variable that will be inherited by subsequent child shells.

You recently used the HOST=FS4 command. Which of the following commands should you use to change the HOST variable to a global variable that will be inherited by subsequent child shells and processes?

export HOST explained: The export HOST command changes the HOST variable to an environment variable.

Tim, a technician, created a local variable named val and set it to 5000 at the bash prompt. Tim wants to use the variable in a script. But when the script is executed, the value of val is not set to 5000. Which of the following commands would allow Tim to set a global variable that would be available to the script?

export val=5000 explained: export val=5000 will create a global variable named val and set the value to 5000. The variable val will be available to any scripts or applications run in that terminal session. declare val is used to declare a variable. In this case, no value would be assigned. The scope of the variable is not global. echo $val=5000 will display the value of $val, which is empty, and then displays =5000 as the output. exec val will display the error "bash: exec: val: not found."

You need to view the contents of the /home/jerrys directory. What would you enter at the command prompt to show all the contents, including hidden files and directories?

ls -a /home/jerrys explained: Use the ls -a command to view the contents of a directory, including the hidden content.

Which of the following commands displays an expanded listing that includes the owner and size of all the files in the /etc directory?

ls -al /etc explained: ls -al /etc with the -a switch for all files and -l switch for the long (expanded) listing displays the desired listing. ld is for the GNU linker. dir is not a standard Linux command. ls -ae does not work because there is no -e switch

Ann, a Linux script developer, is trying to debug a shell script that has the command ls -s in it. She suspects that an error is occurring, and she wants to send the results of the operation and any errors to a file named ~/Friday in order to examine it later. Which of the following commands should she use?

ls -s &> ~/Friday explanation: The &> operator redirects both successful output (1) and error results (2) to the same file. The &> ~/Friday construct is equivalent to 1> ~/Friday 2> &1 and 1> ~/Friday 2> ~/Friday. The > operator only redirects the output. The >> operator only redirects the output and appends the new information to the ~/Friday file. The < operator passes the contents of the ~/Friday file to the ls command as input. In this case, the ls command will ignore the input.

Fred, a Linux administrator, needs to create the directory /var/oracle/database/9i. Only the directory /var currently exists. The current working directory is the root of the filesystem. Which of the following commands will create the directory path?

mkdir -p /var/oracle/database/9i explained The mkdir -p /var/oracle/database/9i command creates all the directories that do not exist in the directory path. The mkd command returns an error unless a command alias has been created. The md command is normally run from a windows command prompt and returns an error unless a command alias has been created. The mkdir /var/oracle/database/9i command displays an error since the /var/oracle/database directory does not exist.

Joe, a bash script developer, is trying to debug a shell script named myscript. Which of the following commands would record the output of the script in a text file?

myscript >> testfile.txt explanation: The myscript >> testfile.txt command uses the >> operator to redirect the output of the executed myscript script to a file named testfile.txt. The echo myscript >> testfile.txt command appends the contents of the myscript file to the testfile.txt file. The myscript | testfile.txt command pipes the output of a command as the input of another command (or shell script). In this case, testfile.txt is not likely to be an executable shell script. The echo command within the myscript | echo | testfile.txt command does not echo the output form the myscript script because it does not read from stdin. Additionally, testfile.txt is not likely to be an executable shell script.

Which of the following commands utilize command substitution? (Choose TWO.)

myvar=`sort -r names.txt` myvar=$(sort -r names.txt) explanation: myvar=`sort -r names.txt` and myvar=$(sort -r names.txt) both provide command substitution. Enclosing a command within backticks (`) performs command substitution in the same way as the $() operator. echo -e "sort -r names.txt" echoes the command to stdout. myvar="echo 'sort -r names.txt'" stores the following in the myvar variable: echo -e text stored in names.txt

Which command displays all the environment variables defined in the shell?

printenv explained: Both the printenv and env commands display the values for environment variables defined in the shell.

Within the /var directory is a subdirectory named backup. Ken, a Linux administrator, needs to delete the directory backup and any files that it contains. He changes directory focus to /var. Which of the following commands deletes the directory named backup and any file it contains?

rm -r backup explained: The rm -r backup command deletes the directories and all the files it contains. The rm backup/* command only deletes the files in the /var/backup directory. The rm backup command fails without the -r recursive switch. The rm -r backup/* command only deletes the files in the /var/backup directory.

The /home/gshant/smp directory contains several files. The directory and files need to be removed. The current working directory is /home/gshant. What would you enter at the command prompt to remove the smp directory and all the files it contains

rm -r smp explained: Use rm -r to delete a directory that still has contents. The -r option deletes directories (and all files) in the directories. The rmdir command only deletes empty directories.

The /home/gshant/smp directory is empty and needs to be removed. The current working directory is /home/gshant. What would you enter at the command prompt to remove the smp directory?

rmdir smp explained: Use the rmdir to delete an empty directory. Use rm to delete a directory which still has contents. In this case, rmdir or rm will delete the directory. Example: rmdir smp

Which command reads from standard input (stdin) and writes to both standard output (stdout) and a file?

tee explanation: The tee command reads from standard input (stdin) and writes to both standard output (stdout) and a file.

Which command overcomes the 128 KB shell command size restriction by breaking up long lists of arguments?

xargs explanation: The xargs command reads items from the standard input and breaks up long lists of arguments into smaller, usable chunks.

After a user starts a bash session and the script in /etc/profile is applied, if all of the following files exist, which will be run next?

~/.bash_profile explained: If the ~/.bash_profile file exists, it is run after the /etc/profile file. No additional configuration script files will be run.

Which of the following files would you use to create aliases that are applied when a specific user starts a bash session? (Select TWO. Each answer is an independent solution.)

~/.profile ~/.bashrc explained: The ~/.profile file runs for individual users. The ~/.bashrc file runs for individual users. The /etc/profile runs for all users. The ~/.bash_logout file runs for an individual user, but only runs when the user logs out. The /etc/bashrc runs for all users.


Kaugnay na mga set ng pag-aaral

Pharmacology Exam 5 Ch.19-24 (Online Questions)

View Set

Chapter Exam- Disability Insurance

View Set

Vocabulary Workshop Level F Unit 9-15

View Set

Generalized Response Systems (GRS): SNS, AANS, CRH

View Set

Chapter 7: Thinking and Intelligence

View Set

Chapter 1: Introduction to Nursing

View Set