Free LPI 102-500 Exam Questions (page: 4)

What command displays all aliases defined in the current shell? (Specify the command without any path information)

  1. alias, alias -p

Answer(s): A

Explanation:

The alias command is used to create, list, or remove aliases in the current shell. An alias is a short name that refers to another command, usually with some options or arguments. Aliases are useful for saving typing time, avoiding spelling errors, or customizing the behavior of commands. To list all the aliases defined in the current shell, we can use the alias command without any arguments. This will print the aliases in the format of alias name='command'123. For example:
$ alias alias cp=`cp -i' alias l=`ls -CF' alias la=`ls -A' alias ll=`ls -alF' alias mv=`mv -i' alias rm=`rm -i' The output shows that some common commands, such as cp, mv, and rm, have aliases that add the - i option, which prompts the user before overwriting or deleting files. The l, la, and ll aliases are shortcuts for different variations of the ls command, which lists files and directories123.


Reference:

1: List All Available Commands and Aliases in Linux - Baeldung
2: get all aliases in linux shell - Stack Overflow
3: How to list all aliases on Linux - Linux Tutorials - Learn Linux Configuration



Which of the following are requirements in order to run a shell script like a regular command from anywhere in the filesystem? (Choose THREE correct answers.)

  1. The user issuing the command must be in the group script.
  2. The script file must be found in the $PATH.
  3. The script file must have the executable permission bit set.
  4. The script must begin with a shebang-line (#!) that points to the correct interpreter.
  5. The file system on which the script resides must be mounted with the option scripts.

Answer(s): B,C,D

Explanation:

In order to run a shell script like a regular command from anywhere in the filesystem, the following requirements must be met:
The script file must be found in the $PATH. The $PATH is a variable that contains a list of directories where the shell looks for executable files when a command is issued. If the script file is not in one of these directories, the shell will not be able to find it unless the full path is specified. The script file must have the executable permission bit set. This is a file attribute that determines whether the file can be executed by the user, the group, or others. The executable permission bit can be set using the chmod command, for example: chmod +x script.sh. The script must begin with a shebang-line (#!) that points to the correct interpreter. This is a special line at the beginning of the script that tells the shell which program to use to run the script, such as #!/bin/bash for bash scripts, or #!/usr/bin/perl for perl scripts. The shebang-line must match the exact path of the interpreter, otherwise the script will not run. The other options are not requirements for running a shell script like a regular command. There is no such group as script, and the file system mount option scripts does not exist.


Reference:

[LPI Linux Essentials - Topic 105: Shells, Scripting and Data Management] [LPI Linux Professional - Exam 102 Objectives - Topic 105: Shells and Shell Scripting]



Which of the following SQL statements will select the fields name and address from the contacts table?

  1. SELECT (name, address) FROM contacts;
  2. SELECT (name address) FROM contacts;
  3. SELECT name, address FROM contacts;
  4. SELECT name address FROM contacts;

Answer(s): C

Explanation:

The correct syntax for selecting specific columns from a table in SQL is to use the SELECT keyword followed by a comma-separated list of column names and then the FROM keyword followed by the table name. Therefore, the only option that follows this syntax is C. SELECT name, address FROM contacts; The other options are incorrect because they either use parentheses around the column names, which are not needed, or they omit the comma between the column names, which causes a syntax error.


Reference:

https://www.sqltutorial.org/sql-select/

https://www.w3schools.com/mysql/mysql_select.asp



Which directory in /etc is used to keep a sample copy of files and directories for when a new user has a home directory created? (Please provide the full path)

  1. /etc/skel,
    /etc/skel/

Answer(s): A

Explanation:

The /etc/skel directory is used to keep a sample copy of files and directories for when a new user has a home directory created. The /etc/skel directory contains files and directories that are automatically copied over to a new user's home directory when such user is created by the useradd or adduser command. The /etc/skel directory allows the system administrator to create a standard environment for all new users on the system. For example, the /etc/skel directory may contain a default .bashrc file that sets some aliases and environment variables for the new user, or a default .profile file that executes some commands at login. The /etc/skel directory may also contain subdirectories such as .ssh or .config that store configuration files for various applications or services. The name /etc/skel comes from the word "skeleton", as it provides a basic structure for the new user's home directory.


Reference:

[Linux User Administration]
[Linux Directory Structure]



Which of the following configuration files should be modified to set default shell variables for all users?

  1. /etc/bashrc
  2. /etc/profile
  3. ~/.bash_profile
  4. /etc/.bashrc

Answer(s): B

Explanation:

The /etc/profile file is a configuration file that is read by the Bash shell when a user logs in. It contains commands and settings that apply to all users of the system, such as environment variables, PATH information, terminal settings, and security commands. Environment variables are variables that affect the behavior of programs and processes. For example, the PATH variable defines the directories where the shell looks for executable files, and the JAVA_HOME variable defines the location of the Java installation. The /etc/profile file can also source other files from the /etc/profile.d/ directory, which can contain additional scripts for setting environment variables or other system-wide settings. The /etc/profile file is the best option for setting default shell variables for all users, as it is executed before any user-specific files. The other options are not suitable for this purpose, because:
/etc/bashrc is a configuration file that is read by the Bash shell when it is started as an interactive non-login shell. It contains commands and settings that apply to all interactive shells of the system, such as aliases, functions, and prompt settings. It is not executed when the shell is started as a login shell, which is the case when a user logs in. Therefore, it is not a good place to set default shell variables for all users.
~/.bash_profile is a configuration file that is read by the Bash shell when it is started as a login shell for a specific user. It contains commands and settings that apply only to that user, such as environment variables, PATH information, and startup programs. It can also source other files, such as ~/.bashrc, which is read by the shell when it is started as an interactive non-login shell for that user. It is not a good place to set default shell variables for all users, as it only affects the user who owns the file.
/etc/.bashrc is not a valid configuration file for the Bash shell. The dot (.) at the beginning of the file name indicates that it is a hidden file, which means that it is not visible by default in the file system. The Bash shell does not look for this file when it is started, and it does not execute any commands or settings from it. Therefore, it is not a good place to set default shell variables for all users.



Which of the following is the best way to list all defined shell variables?

  1. env
  2. set
  3. env -a
  4. echo $ENV

Answer(s): B

Explanation:

The set command is used to display or modify the shell variables and functions in the current shell.
When used without any arguments, it prints the names and values of all shell variables, including environment variables and user-defined variables, in alphabetical order. The output also includes the shell options and the positional parameters. The set command can be used in any POSIX-compliant shell, such as bash, zsh, ksh, etc123.
The other options are not correct because:
env is used to print or modify the environment variables, not the shell variables. It does not show the user-defined variables or the shell options. It can also be used to run a command in a modified environment45.
env -a is an invalid option for the env command. The -a option is not supported by the env command in any standard or common implementation45.
echo $ENV is used to print the value of the environment variable ENV, not the list of all shell variables. The ENV variable is usually set to the name of a file that contains commands or aliases to be executed by the shell. It is mainly used by the ksh and some versions of bash .


Reference:

1: How can I list all shell variables? - Unix & Linux Stack Exchange
2: 2.1 Command Line Basics - Linux Professional Institute Certification ...
3: set - The Open Group Base Specifications Issue 7, 2018 edition
4: How to set and list environment variables on Linux
5: env - The Open Group Base Specifications Issue 7, 2018 edition : What is the difference between .bash_profile and .bashrc? - Unix & Linux Stack Exchange : ENV - The Open Group Base Specifications Issue 7, 2018 edition



Which command allows you to make a shell variable visible to subshells?

  1. export $VARIABLE
  2. export VARIABLE
  3. set $VARIABLE
  4. set VARIABLE
  5. env VARIABLE

Answer(s): B

Explanation:

The command that allows you to make a shell variable visible to subshells is export VARIABLE. This command turns the variable into a global or environment variable, which means it can be accessed by any child process or subshell that inherits the environment of the parent shell. The syntax of the export command does not require a dollar sign ($) before the variable name, unlike when referencing the value of the variable. The other commands are either invalid or do not affect the visibility of the variable to subshells. The set command can be used to assign values to variables, but it does not export them. The env command can be used to run a command in a modified environment, but it does not change the environment of the current shell.


Reference:

[LPI Linux Essentials - Topic 105: Shells, Scripting and Data Management] [LPI Linux Professional - Exam 102 Objectives - Topic 105: Shells and Shell Scripting] What is a Subshell? - Linux Bash Shell Scripting Tutorial Wiki - nixCraft What is Subshell in Linux? [Explained]



Which of the following words is used to restrict the records that are returned from a SELECT query based on a supplied criteria for the values in the records?

  1. LIMIT
  2. FROM
  3. WHERE
  4. IF

Answer(s): C

Explanation:

The correct keyword for restricting the records that are returned from a SELECT query based on a supplied criteria for the values in the records is WHERE. The WHERE clause is used to filter records based on one or more conditions. The syntax of the WHERE clause is:
SELECT column1, column2, ... FROM table_name WHERE condition; The condition can be a logical expression that evaluates to true, false, or unknown. The condition can also use comparison operators, logical operators, and wildcards to specify the criteria. For example, the following query selects all the records from the employees table where the salary is greater than 50000:
SELECT * FROM employees WHERE salary > 50000;
The other options are incorrect because they have different purposes in SQL:
LIMIT is used to specify the maximum number of records to return from a query. For example, the following query returns only the first 10 records from the employees table:
SELECT * FROM employees LIMIT 10;
FROM is used to specify the table or tables from which to retrieve data. For example, the following query selects all the columns from the employees table:

SELECT * FROM employees;
IF is used to execute a block of code conditionally. For example, the following query updates the salary of an employee based on their performance:
UPDATE employees SET salary = IF(performance = `excellent', salary * 1.1, salary) WHERE employee_id = 123;


Reference:

https://bing.com/search?q=SQL+statements+restrict+records+based+on+criteria https://stackoverflow.com/questions/11611931/sql-query-to-select-records-based-on-criteria






Post your Comments and Discuss LPI 102-500 exam prep with other Community members:

102-500 Exam Discussions & Posts