LX4 Flashcards

1
Q

How could one search for the file foo.txt under 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

A
  • Find /home -name foo.txt

The correct answer is “find /home -name foo.txt”. This is because the “find” command is used to search for files and directories within a specified directory. The “-name” option is used to search for files with a specific name, in this case “foo.txt”. The “/home” argument specifies the directory in which to search for the file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
1
Q

What is the output of the following command? tail -n 20 test.txt
The first 20 lines of test.txt
The last 20 lines of test.txt omitting the blank lines
The last 20 lines of test.txt with line numbers
The last 20 lines of test.txt including the blank lines

A
  • The last 20 lines of test.txt including the blank lines

The command “tail -n 20 test.txt” is used to display the last 20 lines of the file “test.txt”. It includes both the non-blank lines and the blank lines present in the file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Which of the following statements may be used to access the second command line argument to a script?
“ARG$2”
$1
“$2”
“$1”

A
  • “$2”

The correct answer is “$2” because in most programming languages, including shell scripting, the dollar sign ($) followed by a number is used to access command line arguments. In this case, “$2” would refer to the second command line argument passed to the script.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Which command displays the list of groups to which a user belongs?
Whoami
Isgroup
Who
Id

A
  • Id

The id command in Unix/Linux displays information about the user and the groups to which the user belongs. When you run the id command, it provides the user ID, group ID, and the list of groups the user is a member of. The whoami command only shows the current logged-in username, who displays information about all users currently logged into the system, and Isgroup is not a standard command in Unix/Linux.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Which is a suitable command to find the next appearance of the word hidden in a man page being viewed from the command line?
Find hidden
/? hidden
CTRL-F hidden
/hidden

A
  • /hidden

The command “/hidden” is the correct answer because it is the syntax used to search for the next appearance of the word “hidden” in a man page being viewed from the command line. By typing “/hidden” and pressing enter, the command line will search for the next occurrence of the word “hidden” on the man page.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How can the normal output of a command be written to a file while discarding the error output?
Command>2>file &1>/dev/null
Command /dev/null
Command>2>discard-error>file
Command> /dev/null 2&>1 output
Command > output.txt 2>/dev/null

A
  • Command > output.txt 2>/dev/null

command: The command whose output you want to capture.

> : Redirects the standard output (stdout) of the command to a file named output.txt.

2>/dev/null: Redirects the standard error output (stderr) of the command to /dev/null, which is a special file that discards any data written to it.

This way, only the normal output of the command will be written to the output.txt file, and any error output will be discarded.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

When typing a long command line at the shell, what single character can be used to split a command across multiple lines?

A
  • \

The backslash () character can be used to split a command across multiple lines when typing a long command line at the shell. This character is known as the line continuation character and it allows the command to continue on the next line, making it easier to read and manage long command lines.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Given the following directory permissions:

drwxrwxrwt 14 root 36864 2012-03-02 11:17 tmp

What is the letter t at the end of drwxrwxrwt indicate?

It is the sticky bit that causes all commands in this directory to be launched as a root.

It means that even though the directory is global writable only the owner can delete their own files.

It makes the directory accessible for everybody.

It indicates that this directory contains only temporary files that may be deleted.

It is a temporary bit that prevents launching commands in this directory

A
  • It means that even though the directory is global writable only the owner can delete their own files.

The letter “t” at the end of “drwxrwxrwt” indicates the sticky bit. This means that even though the directory is globally writable, only the owner of a file within the directory can delete their own files. This is a security measure that prevents unauthorized deletion of files by other users.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Which of the following commands can be used to view a file and do search operations within it while viewing the contents?
Less
Find
Grep
Report
See

A
  • Less

The less command is a versatile tool for viewing file content in a terminal. It provides navigation options like scrolling, paging, and searching within the displayed text. Unlike commands like cat which display the entire file at once, less offers a controlled view, especially useful for large files. It also allows for searching specific terms or patterns using regular expressions, making it a preferred choice for interactive file viewing and analysis.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

A Linux computer has no access to the Internet. Which command displays information about the network gateway for the system?
Traceroute
Ifconfig
Gateway
Route
Ipconfig

A
  • Route

The correct answer is “route”. The “route” command displays information about the network gateway for the system. It shows the routing table, which includes information about the network destinations and the corresponding gateway addresses. This command is commonly used in Linux systems to troubleshoot network connectivity issues and to manage the routing configuration.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Which of the following commands will output all of the lines that contain either the string Fred or fred? (Select all that apply)
Grep -v fred data_file
Grep ‘[f]red’ data_file
Egrep fred data_file
Grep ‘[Ff]red’ data_file
Grep -i fred data_file

A
  • Grep ‘[Ff]red’ data_file
  • Grep -i fred data_file

To output all lines containing either the string “Fred” or “fred,” you can use the following commands:

grep ‘[Ff]red’ data_file - This command matches both “Fred” and “fred” by using a character class [Ff] that allows either uppercase “F” or lowercase “f”.

grep -i fred data_file - The -i flag makes the search case-insensitive, matching “Fred”, “fred”, or any other case variation.

The other commands do not correctly match both “Fred” and “fred”:

grep -v fred data_file: This will output lines that do not contain “fred.”

grep ‘[f]red’ data_file: This matches only “fred” because it does not account for uppercase “F.”

egrep fred data_file: This matches only “fred” in lowercase.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Which of the following commands will create an archive file, named backup.tar, containing all the files from the directory /home?
Tar /home backup.tar
Tar -cf /home backup.tar
Tar -xf /home backup.tar
Tar -xf backup.tar /home
Tar -cf backup.tar /home

A
  • Tar -cf backup.tar /home

The correct answer is “tar -cf backup.tar /home”. This command uses the tar utility with the -cf options to create a new archive file named backup.tar. The /home directory is specified as the source directory from which all files will be included in the archive.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the output of the following command? for token in a b c; do echo -n ${token} done
Anbncn
Abc
$token$token$token
{a}{b}{c}
A b c

A
  • Abc

The for loop iterates over the tokens a, b, and c.

The echo -n ${token} command prints each token without a newline.

Therefore, the tokens a, b, and c are printed consecutively on the same line, resulting in the output abc.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Which of the following applications are used to play an MP3 file on a Linux system? Choose three answers
Xara Xtreme
Banshee
LibreOffice Player
Amarok
Audacious

A
  • Banshee
  • Amarok
  • Audacious

Banshee, Amarok, and Audacious are all applications that can be used to play an MP3 file on a Linux system. Banshee is a popular media player that supports various formats including MP3. Amarok is another feature-rich music player that can handle MP3 files. Audacious is a lightweight audio player that also supports MP3 playback. These applications provide users with options to manage and play their music files on a Linux system.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Which statement about the directory /etc/skel are correct? (Choose two answers)

The personal settings of root are in this directory

The files from the directory are copied to the home directory of the new user when starting the system

The files from the directory are copied to the home directory of the new user when the account is created

The directory contains a default set of configuration files used by the useradd command

The directory contains the global settings for the Linux system

A
  • The files from the directory are copied to the home directory of the new user when the account is created
  • The directory contains a default set of configuration files used by the useradd command

The directory /etc/skel contains a default set of configuration files used by the useradd command. When a new user account is created, the files from this directory are copied to the home directory of the new user. This ensures that the new user has a set of default configuration files and settings. However, the directory does not contain the personal settings of root and it does not contain the global settings for the Linux system.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Which of the following are correct commands for changing the current directory to the user’s home? (Select all that applies)
Cd /home
Cd ~
Cd ..
Cd
Cd /

A
  • Cd ~
  • Cd

The correct commands for changing the current directory to the user’s home directory are:

cd ~ - The tilde ~ represents the user’s home directory.

cd - Without any arguments, cd will take you to the user’s home directory.

16
Q

The output of the program date should be saved in the variable actdat. What is the correct statement?
Actdat=$(date)
Set actdat=’date’
Date | acdat
Date > $actdat
Actdat=date

A
  • Actdat=$(date)

In a Linux shell script, you can use the date command to retrieve the current date and time. To save the output of this command into a variable named actdat, you can use command substitution, denoted by $(…).

17
Q

Which of the following commands moves the directory ~/summer-vacation and its content to ~/vacation/2011?
Mv ~/vacation/2011 ~/summer-vacation
Move -R ~/summer-vacation ~/vacation/2011
Mv /home/summer-vacation /home/vacation/2011
Mv ~/summer-vacation ~/vacation/2011
Mv -R ~/summer-vacation ~/vacation/2011

A
  • Mv ~/summer-vacation ~/vacation/2011

The correct answer is “mv ~/summer-vacation ~/vacation/2011”. This command uses the “mv” command to move the directory ~/summer-vacation and its contents to ~/vacation/2011. The “~” symbol represents the home directory, so this command moves the “summer-vacation” directory from the home directory to the “vacation/2011” directory within the home directory.

18
Q

Which command will archive /home and its content to /mnt/backp? Choose two correct answers.
Cp -ar /home /mnt/backp
Mv /home /mnt/backp
Sync -r /home /mnt/backp
Tar -cf /mnt/backup/archive.tar /home
Copy -r /home /mnt/backp

A
  • Cp -ar /home /mnt/backp
  • Tar -cf /mnt/backup/archive.tar /home

cp -ar /home /mnt/backp: This command copies the /home directory and all its contents recursively to /mnt/backp, preserving file attributes.

tar -cf /mnt/backp/archive.tar /home: This command creates a tar archive of the /home directory and saves it as archive.tar in the /mnt/backp directory.

These commands effectively archive or copy the /home directory as required.

19
Q

Which of the following commands will set the variable text to olaf is home? (Select two answers)
Text=’olaf is home’
Text=$olaf is home
Text=”olaf is home”
Text==’olaf is home’
Text==”olaf is home”

A
  • Text=’olaf is home’
  • Text=”olaf is home”

These commands assign the string “olaf is home” to the variable text. The single or double quotes are used to handle spaces and special characters in the string. The other commands you listed are not correct for this purpose. For example, text=olaf\ is\home would assign the string “olaf ishome” to the variable text, not “olaf is home”. And text=$olaf is home would try to assign the value of the variable olaf followed by the string “is home” to the variable text, which is not what you want. Finally, $text=’olaf is home’ and text==’olaf is home’ are not valid syntax for assigning a value to a variable.