CompTIA Linux+ XK0-005 - Practice Questions
A friend sends you a shell script file that is 117 lines long. He says that he wants you to check the code on lines 82 through 87. What command would you enter while in vi command mode to go directly to line 82?
:82 You would use #82 to go to line 82 of the document while in command mode. Typing a colon (:) enters command line mode from command mode.
Which of the following vi key combinations should you press while in Insert Mode to save the file you are working on and exit the editor?
<Esc>:wq From Insert Mode, press the Esc key to enter the command mode. Enter a colon (:) for command line mode. Press w to write the file and press q to exit the editor (quit).
When working with Linux, it is important to understand what distributions are and how they are used. Which of the following BEST describes a Linux distribution?
A Linux distribution (also known as a distro) is a unique bundling of the Linux kernel, plus other applications and services.
Your company uses both Linux desktops and Windows desktops. Which of the following server roles should you use to provide a central location for users of both operating systems to share files?
A Linux file server is a machine that has been set up and configured to let other machines store and retrieve files to and from a central location. In addition, using a file server can simplify backups and security. Using SMB shares and a variety of programs such as Samba or Network File System, a Linux file server can share files with other Linux systems, as well as with non-Linux systems such as Windows and Mac.
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?
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).
Alex, a webmaster, is implementing an order processing system on the company's website. Which of the following server roles should Alex implement with the order processing application?
A database server should be implemented with the order processing application to store the data gathered by the application.
What type of shell runs after the user successfully logs in using an ID and password?
A login shell runs after the user successfully logs in using a user ID and password.
Which of the following actions defines a persistent alias?
Adding the command defining the alias to the appropriate shell configuration file.
Which of the following is displayed when the uname -a command is run?
All system information
Which of the following Linux features lets you store a shortcut in memory or as part of the shell configuration file that runs a specific command?
An alias is a shortcut stored in memory or as part of the shell configuration file that runs a command on your Linux system.
Anna, a system administrator, wants to set an environment variable that can be used each time she logs in. Currently, Anna has to set the variable each time a terminal is opened. Which of the following files would Anna need to modify to make the variable a global environment variable?
Anna can modify the ~./bash_profile and /etc/profile files to add the variable as a global environment variable. Each time Anna logs on, the variable will be set.
Which of the following commands would update the modification date and last accessed time for the /home/kcole/personal_info file?
Because the personal_info file already exists, the touch /home/kcole/personal_info command would update the modification date and last accessed time for the file.
Which command displays all the environment variables defined in the shell?
Both the printenv and env commands display the values for environment variables defined in the shell.
Match the vi mode on the left to the correct definition on the right.
Command Mode is the initial mode vi uses when started. It has commands that cut and replace text, and it is the mode vi uses to enter the other modes. Command Line Mode is the mode that works with the file system. Use it to save files after editing them. Edit Mode is the mode that vi uses to write and edit text in the file. It has two operation modes.
You are managing a Linux server with a console (without a GUI installed). Which of the following key combinations would you press to switch to the fourth shell session?
Ctrl+Alt+F1 through Ctrl+Alt+F6 (in some Linux distributions Alt+F1 through Alt+F6) will switch to the first through the sixth shell sessions.
You want to view the Linux help information for the mkdir command. While viewing the information, you want to be able to scroll through the onscreen help. What is the command you would use to display and be able to scroll through the mkdir help information?
Depending on your Linux system, you would enter mkdir --help | more or mkdir -h | more to let you scroll through the onscreen mkdir help.
While in vi Command Mode, you copy a whole line of text to the general buffer. You then navigate to a different location in the file. Which of the following commands will let you paste the copied text?
Each of the following commands must be done in Command Mode. To enter Command Mode from Edit Mode, press the <Esc> key. You can use the p command to paste text from the text buffer into the document while in command mode.
You have forgotten what information is provided by the whoami command, and simply want a short description of the command. Which of the following help commands could you enter to view that short description?
Entering help -d whoami would provide a short description of the whoami command.
What command displays a list of the currently defined aliases on the system?
Entering the alias command at the shell prompt displays a list of the currently defined aliases on the system.
Which of the following are rules that apply to Linux files and directories?
File and directory names are case-sensitive. The forward slash is used as a delimiter for a file or directory path. The dot (.) in a filename is not necessary.
A user starts a bash session and the script in /etc/profile. If all of the following files exist, which will be run next?
If the ~/.bash_profile file exists, it is run after the /etc/profile file. No additional configuration script files will be run.
Your company develops applications to run on Linux systems. You currently have four development teams, each working on a different aspect of the same application. Which of the following server roles would give you the BEST method for testing all team members' code without affecting your part of the project or your operating system and personal files?
Linux containers give you the ability to run an application (with all of the necessary libraries, dependencies, and files) in an isolated environment known as an image or container. Due to this isolation, multiple containers can run on the same host without affecting each other or the main operating system. All containers utilize and share the same operating system kernel of the host machine, making them very lightweight and fast.
Linux can be implemented in many different ways. Drag the implementation type on the left to the definition on the right that BEST matches.
Linux on mobile devices Linux has nearly taken over the mobile device market in the form of the Android operating system. The current Android operating system is a specialized Linux distribution created by Google. It was designed primarily for touch screen mobile devices, such as smart phones and tablet computers. Linux Virtualization Virtualization is the ability to install and run multiple operating systems concurrently on a single physical machine. The Linux operating system can be virtualized. Embedded Linux Embedded Linux is the process of embedding Linux within intelligent devices, such as automation and control equipment, smart TVs, smart phones, and tablets. To accomplish this, the operating system is reworked and customized in such a way that it provides only the functions required by that particular device and all the remaining unnecessary elements of the Linux kernel are removed. Once that's done, the kernel itself is embedded in flash memory chips on the given device. Linux and Cloud Computing In cloud computing, the hardware, software, and/or network resources that have historically been implemented onsite are moved offsite. When a new Linux system is required, you can use an internet cloud provider to deploy the new Linux virtual machine using a hypervisor at their site. You then pay that provider a fee to access this virtual machine through your organization's network connection. This process is referred to as Infrastructure as a Service (IaaS).
Mary Brown is a Linux user with the username mbrown. Mary has a directory named logs in her home directory that is regularly updated with new log files when certain system events occur. She runs the following commands several times a week to check this directory: cd /home/mbrown/logs ls -al She wants a persistent alias named logcheck to run these two commands. What command would Mary enter into the shell configuration file to create this persistent alias?
Mary would enter the following command in the shell configuration file: alias logcheck="cd /home/mbrown/logs;ls -al" The two commands need to be inside double quotation marks (") or single quotation marks (') and separated by a semi-colon (;).
Your company has been expanding the number of servers in the company's data center, and there is an increased need to gather metrics, watch process states, work with logs, watch services states and file system usage. Which of the following sever roles should be installed to provide this functionality?
Monitoring refers to the process of monitoring the essential Linux services, including such things as operating system metrics, process state, logs, service state, and file system usage. It also refers to monitoring servers' availability.
What type of shell runs when a user opens a shell after first authenticating with a user ID and password? (Type the answer in the blank field.)
Non-login shells run when a user opens a shell after first authenticating with a user ID and password.
Select the file type from the drop-down list below that is also called by non-login shell configuration files.
On most Linux distributions, the *.sh files in the /etc/profile.d/ directory are also called by non-login shell configuration files.
From the drop-down list below, select the file that is called by the non-login shell configuration file.
On most Linux distributions, the ~/.bashrc file is called by a non-login shell configuration file.
If you are viewing the contents of a man page, which key can you press to get back to the beginning of the page?
Pressing the Home key moves you back to the beginning of the man page.
Drag the server role on the left to its proper description on the right.
Proxy: A proxy is a computer that provides indirect internet access to the computers in your network. In most cases, a proxy server is installed on the same computer as the firewall. Proxy servers provide increased performance and security by blocking direct access between two networks, such as the corporate network and the internet. Proxy can be configured in a variety of ways, such as using SSH tunneling or installing an app on a system that has been configured as a web server. Logging: An important Linux role is the ability to capture a timeline of events that have taken place on the computer in the form of a file, referred to as a log file. The process of creating these logs is known as logging. Logging is enabled by default and logs are often captured for such things as services, the Linux operating system, and applications. Logging is useful for such things as troubleshooting, security, and evaluating server performance. If desired, you can configure a centralized logging server making it easier to evaluate and use the logs created on many systems. Although log files can be stored in a variety of places, most logs are stored in the /var/log directory or a subdirectory thereof. VPN: A VPN (Virtual Private Network) can be installed on a Linux host and is a type of network that uses encryption to allow IP traffic to travel securely over the TCP/IP network. A VPN is used primarily to support secure communications over an untrusted network. For example, connecting two remote sites by means of the internet. Load balancer: When a company has back-end servers that receive a significant amount of traffic (such as Netfilx, Hulu and Airbnb), response time to these servers can be increased through load balancers by distributing the workload across the available servers. Although load balancers can be purchased as a hardware appliance, software can be installed on a Linux server, making it a load balancer. Three common Linux load balancers include Linux Virtual Server (a free and open-source project), Nginx, and HAProxy, all of which run on top of Linux. Some of the load balancer software is free and some are for pay.
Drag the server role on the left to its proper description on the right.
SSH (Secure Shell or Secure Socket Shell) is a protocol used to securely log onto remote systems using encryption. SSH is the most common way to access a remote Linux system. OpenSSH is an open-source implementation of the Secure Shell (SSH) protocol and is implemented on most Linux distributions by default. A web server is responsible for accepting HTTP (Hypertext Transfer Protocol) requests from web browsers or clients and, in turn, sending the clients the files that form webpages. For example, webpages often consist of HTML (Hypertext Markup Language) documents and linked objects, such as images. A machine that has been dedicated to perform this role is also called a web server. A name server resolves (or maps) the fully qualified domain names (FQDNs), such as www.TestOut.com, to their respective IP addresses and IP addresses to their respective FQDNs. This would let a user access the TestOut site from a web browser by entering https://www.TestOut.com instead of something like https://104/16/32/53. The Simple Network Management Protocol (SNMP) is a protocol designed for managing complex networks and is used to communicate with and monitor network devices, servers, and other devices through the IP protocol. SNMP lets network hosts exchange configuration and status information. For example, SNMP can be used to remotely retrieve the operational statistics of a router or a firewall. On a Linux machine, SNMP runs as a daemon.
Which of the following is the primary role of a mail transfer agent (MTA)?
Store messages so they can be downloaded or send email to a destination MTA.
You want to copy all the text files from the /home/kcole/documents directory to the /home/mruiz/personal directory. While copying the files, you want to be prompted before overwriting a file in the /home/mruiz/personal directory. What command would you enter to accomplish this task?
The -i option prompts before overwriting a file in the destination directory. In this scenario, you would enter the cp -i /home/kcole/documents/*.txt /home/mruiz/personal command.
Each time you present credentials to log in, you want a particular entry to be written to a log file. This action will only apply to yourself. You are using the bash shell. Which of the following configuration files is the BEST to modify to enable this action?
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 yourself.
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?
The /etc/profile file runs for all users. Variables in this file are set for every user.
Which of the following is the standard shell for MOST Linux computers?
The Bourne again shell (Bash) is the standard shell used in most Linux computers. It uses commands similar to a UNIX shell. Bash includes features such as: Command completion when pressing the tab key Command history Improved arithmetic functions
Which of the following man page sections shows a list of options available for a Linux command and explains what the options do?
The DESCRIPTION section typically lists the options that are available for the command and explains their purpose and use.
Which of the following commands configures the shell to retain 300 recently used commands in the ~/.bash_history file for multiple shell sessions?
The HISTFILESIZE=300 command sets the number of past commands remembered between multiple sessions and stored in the ~/.bash_history file.
Which of the following statements BEST describes the PATH environment variable?
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.
Which of the following nano editor keyboard shortcuts displays help text, including a list of all keyboard shortcuts?
The ^G (Ctrl+G) keyboard shortcut displays help text which includes a list of all keyboard shortcuts.
Which of the following commands creates a shortcut that can be used to run the tail -f /var/log/messages command?
The alias sysmesg="tail -f /var/log/messages" command creates an alias named sysmesg that, when typed at the shell prompt, executes the tail -f /var/log/messages command.
What would you enter at a command prompt to start a new Bourne again shell (Bash) session?
The bash command opens a Bourne again shell (Bash) session. Bash is the standard shell used in most Linux computers. It uses commands similar to a UNIX shell. Bash includes features such as: Command completion when pressing the tab key Command history Improved arithmetic functions
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?
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.
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.
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?
The echo $HISTSIZE command displays the value for the HISTSIZE environment variable.
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 value of the variable. The echo LANG command displays "LANG" without providing the assigned value of the variable.
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 an environment variable that will be inherited by subsequent child shells and processes?
The export HOST command changes the HOST variable to an environment variable.
Which of the following are examples of a user running a login shell?
The following are examples of a user running a login shell: When the Linux system does not have a GUI and the user logs in using the text-based interface. When a user runs the sudo -i <user ID> command and enters the correct password.
Which of the following are examples of a user running a non-login shell?
The following are examples of a user running a non-login shell: When a user opens a shell session (terminal application) from within the GUI. When a user runs the sudo <user ID> command without the -i option.
Match the nano shortcut on the left to the correct shortcut definition on the right.
The following are the correct definitions for the listed shortcuts: ^G (Ctrl+G) - Displays the help text, which includes a list of all keyboard shortcuts. ^X (Ctrl+X) - Closes the current buffer or exits from nano. ^Space (Ctrl+Space) - Moves forward one word in the current line. ^K (Ctrl+K) - Cuts the current line (or selected text) and stores it in the cutbuffer. ^U (Ctrl+U) - Uncuts (pastes) the text from the cutbuffer into the current line.
The ls command displays the contents of a directory and includes several options. From the list of options on the left, drag an option to the correct definition on the right.
The following are the correct definitions for the ls command options: -a displays all directory content, including hidden content. -l displays extended information, including the owner, modified date, size, and permissions. -R displays the contents of a directory and all of its subdirectories. -d displays directories but not files.
What commonly predefined alias is configured to run the ls -l command?
The ll command is a commonly predefined alias that runs the ls -l command, which lists the contents of a directory in long form.
You want to search all the man pages for information available for the Bluetooth protocol. Which of the following commands would you enter to display this information?
The man -k bluetooth command searches all man pages for any mention of bluetooth.
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 testfile.txt text file?
The myscript >> testfile.txt command uses the >> operator to redirect the output of the executed myscript script to a file named testfile.txt.
Which of the following nano text editor features makes it easier for beginners to learn than the vi text editor?
The nano text editor is considered by most beginning users to be easier to learn because the keyboard shortcuts are displayed at the bottom of the editor.
Which of the following commands is designed to delete an empty directory?
The rmdir command is designed to delete an empty directory.
Which command reads from standard input (stdin) and writes to both standard output (stdout) and a file?
The tee command reads from standard input (stdin) and writes to both standard output (stdout) and a file.
You have created a listgroups alias that you now want to remove. Which of the following commands will remove the alias?
The unalias listgroups command will remove the listgroups alias.
In which of the following files is the user's preferred shell normally set?
The user's preferred shell is normally set in the /etc/passwd file.
Which command overcomes the 128 KB shell command size restriction by breaking up long lists of arguments?
The xargs command reads items from the standard input and breaks up long lists of arguments into smaller, usable chunks.
Which of the following files could you use to create aliases that are applied when a specific user starts a bash session?
The ~/.profile file runs for individual users. The ~/.bashrc file runs for individual users.
Which of the following are characteristics make info nodes different from man pages?
They are more verbose and emphasize how to use commands and utilities. They contain hypertext links to navigate between nodes.
You want to make an alias persistent across all reboots of your Linux server. In which of the following files do you need to place the alias command to make the alias persistent?
To make an alias persistent across reboots, add the alias to the /etc/profile or /home/user/.bashrc file.
Match the vi command on the left with the correct description of the cursor movement the on the right.
To navigate while in vi Command Mode, use the following: h moves the cursor one space to the left. j moves the cursor down a line. k moves the cursor up a line. l moves the cursor one space to the right.
You want to rename the /home/kcole/documents directory to /home/kcole/personal. What command would you enter to perform this task?
To rename the directory to personal, you would enter the mv /home/kcole/documents /home/kcole/personal command.
A Linux user has an executable file named ni that can save a snapshot of network information with the date and time in a log file. The executable ni file is in the /root directory, and /root is the current working directory. Which of the following commands would run the executable file?
To run an executable, you can either change to the directory where the script is stored and type ./ni or type the absolute path (in this case, /root/ni) to run the script from any directory. Typing just the file name, ni, will not work because the current working directory, /root, is not typically contained in the PATH variable.
Which of the following commands searches man pages for a specific keyword?
To search the man pages, use the man -k, apropos, or whatis commands. The whatis database must be created prior to using these commands. Use the makewhatis command to build the database.
As a Linux user, you have access to an executable file named myapp. It's found in the current directory, but not in the command path. What would you enter at the command prompt to start the myapp file and replace the shell with myapp process?
Use exec ./myapp to start the myapp executable file and replace the shell with myapp process.
Which of the following commands should a Linux user enter to see a list of all the commands the user recently ran at the command prompt?
Use history to see all commands in the history queue. The -c option clears the history list. History command queues are separate for each user. A command typed as one user cannot be used after using the su command to switch to another user.
What would you enter at the command prompt to display the current working directory?
Use the pwd command to display the current working directory.
You have just entered the apropos grep command at the command prompt. What can you expect to be displayed?
When you enter the apropos grep command, a one-line man page description is displayed for the command.
When creating a custom alias, how many commands can you add to the alias?
You can add one (1) or more commands to a custom alias.
You are at a terminal command prompt in a Linux GUI interface that someone else has been using and want to find out which shell type is currently being used by the terminal. What command can you enter to find out the current shell type?
You can enter the echo $0 command to find out the current shell type. The variable $0 normally holds the command used to start a script. A shell session is initiated by a script. Consequently, $0 will hold the name of the script which is consistent with the shell type.
What command would you enter while in vi Command Mode to find the word Sam?
You can use either of the following to search for the word Sam while in vi Command Mode: /Sam searches forward for all instances of a term.
You want to create a /sales/documents/quarterly_reports directory. The documents directory does not exist yet. What command would you enter to create the quarterly_reports directory?
You can use the -p option to create all directories within the specified path when that path does not already exist. In this scenario, you can enter mkdir -p /sales/documents/quarterly_reports or md -p /sales/documents/quarterly_reports to create both the documents and quarterly_reports directories.
As an IT administrator, you are tasked with configuring an Apache web server by modifying the /etc/apache2/apache2.conf file. You open the file in vi. As you're looking at the file, you knock your spill-proof drink container onto the keyboard. It rolls over several keys as you try to pick it up. Now there are extra characters everywhere in the text buffer. Which of the following commands can you use to exit vi without saving any changes that were made to the text buffer?
You can use the :q! command to exit without saving the changes made to a file.
You have just finished editing the grub file in the vi editor and want to change to the command-line mode, save the changes, and exit the editor. What would you enter in the vi editor to accomplish these tasks?
You would enter :wq to accomplish these tasks. The : switches you to the command-line mode from command mode; the w saves the current document; the q exits vi.
You want to create a grepcolor alias that provides a lime green (36) background color to the search terms when using the grep command. You want this command to be persistent when rebooting your Linux server. What command would you enter into the shell configuration file to create this persistent alias?
You would enter one of the following commands in the shell configuration file: alias grepcolor="grep --color=36" alias grepcolor='grep --color=36'
You are currently in the /home/kcole/personal directory. What command would you enter to change to the /home/kcole parent directory?
You would enter the cd .. command to change to the /home/kcole parent directory.
Which of the following commands would you enter to view info node information about the sysctrl command?
You would enter the info sysctrl command to view the info node pages for the sysctrl command.
You want to remove the /home/kcole/documents directory with all its subdirectories and files without prompting. What command would you enter to accomplish this task?
You would enter the rm -rf /home/kcole/documents command to delete the documents directory with all its subdirectories and files without prompting.
Which of the following commands stores the output of the ls -a command in a shell variable named allfiles?
allfiles=$(ls -a) stores the output from the ls -a command in the shell variable allfiles. This is command substitution.
Which of the following commands gives the same results as cat < turbo?
cat turbo 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.
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
Which of the following commands displays the value of the LANG environmental variable currently set for the language the operating system uses?
echo $LANG 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 value of the variable.
Tim, a technician, creates a local variable named val and sets 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 val as an environment variable that would be available to the script?
export val=5000 will create an environment 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.
As a Linux script developer you are trying to debug a shell script that has the command ls -s in it. You suspect that an error is occurring, and want 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 you use?
ls -s &> ~/Friday
You are working on a Linux system and need more information about the uname command. What would you enter at the command prompt to learn about the uname command syntax and options?
man uname displays the man page for the uname command. A man page shows the command's syntax, options, and related files and commands.
Which of the following commands utilize command substitution?
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.
An IT technician has been given a work order to install the Apache web server on a system configured with a YUM repository. Which of the following commands will install the web server?
yum install httpd is used to install Apache on a system using a YUM repository.