Which of the following commands sets the variable USERNAME to the value bob?
set USERNAME bob
$USERNAME==bob
var USERNAME=bob
USERNAME<=bob
USERNAME=bob
The correct command to set the variable USERNAME to the value bob is USERNAME=bob. This command assigns the string bob to the variable name USERNAME, using the equal sign (=) as the assignment operator. There is no space around the equal sign, and the variable name and value are case-sensitive. This command sets a shell variable, which is only valid in the current shell session. To make the variable an environment variable, which can be inherited by child processes and subshells, you need to use the export command, such as export USERNAME=bob. The other commands are not valid for setting variables in Linux. The set command is used to set orunset shell options and positional parameters, not variables. The $ sign is used to reference the value of a variable, not to assign it. The == sign is used for comparison, not assignment. The var keyword is not used in Linux, but in some other programming languages. The <= sign is used for redirection, not assignment. References:
Which of the following commands creates an archive filework.tarfrom the contents of the directory./
work/?
tar --new work.tar ./work/
tar –cf work.tar ./work/
tar –create work.tgz –content ./work/
tar work.tar < ./work/
tar work > work.tar
The correct command to create an archive file work.tar from the contents of the directory ./work/ is tar –cf work.tar ./work/. This command uses the -c option to create a new archive, the -f option to specify the file name, and the ./work/ argument to indicate the source directory. The other commands are incorrect for various reasons:
Which of the following is a protocol used for automatic IP address configuration?
NFS
LDAP
SMTP
DNS
DHCP
DHCP stands for Dynamic Host Configuration Protocol. It is a protocol that provides quick, automatic, and central management for the distribution of IP addresses within a network. It also configures other network information, such as the subnet mask, default gateway, and DNS server information, on the device1. DHCP uses a client/server architecture, where a DHCP server issues unique IP addresses and automatically configures the devices that request them2. DHCP allows devices to move freely from one network to another and receive an IP address automatically, which is helpful with mobile devices1.
The other options are not protocols used for automatic IP address configuration. NFS stands for Network File System, which is a protocol that allows a user to access and modify files over a network as if they were on their own computer. LDAP stands for Lightweight Directory Access Protocol, which is a protocol that provides access to a centralized directory service that stores information about users, groups, computers, and other resources on a network. SMTP stands for Simple Mail Transfer Protocol, which is a protocol that enables the sending and receiving of email messages over a network. DNS stands for Domain Name System, which is a protocol that translates domain names into IP addresses and vice versa. References:
Which of the following commands output the content of the file Texts 2.txt? (Choose two.)
cat 'Texts 2.txt’
cat -- Texts 2.txt
cat |Texts 2.txt|
cat 'Texts\ 2.txt’
cat Texts\ 2.txt
The correct commands to output the content of the file Texts 2.txt are A and E. These commands use the cat command, which stands for concatenate, to display the content of one or more files. The cat command can take one or more filenames as arguments and print their content to the standard output (usually the terminal screen)12. The commands A and E use different ways to deal with the space character in the filename. The space character is a special character in Linux that separates words and commands. To prevent the shell from interpreting the space as a word separator, the commands A and E use either of the following methods34:
The other options are incorrect because they use different syntax that do not output the content of the file. For example:
References: 1: How to Use Linux Cat Command (With Examples) - phoenixNAP 2: Cat command in Linux with examples - GeeksforGeeks 3: How to escape spaces in path during scp copy in Linux? - Stack Overflow 4: How to handle spaces in file names when using xargs on find results? - Ask Ubuntu
Which of the following commands sorts the output of the commandexport-logs?
export-logs < sort
export-logs > sort
export-logs & sort
export-logs | sort
export-logs <> sort
The sort command is used to sort the lines of a text file or the output of another command in alphabetical, numerical, or other order. The sort command has the following syntax: sort [options] [file…]. The file argument is the name of one or more files to be sorted. If no file is given, the sort command reads from the standard input, which is usually the keyboard or the output of another command.
The | (pipe) symbol is used to connect the output of one command to the input of another command. This allows the creation of pipelines of commands that process data sequentially. The pipe symbol has the following syntax: command1 | command2. The command1 argument is the name of the first command, whose output is sent to the input of the second command. The command2 argument is the name of the second command, which receives the output of the first command as its input.
Therefore, the command export-logs | sort sorts the output of the export-logs command in alphabetical order. The export-logs command is assumed to be a custom command that exports some logs to the standard output. The sort command receives the output of the export-logs command as its input and sorts it according to the default criteria, which is the first character of each line. The sorted output is then displayed on the screen or can be redirected to a file or another command.
The other options in the question are incorrect because they use the wrong symbols to connect the commands. The < (input redirection) symbol is used to read the input of a command from a file instead of the keyboard. The > (output redirection) symbol is used to write the output of a command to a file instead of the screen. The & (background) symbol is used to run a command in the background, which means the command does not wait for user input and allows the user to run other commands simultaneously. The <> (bidirectional redirection) symbol is used to read and write the input and output of a command from and to the same file. None of these symbols can be used to sort the output of the export-logs command. References:
What is the preferred source for the installation of new applications in a Linux based operating system?
The vendor's version management system
A CD-ROM disk
The distribution's package repository
The vendor's website
A retail store
The distribution’s package repository is the preferred source for the installation of new applications in a Linux based operating system. A package repository is a collection of software packages that are maintained by the distribution and can be easily installed, updated, or removed using a package manager. Package repositories offer several advantages, such as:
The other sources are not preferred because they may not offer these benefits and may cause problems with the system. The vendor’s version management system, the vendor’s website, or a CD-ROM disk may contain packages that are not compatible with the distribution or may conflict with other packages. A retail store may not have the latest or the most suitable packages for the system. References:
What is true about a recursive directory listing?
It includes the content of sub-directories.
It includes the permissions of the directory listed.
It includes details of file system internals, such as inodes.
It includes ownership information for the files.
It includes a preview of content for each file in the directory.
A recursive directory listing is a way of displaying the files and folders in a directory and all its sub-directories. The recursive option can be used with various commands, such as ls, find, or dir, to list the files recursively. For example, the command ls -R will list all the files and folders inthe current directory and any sub-directories, showing the hierarchy of the file system123 A recursive directory listing does not include the permissions, ownership, or file system details ofthe files, unless specified by other options. For example, the command ls -lR will list the files recursively and also show the permissions, ownership, size, and modification date of each file1 A recursive directory listing also does not include a preview of the content of each file, unless specified by other options. For example, the command ls -R --file-type will list the files recursively and also show the file type indicator, such as / for directories, * for executable files, @ for symbolic links, etc1 References: 1: ls (Unix) - Wikipedia 2: Recursively List all directories and files - Stack Overflow 3: Why is ls -R called “recursive” listing? - Ask Ubuntu
Which of the following statements are true regarding a typical shell script? (Choose two.)
It has the executable permission bit set.
It starts with the two character sequence #!.
It is located in /usr/local/scripts/.
It is located in /etc/bash/scripts/.
It is compiled into a binary file compatible with the current machine architecture.
A typical shell script is a text file that contains a series of commands or instructions that can be executed by a shell interpreter. A shell script usually has the executable permission bit set, which means that it can be run as a program by the user or another program. A shell script also starts with the two character sequence #!, which is called a shebang or a hashbang. This sequence tells the operating system which shell interpreter to use to run the script. For example, #!/bin/bash indicates that the script should be run by the bash shell. References:
What are the differences between hard disk drives and solid state disks? (Choose two correct answers.)
Hard disks have a motor and moving parts, solid state disks do not.
Hard disks can fail due to physical damage, while solid state disks cannot fail.
Solid state disks can store many times as much data as hard disk drives.
/dev/sdais a hard disk device while/dev/ssdais a solid state disk.
Solid state disks provide faster access to stored data than hard disks.
The main difference between hard disk drives (HDDs) and solid state drives (SSDs) is the way they store and access data. HDDs use a spinning disk (platter) and a moving head to read and write data, while SSDs use flash memory chips that have no moving parts. This makes SSDs faster, quieter, and more durable than HDDs, but also more expensive and less spacious. HDDs and SSDs are both I/O devices that can be used to boot the system and store data, but they have different advantages and disadvantages depending on the use case. References:
The file script.sh in the current directory contains the following content:
#!/bin/bash echo $MYVAR
The following commands are used to execute this script:
MYVAR=value
./script.sh
The result is an empty line instead of the content of the variable MYVAR. How should MYVAR be set in order to make script.sh display the content of MYVAR?
!MYVAR=value
env MYVAR=value
MYVAR=value
$MYVAR=value
export MYVAR=value
The reason why the script.sh does not display the content of the variable MYVAR is that the variable is not exported to the environment of the script. When a script is executed, it runs in a separate process that inherits the environment variables from the parent process, but not the shell variables. A shell variable is a variable that is defined and visible only in the current shell session, while an environment variable is a variable that is exported to the environment and visible to all processes that run in that environment1.
To make a shell variable an environment variable, we need to use the export command. The export command takes a shell variable name and adds it to the environment of the current shell and any subshells or processes that are created from it2. For example, to export the variable MYVAR with the value value, we can use:
export MYVAR=value
This will make the variable MYVAR available to the script.sh when it is executed, and the script will print the value of MYVAR as expected. Alternatively, we can also use the export command with the -n option to remove a variable from the environment, or with the -p option to list all the environment variables2.
The other options are not valid ways to set MYVAR as an environment variable. The !MYVAR=value option is not a valid syntax for setting a variable in bash. The env MYVAR=value option will run the env command with the MYVAR=value argument, which will print the environment variables with the addition of MYVAR=value, but it will not affect the current shell or the script.sh3. The MYVAR=value option will set MYVAR as a shell variable, but not as an environment variable, so it will not be visible to the script.sh1. The $MYVAR=value option will try to set the variable whose name is the value of MYVAR to the value value, which is not what we want4. References:
Which of the following statements is true about Free Software?
It is developed by volunteers only.
It may be modified by anyone using it.
It must always be available free of charge.
It only runs on Linux.
It is only distributed as a compiled binary.
The correct statement about Free Software is that it may be modified by anyone using it. This is one of the four essential freedoms of Free Software, which are: the freedom to run the program as you wish, for any purpose; the freedom to study how the program works, and change it so it does your computing as you wish; the freedom to redistribute copies so you can help your neighbor; and the freedom to distribute copies of your modified versions to others1. Access to the source code is a precondition for these freedoms1.
The other statements are false for the following reasons:
References:
What is true about the su command?
It is the default shell of the root account.
It can only be used by the user root.
It runs a shell or command as another user.
It changes the name of the main administrator account.
It locks the root account in specific time frames.
The su command stands for substitute user or switch user. It allows you to run a shell or a command as another user, usually the superuser or root. To use the su command, you need to know the password of the target user. For example, if you want to switch to the root user, you can type su - and enter the root password. This will give you a root shell, where you can execute commands with administrative privileges. To exit the root shell, you can type exit or press Ctrl-D. The su command is not the default shell of the root account, nor can it only be used by the root user. It can be used by any user who knows the password of another user. The su command does not change the name of the main administrator account, which is always root on Linux systems. The su command also does not lock the root account in specific time frames, although there are other ways to do that, such as using the pam_time module. References:
What is the purpose of the PATH environment variable?
It allows the execution of commands without the need to know the location of the executable.
It increases security by preventing commands from running in certain locations.
It specifies the location of a user's home directory.
It indicates the location of the default shell to be used when a user logs in.
It contains the absolute path to the current directory.
The PATH environment variable is a special variable that contains a list of directories that the system searches when looking for a command to execute12. The purpose of the PATH variable is to make it easier and faster for users to run commands without having to type the full path to the executable file. For example, if you want to run the ls command, which is located in the /bin directory, you don’t have to type /bin/ls every time. You can just type ls, and the system will find the executable file in the /bin directory, which is one of the directories in the PATH variable. The PATH variable can be viewed with the echo command12:
$ echo $PATH
The PATH variable can also be modified by adding or removing directories, either temporarily or permanently, depending on the user’s needs12. For example, if you have acustom script or program in your home directory, and you want to run it from anywhere, you can add your home directory to the PATH variable with the export command12:
$ export PATH=$PATH:~/myprogram
This will append your home directory to the end of the PATH variable, and the system will search it last when looking for a command. To make this change permanent, you need to edit a configuration file, such as ~/.bashrc or ~/.profile, and add the export command there12.
References:
Which of the following commands shows the absolute path to the current working directory?
who
cd ..
pwd
ls -l
cd ~/home
The command pwd stands for “print working directory”. It will print the absolute path of the current working directory to the terminal. For example, if we are currently in the /home/user/directory, it will print out that exact path1. The pwd command is useful for finding out where we are in the file system hierarchy and for verifying the location of files and directories2.
The other options are not commands that show the absolute path to the current working directory. The who command shows the users who are currently logged in to the system3. The cd … command changes the current working directory to the parent directory of the current one2. The ls -l command lists the files and directories in the current working directory in a long format, which shows the permissions, ownership, size, date, and name of each file and directory2. The cd ~/home command changes the current working directory to the /home directory under the user’s home directory, which may or may not exist2. References:
What is the UID of the user root?
1
-1
255
65536
0
The UID of the user root is always 0 on Linux systems. This is because the kernel uses the UID 0 to check for the superuser privileges and grant access to all system resources. The name of the user account with UID 0 is usually root, but it can be changed or have aliases. However, some applications may expect the name root and not work properly with a different name. The UID 0 is reserved for the root user and cannot be assigned to any other user. The UID 0 is stored in the /etc/passwd file along with other user information. References:
What is true about the owner of a file?
Each file is owned by exactly one user and one group.
The owner of a file always has full permissions when accessing the file.
The user owning a file must be a member of the file’s group.
When a user is deleted, all files owned by the user disappear.
The owner of a file cannot be changed once it is assigned to an owner.
In Linux, every file and directory is associated with an owner and a group. The owner is the user who created the file or directory, and the group is the group to which the owner belongs. Therefore, each file is owned by exactly one user and one group. This is true for option A. The other options are false for the following reasons:
Which of the following commands will search for the filefoo.txtunder the directory/home?
search /home –file foo.txt
search /home foo. txt
find /home – file foo.txt
find /home –name foo.txt
find /home foo.txt
The correct command to search for the file foo.txt under the directory /home is find /home –name foo.txt. This command uses the find command, which is used to search for files and directories that match certain criteria. The first argument, /home, specifies the starting point of the search. The second argument, -name, indicates that the search is based on the name of the file or directory. The third argument, foo.txt, is the name of the file to be searched for. The find command will recursively search all the subdirectories under /home and print the path of any file or directory that matches the name foo.txt.
The other commands are incorrect for various reasons:
References: : find command in Linux with examples - GeeksforGeeks : 15 Super Useful Examples of Find Command in Linux
What is a Linux distribution?
The Linux file system as seen from the root account after mounting all file systems.
A bundling of the Linux kernel, system utilities and other software.
The set of rules which governs the distribution of Linux kernel source code.
An operating system based on Linux but incompatible to the regular Linux kernel.
A set of changes to Linux which enable Linux to run on another processor architecture.
A Linux distribution is a collection of software that is based on the Linux kernel and can be installed on a computer or a device to create a functional operating system. A Linux distribution typically includes the Linux kernel, a set of system utilities and libraries, a graphical user interface (GUI), a package manager, and various applications and services. A Linux distribution may also include additional software or features that are specific to the distribution’s goals, target audience, or philosophy. For example, some Linux distributions are designed for desktop users, while others are optimized for servers, embedded systems, or security. Some Linux distributions are based on other Linux distributions, while others are developed independently. Some Linux distributions are free and open source, while others are proprietary or commercial. Some Linux distributions are popular and widely used, while others are niche or experimental. Some examples of Linux distributions are Ubuntu, Fedora, Debian, Mint, Arch, and Red Hat. References:
Most commands on Linux can display information on their usage. How can this information typically be displayed?
By running the command with the option /? or /??.
By running the command with the option ?! or ?=!.
By running the command with the option /doc or /documentation.
By running the command with the option -h or --help.
By running the command with the option -m or --manpage.
Most commands on Linux can display information on their usage by running the command with the option -h or --help. This option shows a brief summary of the command syntax, options, arguments, and examples. For example, running ls -h or ls --help will display the usage information for the ls command, which lists files and directories. The -h or --help option is a standard convention for most Linux commands, and it is useful for learning how to use a command or checking its available options. However, some commands may not support this option, or may use a different option to display usage information. In that case, you can use the man command to access the manual page for the command, which provides more detailed information on the command usage, description, options, arguments, examples, and references. For example, running man ls will display the manual page for the ls command. The man command is one of the applications covered in the Linux Essentials certification program from the Linux Professional Institute (LPI). References:
The current directory contains the following file:
-rw-r—r— 1 root exec 24551 Apr 2 12:36 test.sh
The file contains a valid shell script, but executing this file using./test.shleads to this error:
bash: ./test.sh: Permission denied
What should be done in order to successfully execute the script?
The file’s extension should be changed from .shto.bin.
The execute bit should be set in the file’s permissions.
The user executing the script should be added to theexecgroup.
The SetUID bit should be set in the file’s permissions
The script should be run using#!./test. shinstead of./test.sh.
The execute bit in Linux is a permission bit that allows the user to run an executable file or enter a directory. For regular files, such as scripts or binaries, the execute bit must be set for the user to run them. For directories, the execute bit allows the user to access the files and subdirectories inside. Therefore, to successfully execute the script test.sh, the execute bit should be set in the file’s permissions. This can be done by using the chmod command with the +x option, for example: chmod +x test.sh. The other options are either irrelevant or incorrect. The file’s extension does not affect its executability, only its association with a program. The user executing the script does not need to be in the exec group, as long as the user has the execute permission on the file. The SetUID bit is a special permission bit that allows the user to run the file as the file’s owner, regardless of the user’s identity. This is not necessary for executing the script, and may pose a security risk. The #!./test.sh syntax is invalid, as the #! is used to specify the interpreter for the script, not the script itself. References:
Which of the following commands extracts the contents of the compressed archive file1.tar.gz?
tar -czf file1.tar.gz
ztar file1.tar.gz
tar -xzf file1.tar.gz
tar --extract file1.tar.gz
detar file1.tar.gz
The correct command to extract the contents of the compressed archive file1.tar.gz is tar -xzf file1.tar.gz. This command uses the following options:
The other commands are incorrect for the following reasons:
References:
Which command adds the new usertuxand creates the user’s home directory with default configuration
files?
defaultuser tux
useradd –m tux
usercreate tux
useradd –o default tux
passwd –a tux
The useradd command in Linux is used to create new user accounts on the system1. The -m option tells the command to create the user’s home directory as /home/username and copy the files from /etc/skel directory to the user’s home directory2. The /etc/skel directory contains the default configuration files for new users3. Therefore, the command useradd -m tux will add the new user tux and create the user’s home directory with default configuration files. The other options are either invalid or do not create the user’s home directory. References:
Which of the following directories must be mounted with read and write access if it resides on its own dedicated file system?
/opt
/lib
/etc
/var
/usr
The /var directory must be mounted with read and write access if it resides on its own dedicated file system. The reason is that the /var directory contains files and directories that are expected to change in size and content as the normal operation of the system progresses, such as logs, spool files, and temporary files1. Therefore, the /var directory needs to have enough space and permission to accommodate these changes. If the /var directory is mounted as read-only, some system services and applications may fail to start or function properly2.
The other options are not directories that must be mounted with read and write access if they reside on their own dedicated file system. The /opt directory contains optional or third-party software packages that are not part of the default installation1. The /lib directory contains libraries and kernel modules that are essential for the binaries in /bin and /sbin directories1. The /etc directory contains configuration files for the system and applications1. The /usr directory contains user-related programs, libraries, documentation, and data1. These directories are usually mounted as read-only to prevent accidental or malicious modification of their contents3. References:
How is a new Linux computing instance provisioned in an laaS cloud?
The standard Linux installer has to be run through a remote console.
After buying a Linux distribution, its vendor delivers it to a cloud instance.
The installation has to be prepared in a local virtual machine which is then copied to the cloud.
The cloud hosting organization provides a set of pre-prepared images of popular Linux distributions.
A provider-specific configuration file describing the desired installation is uploaded to the cloud provider.
In an Infrastructure as a Service (IaaS) cloud, the provider offers virtualized computing resources such as servers, storage, and network over the internet. The user can provision and manage these resources according to their needs. One of the common ways to provision a new Linux computing instance in an IaaS cloud is to use a pre-prepared image of a Linux distribution provided by the cloud hosting organization. An image is a snapshot of a virtual machine that contains the operating system and other software components. The user can choose from a variety of images that suit their requirements and launch a new instance from the image. This way, the user does not have to install and configure the Linux operating system from scratch, which saves time and effort. Some examples of cloud hosting organizations that provide pre-prepared images of popular Linux distributions are Amazon Web Services (AWS), Microsoft Azure, Google Cloud Platform (GCP), and DigitalOcean. References: Linux Essentials - Topic 108: Cloud Computing and Linux Essentials - Topic 108: Cloud Computing - Exam Objectives
Copyright © 2021-2024 CertsTopics. All Rights Reserved