Which of the following outputs could stem from the command last?
The last command in Linux is used to display the list of all the users logged in and out since the file/var/log/wtmpwas created1.The output of the last command shows the username, the terminal, the IP address, the login time and date, and the duration of the session for each record2. The option E is the only one that matches this format. The other options are not related to the last command. Option A shows a list of commands executed by a user. Option B shows the password change information for a user. Option C shows the last login information for a user. Option D shows the mount information for a filesystem.Reference:
Linux Essentials Version 1.6 Objectives3, Topic 1.4: Command Line Basics, Subtopic: Basic Shell Commands
Linux last Command Tutorial for Beginners (8 Examples)4
Linux Essentials Version 1.6 Exam Preparation Guide, Section 1.4: Command Line Basics, Page 16
Which of the following commands sets the variable USERNAME to the value 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 or unset 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.Reference:
Linux Essentials - Linux Professional Institute (LPI)
How to Set and List Environment Variables in Linux | Linuxize
Which of the following examples shows the general structure of a for loop in a shell script?
The general structure of a for loop in a shell script is as follows12:
for variable in list do commands done
The variable is the name of a loop counter or iterator that takes on the values of the items in the list. The list can be a sequence of words, numbers, filenames, or the output of a command. The commands are the body of the loop that are executed for each value of the variable. The do and done keywords mark the beginning and the end of the loop body.
The option C. for file in *.txt do echo $i done follows this structure, with the variable being file, the list being *.txt (which matches all the files with the .txt extension in the current directory), and the command being echo $i (which prints the value of the variable i, which is presumably set somewhere else in the script).
The other options are incorrect because:
A . for *.txt as file => echo $file uses an invalid syntax for a for loop. The as keyword is not part of the shell script syntax, and the => symbol is not a valid operator. The correct way to write this loop would be:
for file in *.txt do echo $file done
B . for *.txt ( echo $i ) uses an invalid syntax for a for loop. The parentheses are not part of the shell script syntax, and the loop body is missing the do and done keywords. The correct way to write this loop would be:
for i in *.txt do echo $i done
D . for ls *.txt exec {} ; uses an invalid syntax for a for loop. The ls command is not a valid variable name, and the exec {} ; is not a valid command. This looks like a mix of a for loop and a find command. The correct way to write this loop would be:
for file in *.txt do exec $file done
E . foreach @{file} { echo $i } uses an invalid syntax for a for loop. The foreach keyword is not part of the shell script syntax, and the @{file} and { echo $i } are not valid expressions. This looks like a mix of a for loop and a Perl syntax. The correct way to write this loop would be:
for file in * do echo $file done
Looping Statements | Shell Script - GeeksforGeeks
How do I write a 'for' loop in Bash? - Stack Overflow
Which of the following commands creates the ZIP archive poems.zip containing all files in the current directory whose names end in .txt?
The zip command is used to create compressed archive files that can contain one or more files or directories. The zip command takes the name of the archive file as the first argument, followed by the names of the files or directories to be included in the archive. You can also use wildcards to match multiple files or directories with a common pattern. For example, the command zip poems.zip *.txt will create the ZIP archive poems.zip containing all files in the current directory whose names end in .txt. The other commands are either invalid or do not perform the desired operation. The command zip *.txt > poems.zip will try to create an archive for each file ending in .txt and redirect the output to poems.zip, which is not a valid archive file. The command zcat *.txt poems.zip will try to decompress and concatenate the contents of the files ending in .txt and poems.zip, which is not a valid ZIP file. The command zip cfz poems.zip *.txt will fail because the options c, f, and z are not valid for the zip command. The command cat *.txt | zip poems.zip will try to read the contents of the files ending in .txt from the standard input and create an archive named poems.zip, but this will not preserve the file names or attributes of the original files.Reference:
Linux Essentials - Linux Professional Institute (LPI), section 3.1.1
3.1 Archiving Files on the Command Line - Linux Professional Institute Certification Programs, slide
Eric Peterson
1 month agoBrian Rodriguez
2 months agoJason Mitchell
3 months agoPaul Hall
3 months agoMichael Sanchez
4 months agoElizabeth Hernandez
4 months agoHarold Rodriguez
5 months agoRebecca Jackson
5 months agoBarbara Brown
6 months agoAmanda Robinson
6 months agoBrenda Garcia
7 months agoKevin Baker
6 months agoSandra Martinez
6 months agoStephen Sanchez
6 months agoChristopher Rodriguez
7 months agoPaul Flores
6 months agoJulio
7 months agoJacqueline
8 months agoHeidy
8 months agoMica
8 months agoMitzie
8 months agoClare
9 months agoKaitlyn
9 months agoFelice
9 months agoDarrin
9 months agoMarion
10 months agoFrank
10 months agoDenna
10 months agoKaycee
10 months agoDetra
10 months agoBettye
11 months agoFrancesco
11 months agoWillard
11 months agoLuis
11 months agoBenedict
12 months agoGabriele
12 months agoMalinda
1 year agoFrederica
1 year agoRashad
1 year agoMarta
1 year agoLorrine
1 year agoTawna
1 year agoRichelle
1 year agoTayna
1 year agoNobuko
1 year agoSkye
1 year agoFiliberto
1 year agoVince
1 year agoHeike
1 year agoDominque
1 year agoWillie
1 year agoEura
2 years agoMalcom
2 years agoJina
2 years agoDanilo
2 years agoMa
2 years agoWinifred
2 years agoBarney
2 years agoMyong
2 years agoLizbeth
2 years agoCarla
2 years agoRuth
2 years agoGeraldo
2 years agoJoye
2 years agoNickolas
2 years agoHeike
2 years agoStanton
2 years agoDalene
2 years agoStarr
2 years agoLoren
2 years agoSophia
2 years agoBernardo
2 years agoDelsie
2 years agoTasia
2 years agoKrissy
2 years agoRolland
2 years agoAdelina
2 years agoJanet
2 years agoLaila
2 years agoRodrigo
2 years agoAlyce
2 years agoGeorgene
2 years agoFranklyn
2 years agoCatarina
2 years agoMerilyn
2 years agoDesirae
2 years agoLore
2 years agoMaile
2 years agoVerdell
2 years ago