Linux Foundations_LPI_Guide Flashcards

1
Q

How is Debian GNU/Linux different from Ubuntu? Name two aspects.

A

The major difference
is the complexity of the user configuration that Ubuntu doesn’t require during the installation
process.

Another difference would be the stability of each distribution. Debian is considered to be more
stable compared to Ubuntu. This is because Debian receives fewer updates that are tested in
detail and the entire operating system is more stable. On the other hand, Ubuntu enables the
user to use the latest releases of software and all the new technologies.

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

What are the most common environments/platforms Linux is used for? Name three different
environments/platforms and name one distribution you can use for each.

A

smartphone, desktop and server. On smartphones, it can be used by distributions such as Android. On desktop and server, it can be
used by any distribution that is mostly suitable with the functionality of that machine, from
Debian, Ubuntu to CentOS and Red Hat Enterprise Linux.

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

You are planning to install a Linux distribution in a new environment. Name four things that
you should consider when choosing a distribution.

A

considered is cost,
performance,
scalability,
how stable it is
the hardware demand of the system.

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

Name three devices that the Android OS runs on, other than smartphones.

A

smart TVs,
tablet computers,
Android Auto and
smartwatches.

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

Explain three major advantages of cloud computing.

A

flexibility,
easy to recover
low use cost.
Cloud based services are easy to implement and scale, depending on the business
requirements.
It has a major advantage in backup and recovery solutions, as it enables
businesses to recover from incidents faster and with repocussion
subscription-based model

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

Considering cost and performance, which distributions are mostly suitable for a business that
aims to reduce licensing costs, while keeping performance at its highest? Explain why

A

CentOS.
incorporates all Red Hat products, which are further used within their commercial operating
system,
while being free to use.
Similarly, Ubuntu LTS releases guarantee support for a longer
period of time.
The stable versions of Debian GNU/Linux are also often used in enterprise
environments

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

What are the major advantages of the Raspberry Pi and which functions can they take in
business?

A

Raspberry Pi is small in size
is low cost
and can handle web traffic and many other functionalities.
It can be used as a server, a firewall
and can be used as the main board for robots, and many other small devices

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

What range of distributions does Amazon Cloud Services and Google Cloud offer? Name at least
three common ones and two different ones.

A

The common distributions between Amazon and Google Cloud Services are Ubuntu, CentOS
and Red Hat Enterprise Linux. Each cloud provider also offers specific distributions that the
other one doesn’t. Amazon has Amazon Linux and Kali Linux, while Google offers the use of
FreeBSD and Windows Servers.

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

Guided Exercises
1. For each of the following commands, identify whether it is associated with the Debian
packaging system or the Red Hat packaging system:
dpkg
rpm
apt-get
yum
dnf

A

dpkg ——–>Debian packaging system
rpm ———> Red Hat packaging system
apt-get—–> Debian packaging system
yum———> Red Hat packaging system
dnf ———>Red Hat packaging system

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

Define dnf

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

Which command could be used to install Blender on Ubuntu? After installation, how can the
program be executed?

A

The command apt-get install blender. The package name should be specified in
lowercase. The program can be executed directly from the terminal

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

Which application from the LibreOffice suite can be used to work with electronic
spreadsheets?

A

CALC

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

Which open-source web browser is used as the basis for the development of Google Chrome?

A

Chromium

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

SVG is an open standard for vector graphics. Which is the most popular application for editing
SVG files in Linux systems?

A

Inkscape

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

For each of the following file formats, write the name of an application able to open and edit
the corresponding file:
png
doc
xls
ppt

A

png——-> Gimp
doc——-> LibreOffice Writer
xls——–> LibreOffice Calc
ppt——-> LibreOffice Impress

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

Which software package allows file sharing between Linux and Windows machines over the
local network?

A

Samba

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

You know that configuration files are kept even if the associated package is removed from the
system. How could you automatically remove the package named cups and its configuration
files from a DEB based system?

A

apt-get purge cups

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

Suppose you have many TIFF image files and want to convert them to JPEG. Which software
package could be used to convert those files directly at the command line?

A

ImageMagick

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

Which software package do you need to install in order to be able to open Microsoft Word
documents sent to you by a Windows user?

A

LibreOffice or OpenOffice

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

Every year, linuxquestions.org promotes a survey about the most popular Linux applications.
Visit https://www.linuxquestions.org/questions/2018-linuxquestions-org-members-choice-
awards-128/ and find out which desktop applications are most popular among experienced
Linux users.

A

Browser: Firefox. Email client: Thunderbird. Media player: VLC. Raster graphics editor: GIMP

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

What are — in a nutshell — the “four freedoms” as defined by Richard Stallman and the Free
Software Foundation?

A

freedom 0———–> run the software
freedom 1———–> study and modify the software (source code)
freedom 2———–> distribute the software
freedom 3———–> distribute the modified software

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

What does the abbreviation FLOSS stand for?

A

Free/Libre Open Source Software

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

You have developed free software and want to ensure that the software itself, but also all
future results based on it, remain free as well. Which license do you choose?
CC BY———————->
GPL version 3———–> X
2-Clause BSD License———–>
LGPL———–>

A

GPL version 3 (GNU General Public License version 3)

Copyleft
Freedom

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

Which of the following licenses would you call permissive, which would you call copyleft?

A

Simplified BSD License permissive
GPL version 3 copyleft
CC BY permissive
CC BY-SA copyleft

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

You have written a web application and published it under a free license. How can you earn
money with your product? Name three possibilities.

A

◦ Dual licensing, e.g. by offering a chargeable “Business Edition”
◦ Offering hosting, service, and support
◦ Developing proprietary extensions for customers

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

Under which license (including version) are the following applications available?

A

Apache HTTP Server ——————> Apache License 2.0
MySQL Community Server———–> GPL 2
Wikipedia articles (English)———–> Creative Commons Attribution Share-Alike license (CC-BY-SA)
Mozilla Firefox Mozilla—————–> Public License 2.0
GIMP —————————————->GPL 3

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

You want to release your software under the GNU GPL v3. What steps should you follow?

A

◦ If necessary, secure yourself against the employer with a copyright waiver, for example, so
that you can specify the license.
◦ Add a copyright notice to each file.
◦ Add a file called COPYING with the full license text to your software.
◦ Add a reference to the license in each file

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

You have written proprietary software and would like to combine it with free software under the GPL version 3. Are you allowed to do this or what do you have to consider?

A

The FAQs of the Free Software Foundation provide information here: Provided that your proprietary software and the free software remain separate from each other, the combination is possible.
However, you have to make sure that this separation is technically guaranteed and recognizable for the users.
If you integrate the free software in such a way that it becomes part
of your product, you must also publish the product under the GPL according to the copyleft principle.

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

Why did the Free Software Foundation release the GNU Affero General Public License (GNU AGPL) as a supplement to the GNU GPL?

A

The GNU AGPL closes a license gap that arises especially with free software hosted on a server:
If a developer makes changes to the software, he is not obliged under the GPL to make these
changes accessible, since he allows access to the program, but does not “redistribute” on the
program in the GPL sense. The GNU AGPL, on the other hand, stipulates that the software must
be made available for download with all changes

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

Name three examples of free software, which are also offered as “Business Edition”, e.g. in a chargeable version

A

MySQL
Zammad
Nextcloud

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

You should use a “private window” in your browser if you want:
To browse completely anonymous on the
Internet
To leave no trace on the computer you’re
using
To activate TLS to avoid cookie tracking
In order to use DNT
To use cryptography during data transmission

A

To leave no trace on the computer you’re
using

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

What is OpenStack?
A project that allows the creation of private
IaaS
A project that allows the creation of private
PaaS
A project that allows the creation of private
SaaS
A hypervisor
An open source password manager

A

A project that allows the creation of private
IaaS

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

Which of the below options are valid disk encryption softwares?
RevealJS, EncFS and dm-crypt
dm-crypt and KeePass
EncFS and Bitwarden
EncFS and dm-crypt
TLS and dm-crypt

A

EncFS and dm-crypt

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

Select true or false for dm-crypt device encryption:
Files are encrypted before being written to the
disk.

A

true

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

Select true or false for dm-crypt device encryption:

The entire filesystem is an encrypted blob

A

true

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

Select true or false for dm-crypt device encryption:

Only files and directories are encrypted, not
symlinks

A

false

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

Select true or false for dm-crypt device encryption:

Don’t require root access

A

false

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

Select true or false for dm-crypt device encryption:

Is a block device encryption

A

true

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

Beamer is:
An encryption mechanism
A hypervisor
A virtualization software
An OpenStack component
A LaTeX presentation tool

A

A LaTeX presentation tool

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

Find what type the following commands are:

cd———->
cat———>
exit——–>

A

cd———-> Shell builtin
cat———> External command
exit——–> Shell builtin

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

With one command and using brace expansion in Bash (review the man page for Bash), create
5 files numbered 1 to 5 with the prefix game (game1, game2, …).
Ranges can be used to express the numbers from 1 to 5 within one command:

A

$ touch game{1..5}
$ ls
game1 game2 game3 game4 game5

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

Delete all 5 files that you just created with just one command, using a different special
character (review Pathname Expansion in the Bash man pages).
Since all files start with game and end in a single character (a number from 1 to 5 in this case),
? can be used as a special character for the last character in the filename:

A

$ rm game?

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

Is there any other way to make two commands interact with each other? What are those?

A

one command could write data to a file which is then processed by another command.

Linux can also collect the output of one command and use it as input for another command. This is called piping and we will learn more about it in a future lesson.

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

Create a local variable number.

A

Answers to Guided Exercises
1. Create a local variable number.
$ number=5

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

Create an environment variable ORDER, using one of the two above methods.

A

$ export ORDER=desc

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

Display both the variable names and their contents.

A

$ echo number
number
$ echo ORDER
ORDER
$ echo $number
5
$ echo $ORDER
desc

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

What are the scopes of the previously created variables?

A

The scope of the local variable number is the current shell only.
◦ The scope of the environment variable ORDER is the current shell and all the subshells
generated by it.

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

Create a local variable nr_files and assign the number of lines found in the /etc/passwd
file. Hint: Look into the command wc and command substitution and don’t forget about
quotation marks.

A

$ nr_files=wc -l /etc/passwd

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

Create an environment variable ME. Assign the USER variable’s value.

A

$ export ME=$USER

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

Append the HOME variable value to ME, having the : delimiter. Display the contents of the ME
variable.

A

$ ME=$ME:$HOME
$ echo $ME
user:/home/user

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

Using the date example above, create a variable called today and assign the date for one of the
time zones.
The following use the GMT and EST time zones as an example, but any time zone selection is
valid.

A

$ today=$(TZ=GMT date)
$ echo $today
Thu 31 Jan 15:07:35 GMT 2019

or

$ today=$(TZ=EST date)
$ echo $today
Thu 31 Jan 10:07:35 EST 2019

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

Create another variable called today1 and assign the system’s date to it.
Assuming that you are in GMT:

A

$ today1=$(date)
$ echo $today1
Thu 31 Jan 10:07:35 EST 2019

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

Display the path to the first 3 README files. Use the man command to identify the correct option
for locate.

A

$ locate -l 3 README
/etc/alternatives/README
/etc/init.d/README
/etc/rc0.d/README

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

Create a file called test in your home directory. Find its absolute path with the locate
command.

A

$ touch test
$ locate test
/home/user/test

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

Did you find it immediately? What did you have to do in order for locate to find it?

A

$ sudo updatedb

The file is newly created, therefore there is no record of it in the database.

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

Search for the test file that you previously created, using the find command. What syntax did
you use and what is the absolute path ?

A

$ find ~ -name test
or
$ find . -name test
/home/user/test

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

Display on the screen the present working directory, including the subfolders.

A

$ ls -R

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

Search within the tree for all files that end with a number.

A

$ find ~ -name “[0-9]”
$ locate “
[0-9]”

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

Remove the entire directory tree with a single command

A

$ rm -r Documents Downloads Test test

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

For each of the following paths, identify whether it is absolute or relative:
/home/user/Downloads absolute
../Reports relative
/var absolute
docs relative
/ absolute

A

For each of the following paths, identify whether it is absolute or relative:
/home/user/Downloads————> absolute
../Reports ——————————->relative
/var —————————————>absolute
docs ————————————–>relative
/ ——————————————->absolute

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

Observe the following file structure. Note: Directories end with a slash (/) when tree is
invoked with the -F option. You will need elevated privileges in order to run the tree
command on the root (/) directory. The following is example output and is not indicative of a
full directory structure. Use it to answer the following questions:

A

$ sudo tree -F /
/
├── etc/
│ ├── network/
│ │ └── interfaces
│ ├── systemd/
│ │ ├── resolved.conf
│ │ ├── system/
│ │ ├── system.conf
│ │ ├── user/
│ │ └── user.conf
│ └── udev/
│ ├── rules.d/
│ └── udev.conf
└── home/
├── lost+found/
└── user/
└── Documents/
12 directories, 5 files

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

Enter the shortest possible command for each of the following:
◦ Your current location is root (/). Enter the command to navigate to lost+found within the
home directory (example):

A

$ cd home/lost+found

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

Enter the shortest possible command for each of the following:

◦ Your current location is root (/). Enter the command to navigate to the directory named network:

A

$ cd etc/network

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

Enter the shortest possible command for each of the following:

◦ Your current location is Documents. Navigate to the directory named etc:

A

$ cd /etc

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

Enter the shortest possible command for each of the following:

◦ Your current location is system. Navigate to the directory named user:

A

$ cd /home/user

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

Consider the following commands:

$ pwd
/etc/udev/rules.d
$ cd ../../systemd/user
$ cd ..
$ pwd

What is the output of the final pwd command?

A

/etc/systemd

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

Suppose a user has entered the following commands:

What cd command would allow you to enter this directory

A

$ mkdir “this is a test”
$ ls
this is a test

$ cd this\ is\ a\ test

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

Try this again, but after typing in cd this, press the TAB key. What is now displayed on the
prompt?

A

$ cd this\ is\ a\ test

This is an example of autocompletion, which is an invaluable tool not only for saving time, but
for preventing spelling errors.

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

Try to create a directory whose name contains a \ character. Display the directory’s name with
ls and delete the directory.
You can either escape the backslash using another backslash (\) or use single or double
quotes around the whole directory name:

A

$ mkdir my\dir
$ ls
‘my\dir’
$ rmdir ‘my\dir’

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

Here is a new command to try: du -h. Run this command and describe the output that it gives
you.

A

The du command will generate a list of all files and directories, and indicate the size of each.
For example, du -s will display the file size of all files, directories, and subdirectories for a
certain location.

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

On many Linux systems, you can type in ll and get the same output as you would if you typed
ls -l. Please note however that ll is not a command. For example, man ll will give you the
message that no manual entry exists for it. This is an example of an alias. Why might aliases be
useful to a user?

A

ll is an alias of ls -l. In Bash, we can use aliases to simplify commonly-used commands. ll is
often defined for you in Linux, but you can create your own as well.

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

What command will navigate into the network directory regardless of your current
location?

A

cd /etc/network

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

What command can user enter to navigate into their Documents directory from
/etc/udev? Use the shortest possible path

A

cd ~/Documents

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

What command can user enter to navigate into michael ‘s Music directory? Use the
shortest possible path:

A

cd ~michael/Music

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

What does -v do for mkdir, rm, and cp?

A

$ rm -v a b
removed ‘a’
removed ‘b’
$ mv -v a b
‘a’ -> ‘b’
$ cp -v b c
‘b’ -> ‘c’

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

What happens if you accidentally attempt to copy three files on the same command line to a
file that already exists instead of a directory?
Linux Essentials (Version 1.6) | 2.4 Creating, Moving and Deleting Files
Version: 2024-10-27 | Licensed under CC BY-NC-ND 4.0. | learning.lpi.org | 163
cp will refuse to do anything and output an error message:

A

$ touch a b c d
$ cp a b c d
cp: target ‘d’ is not a directory

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

What happens when you use mv to move a directory into itself?
You will get an error message telling you mv cannot do that.

A

$ mv a a
mv: cannot move ‘a’ to a subdirectory of itself, ‘a/a’

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

How would you delete all files in your current directory that start with old?
You would use the glob old* with rm:

A

$ rm old*

79
Q

Which of the following files would log_[a-z]201?*_01.txt match?

og_3_2017Jan_01.txt
log
+_2017_Feb_01.txt
log_b_2007_Mar_01.txt
log_f_201A_Wednesday_01.txt

A

log_f_201A_Wednesday_01.txt

$ ls log_[a-z]201?*_01.txt
log_f_201A_Wednesday_01.txt

80
Q

Create a few globs to match the following list of file names:

doc100
doc200
doc301
doc401

A

There are several solutions. Here are some of them:
doc*
doc[1-4]*
doc?0?
doc[1-4]0?

81
Q

Use the cp man page to find out how to make a copy of a file and have the permissions and
modification time match the original.
You would use the -p option. From the man page:

A

$ man cp
-p same as –preserve=mode,ownership,timestamps
–preserve[=ATTR_LIST]
preserve the specified attributes (default: mode,ownership,time‐
stamps), if possible additional attributes: context, links,
xattr, all

82
Q

What does the rmdir -p option do? Experiment with it and explain how it differs from rm -r.
It causes rmdir to behave similarly to mkdir -p. If passed a tree of empty directories, it will
remove all of them.

A

$ find
.
./a
./a/b
./a/b/c
$ rmdir -p a/b/c
$ ls

83
Q

DO NOT ACTUALLY EXECUTE THIS COMMAND: What do you think rm -ri /* will do?
(HONESTLY, DO NOT ATTEMPT TO DO THIS!)

A

It will remove all files and directories writable by your user account. This includes any network file systems.

84
Q

Explain cp -u

A

The -u option causes cp to only copy a file if the destination is missing or is older than the
source file.

85
Q

According to the extensions, which of the following tools were used to create these files?

Filename—————>tar————-> gzip———–> bzip2————–> xz
archive.tar
archive.tgz
archive.tar.xz

A

Filename—————>tar————-> gzip———–> bzip2————–> xz
archive.tar————-> X————–> - <————–> - <————-> -
archive.tgz ————>X—————–> X <———–> - <—————-> -
archive.tar.xz———> X —————-> - <———–> - <—————-> X

86
Q

Which tar option instructs tar to include the leading / in absolute paths?
The -P option. From the man page:

A

-P, –absolute-names
Don’t strip leading slashes from file names when creating archives

87
Q

Does zip support different compression levels?

A

Yes. You would use -#, replacing # with a number from 0-9. From the man page:

-#
(-0, -1, -2, -3, -4, -5, -6, -7, -8, -9)
Regulate the speed of compression using the specified digit #,
where -0 indicates no compression (store all files), -1 indi‐
cates the fastest compression speed (less compression) and -9
indicates the slowest compression speed (optimal compression,
ignores the suffix list). The default compression level is -6.
Though still being worked, the intention is this setting will
control compression speed for all compression methods. Cur‐
rently only deflation is controlled.

88
Q

When extracting files, does tar support globs in the file list?

A

Yes, you would use the –wildcards option. –wildcards must be placed right after the tar file when using the no dash style of options. For example:
$ tar xf tarfile.tar –wildcards dir/file*
$ tar –wildcards -xf tarfile.tar dir/file*

89
Q

How can you make sure a decompressed file is identical to the file before it was compressed?

A

You don’t need to do anything with the tools covered in this lesson. All three of them include
checksums in their file format that is verified when they are decompressed.

90
Q

What happens if you try to extract a file from a tar archive that already exists on your
filesystem?

A

The file on your filesystem is overwritten with the version that is in the tar file.

91
Q

How would you extract the file archive.tgz without using the tar z option?

A

You would decompress it with gunzip first.
$ gunzip archive.tgz
$ tar xf archive.tar

92
Q

List the contents of your current directory, including the ownership and permissions, and
redirect the output to a file called contents.txt within your home directory.

A

$ ls -l > contents.txt

93
Q

Display the last 10 lines of the /etc/passwd file and redirect it to a new file in the your user’s
Documents directory.

A

$ tail /etc/passwd > Documents/newfile

94
Q

Count the number of words within the contents.txt file and append the output to the end of
a file field2.txt in your home directory. You will need to use both input and output
redirection.

A

$ wc < contents.txt&raquo_space; field2.txt

95
Q

Display the first 5 lines of the /etc/passwd file and sort the output reverse alphabetically.

A

$ head -n 5 /etc/passwd | sort -r

96
Q

Using the previously created contents.txt file, count the number of characters of the last 9
lines.

A

$ tail -n 9 contents.txt | wc -c
531

97
Q

Count the number of files called test within the /usr/share directory and its subdirectories.
Note: each line output from the find command represents a file.

A

$ find /usr/share -name test | wc -l
125

98
Q

Select the second field of the contents.txt file and redirect the standard output and error
output to another file called field1.txt.

A

$ cut -f 2 -d “ “ contents.txt &> field1.txt

99
Q

Using the input redirection operand and the tr command, delete the dashes (-) from the
contents.txt file.

A

$ tr -d “-“ < contents.txt

100
Q

What is the biggest advantage of only redirecting errors to a file?

A

Only redirecting errors to a file can help with keeping a log file that is monitored frequently.

101
Q

Replace all recurrent spaces within the alphabetically sorted contents.txt file with a single
space.

A

$ sort contents.txt | tr -s “ “

102
Q

In one command line, eliminate the recurrent spaces (as done in the previous exercise), select
the ninth field and sort it reverse alphabetically and non-case sensitive. How many pipes did
you have to use?

A

$ cat contents.txt | tr -s “ “ | cut -f 9 -d “ “ | sort -fr

103
Q

All lines containing the word cat anywhere on the line.

A

$ grep “cat” /usr/share/hunspell/en_US.dic
Alcatraz/M
Decatur/M
Hecate/M

104
Q

All lines that do not contain any of the following characters: sawgtfixk.

A

$ grep -v “[sawgtfixk]” /usr/share/hunspell/en_US.dic
49269
0/nm
1/n1
2/nm
2nd/p
3/nm
3rd/p
4/nm
5/nm
6/nm
7/nm
8/nm

105
Q

All lines that start with any 3 letters and the word dig.

A

$ grep “^…dig” /usr/share/hunspell/en_US.dic
cardigan/SM
condign
predigest/GDS

106
Q

All lines that end with at least one e

A

$ grep -E “e+$” /usr/share/hunspell/en_US.dic
Anglicize
Anglophobe
Anthropocene

107
Q

All lines that contain one of the following words: org , kay or tuna.

A

$ grep -E “org|kay|tuna” /usr/share/hunspell/en_US.dic
Borg/SM
George/MS
Tokay/M
fortunate/UY

108
Q

Number of lines that start with one or no c followed by the string ati.

A

$ grep -cE “^c?ati” /usr/share/hunspell/en_US.dic
3

109
Q

Find the regular expression that matches the words in the “Include” line and doesn’t match the ones in the “Exclude” line:

A

◦ Include: pot, spot, apot
Exclude: potic, spots, potatoe
Answer: pot$
◦ Include: arp99, apple, zipper
Exclude: zoo, arive, attack
Answer: p+
◦ Include: arcane, capper, zoology
Exclude: air, coper, zoloc
Answer: arc|cap|zoo
◦ Include: 0th/pt, 3th/tc, 9th/pt
Exclude: 0/nm, 3/nm, 9/nm
Answer: [0-9]th.+
◦ Include: Hawaii, Dario, Ramiro
Exclude: hawaii, Ian, Alice
Answer: ^[A-Z]a.*i+

110
Q

What other useful command is commonly used to search within the files? What additional
functionalities does it have?

A

The sed command. The command can find and replace characters or sets of characters within
a file.

111
Q

Thinking back at the previous lesson, use one of the examples and try to look for a specific
pattern within the output of the command, with the help of grep.

A

I took one of the answers from the Explorational Exercises and looked for the line that has read, write and execute as the group permissions. Your answer might be different, depending
on the command that you chose and the pattern that you created

$ cat contents.txt | tr -s “ “ | grep “^….rwx”

112
Q

The user types the following into their shell:

What has the user done?

A

$ PATH=~/scripts
$ ls
Command ‘ls’ is available in ‘/bin/ls’
The command could not be located because ‘/bin’ is not included in the PATH environment
variable.
ls: command not found

The user has overwritten the contents of PATH with the directory ~/scripts. The ls
command can no longer be found, since it isn’t contained in PATH. Note that this change
only affects the current session, logging out and back in with revert the change

113
Q

Consider the following script. Notice that it is using elif to check for a second condition:

A

> /!bin/bash
fruit1 = Apples
fruit2 = Oranges
if [ $1 -lt $# ]
then
echo “This is like comparing $fruit1 and $fruit2!”
elif [$1 -gt $2 ]
then
echo ‘$fruit1 win!’
else
echo “Fruit2 win!”
done

114
Q

!/bin/bash

fruit1=Apples
fruit2=Oranges
if [ $1 -lt $# ]
then
echo “This is like comparing $fruit1 and $fruit2!”
elif [ $1 -gt $2 ]
then
echo “$fruit1 win!”
else
echo “$fruit2 win!”
fi

What will the output be in the following situations?
$ ./guided1.sh 3 0

A

Apples win!

115
Q

Write a simple script that will check if exactly two arguments are passed. If so, print the
arguments in reverse order. Consider this example (note: your code may look different than
this, but should lead to the same output):

A

!/bin/bash

if [ $1 == $number ]
then
echo “True!”
fi

if [ $# -ne 2 ]
then
echo “Error”
else
echo “$2 $1”
fi

116
Q

This code is correct, but it is not a number comparison. Use an internet search to discover how
this code is different from using -eq.
Using == will compare strings. That is, if the characters of both variables match up exactly, then
the condition is true.

abc ==
abc ==
1 == 1
1+1 == 2

A

abc == ——————————->abc true
abc == ——————————->ABC false
1 == 1 ——————————->true
1+1 == 2 ——————————->false

String comparisons lead to unexpected behavior if you are testing for numbers.

117
Q

There is an environment variable that will print the current directory. Use env to discover the
name of this variable.

A

PWD

118
Q

Using what you have learned in questions 2 and 3, write a short script that accepts an argument. If an argument is passed, check if that argument matches the name of the current
directory. If so, print yes. Otherwise, print no.

A

!/bin/bash

if [ “$1” == “$PWD” ]
then
echo “yes”
else
echo “no”
fi

119
Q

!/bin/bash

if [ $# -lt 1 ]
then
echo “This script requires at least 1 argument.”
exit 1
fi
echo $1 | grep “^[A-Z]*$” > /dev/null
if [ $? -ne 0 ]
then
echo “no cake for you!”
exit 2
fi
echo “here’s your cake!”
exit 0

Read the contents of script1.sh below:
What is the output of these commands?
Command: ./script1.sh
Output:
◦ Command:
Output:
◦ Command:
Output:
◦ Command:
Output:
◦ Command:
Output:

A

Command: ./script1.sh
Output: This script requires at least 1 argument.
◦ Command: echo $?
Output: 1
◦ Command: ./script1.sh cake
Output: no cake for you!
◦ Command: echo $?
Output: 2
◦ Command: ./script1.sh CAKE
Output: here’s your cake!
◦ Command: echo $?
Output: 0

120
Q

Read the contents of file script2.sh:

for filename in $1/*.txt
do
cp $filename $filename.bak
done

A

Describe the purpose of this script as you understand it.
This script will make backup copies of all files ending with .txt in a subdirectory defined in
the first argument.

121
Q

Create a script that will take any number of arguments from the user, and print only those
arguments that are numbers greater than 10.

A

!/bin/bash

for i in $@
do
echo $i | grep “^[0-9]*$” > /dev/null
if [ $? -eq 0 ]
then
if [ $i -gt 10 ]
then
echo -n “$i “
fi
fi
done
echo “”

122
Q

Retrieve the current kernel release of your Linux system if you have access to the command
line.

A

$ uname -r
4.15.0-47-generic

123
Q

Using your preferred search engine locate and identify public cloud providers available to you.
These could include AWS, Google Cloud, Rackspace and many more. Choose one and see which
operating systems are available to deploy.

A

AWS, as an example, allows you to deploy many Linux distributions such as Debian, Red Hat,
SUSE or Ubuntu as well as Windows.

124
Q

Use the which command to find out the location of the following programs and complete the table:
Program which command Path to Executable
(output)
User needs root
privileges?
swapon
kill
cut
usermod
cron
ps

A

Program which command Path to Binary
(output)
User needs root
privileges?
swapon which swapon /sbin/swapon Yes
kill which kill /bin/kill No
cut which cut /usr/bin/cut No
usermod which usermod /usr/sbin/usermod Yes
cron which cron /usr/sbin/cron Yes
ps which ps /bin/ps No

125
Q

Where are the following files to be found?
File /etc ~
.bashrc
bash.bashrc
passwd
.profile
resolv.conf
sysctl.conf

A

File /etc ~
.bashrc No Yes
bash.bashrc Yes No
passwd Yes No
.profile No Yes
resolv.conf Yes No
sysctl.conf Yes No

126
Q

Explain the meaning of the number elements for kernel file vmlinuz-4.15.0-50-generic
found in /boot:
Number Element Meaning
4
15
0
50

A

Number Element Meaning
4 Kernel version
15 Major revision
0 Minor revision
50 Patch number

127
Q

What command would you use to list all hard drives and partitions in /dev?

A

ls /dev/sd*

128
Q

Device files for hard drives are represented based on the controllers they use — we saw
/dev/sd* for drives using SCSI (Small Computer System Interface) and SATA (Serial Advanced
Technology Attachment), but

A

◦ How were old IDE (Integrated Drive Electronics) drives represented?
/dev/hd*
◦ And modern NVMe (Non-Volatile Memory Express) drives?
/dev/nvme*

129
Q

Take a look at the file /proc/meminfo. Compare the contents of this file to the output of the
command free and identify which key from /proc/meminfo correspond to the following
fields in the output of free:

A

Answers to Explorational Exercises
1. Device files for hard drives are represented based on the controllers they use — we saw
/dev/sd* for drives using SCSI (Small Computer System Interface) and SATA (Serial Advanced
Technology Attachment), but
◦ How were old IDE (Integrated Drive Electronics) drives represented?
/dev/hd*
◦ And modern NVMe (Non-Volatile Memory Express) drives?
/dev/nvme*
2. Take a look at the file /proc/meminfo. Compare the contents of this file to the output of the
command free and identify which key from /proc/meminfo correspond to the following
fields in the output of free:
free output /proc/meminfo field
total MemTotal / SwapTotal
free MemFree / SwapFree
shared Shmem
buff/cache Buffers, Cached and SReclaimable
available MemAvailable

130
Q

What command is used to read the following binary logs?

A

◦ /var/log/wtmp
Answer: last
◦ /var/log/btmp
Answer: lastb
◦ /run/log/journal/2a7d9730cd3142f4b15e20d6be631836/system.journal
Answer: journalctl

131
Q

In combination with grep, what commands would you use to find out the following information about your Linux system?

A

◦ When the system was last rebooted (wtmp)
Answer: last
◦ Which hard disk are installed (kern.log)
Answer: less /var/log/kern.log
◦ When the last login occurred (auth.log)
Answer: less /var/log/auth.log

132
Q

What two commands would you use to have the kernel ring buffer displayed?

A

dmesg and journalctl -k (also journalctl –dmesg).

133
Q

Indicate where the following log messages belong:
◦ Jul 10 13:37:39 debian dbus[303]: [system] Successfully activated service ‘org.freedesktop.nm_dispatcher’

/var/log/auth.log
/var/log/kern.log
/var/log/syslog
/var/log/messages

A

/var/log/syslog

134
Q

Indicate where the following log messages belong:

ul 10 11:23:58 debian kernel: [ 1.923349] usbhid: USB HID core driver
(2 answers)

/var/log/auth.log
/var/log/kern.log
/var/log/syslog
/var/log/messages

A

/var/log/kern.log
/var/log/messages

135
Q

Indicate where the following log messages belong:

Jul 10 14:02:53 debian sudo: pam_unix(sudo:session): session opened for user root by carol(uid=0)

/var/log/auth.log
/var/log/kern.log
/var/log/syslog
/var/log/messages

A

/var/log/auth.log X

136
Q

Indicate where the following log messages belong:

Jul 10 11:23:58 debian NetworkManager[322]: <info> [1562750638.8672]
NetworkManager (version 1.6.2) is starting…</info>

/var/log/auth.log
/var/log/kern.log
/var/log/syslog
/var/log/messages

A

/var/log/messages X

137
Q

Have journalctl query information about the following units

Unit ————————Command
ssh
networking-
rsyslog
cron

A

Unit ————————Command
ssh ———————journalctl -u ssh.service
networking————– journalctl -u networking.service
rsyslog———- journalctl -u rsyslog.service
cron————– journalctl -u cron.service

138
Q

Learn about the command exec in Bash. Try to demonstrate its functionality by starting a Bash
session, finding the Bash process with ps, then run exec /bin/sh and search for the process
with the same PID again.

A

exec replaces a process with another command. In the following example we can see that the
Bash process is replaced by /bin/sh (instead of /bin/sh becoming a child process):
$ echo $$
19877
$ ps auxf | grep 19877 | head -1
carol 19877 0.0 0.0 7448 3984 pts/25 Ss 21:17 0:00 _ bash
$ exec /bin/sh
sh-5.0$ ps auxf | grep 19877 | head -1
carol 19877 0.0 0.0 7448 3896 pts/25 Ss 21:17 0:00 _ /bin/sh

139
Q

Follow these steps to explore kernel events and udev’s dynamic management of devices:

A

Hotplug a USB drive into your computer. Run dmesg and pay attention to the last lines. What
is the most recent line?
You should get something along the lines of [ 1967.700468] sd 6:0:0:0: [sdb]
Attached SCSI removable disk.

there is more

140
Q

A network engineer is asked to assign two IP addresses to the ens33 interface of a host, one
IPv4 address (192.168.10.10/24) and one IPv6 address
(2001:0:0:abcd:0:8a2e:0370:7334/64). What commands must they enter to achieve this?

A

sudo ip addr add 192.168.10.10/24 dev ens33
sudo ip addr add 2001:0:0:abcd:0:8a2e:0370:7334/64 dev ens33

141
Q

which addresses from the list below are private? (3 answers)

192.168.10.1
120.56.78.35
172.16.57.47
10.100.49.162
200.120.42.6

A

192.168.10.1 X
172.16.57.47 X
10.100.49.162 X

142
Q

What entry would you add into the hosts file to assign 192.168.0.15 to example.com?

A

192.168.0.15 example.com

143
Q

What effect would the following command have?

A

sudo ip -6 route add default via 2001:db8:0:abcd::1

It would add a default route into the table that sends all IPv6 traffic to the router with an
internal address of 2001:db8:0:abcd::1.

144
Q

Name the DNS record type used to serve the following requests
Textual data
Reverse IP address lookup
A domain that has no address of its own and relies on another domain for this information
Mail Server

A

Textual data
TXT
◦ Reverse IP address lookup
PTR
◦ A domain that has no address of its own and relies on another domain for this information
CNAME
◦ Mail Server
MX

145
Q

Linux has a feature called bridging, what does it do and how is it useful?

A

A bridge connects multiple networking interfaces. All interfaces connected to a bridge can
communicate as if they were connected to the same link layer network: All devices use IP
addresses from the same subnet and do not require a router in order to connect to each other

146
Q

What option needs to be supplied to the ss command in order to view all established UDP
sockets?

A

The -u option shows all established UDP sockets.

147
Q

Which command shows a summary of all sockets running on a Linux device?

A

The ss -s command shows a summary of all sockets

148
Q

he following output is generated by the command from the previous exercise. How many TCP
and UDP sockets are active?

A

Total: 978 (kernel 0)
TCP: 4 (estab 0, closed 0, orphaned 0, synrecv 0, timewait 0/0), ports 0
Transport Total IP IPv6
* 0 - -
RAW 1 0 1
UDP 7 5 2
TCP 4 3 1
INET 12 8 4
FRAG 0 0 0

11 TCP and UDP sockets are active.

149
Q

consider the following output of the id command:
$ id emma
uid=1000(emma) gid=1000(emma)
groups=1000(emma),4(adm),5(tty),10(uucp),20(dialout),27(sudo),46(plugdev)

In which files are the following attributes stored?
UID and GID
Groups

A

UID and GID /etc/passwd
Groups /etc/group

Additionally, in which file is the user password stored?
The hashed user password is stored in /etc/shadow.

150
Q

Which of the following types of cryptography is used by default to store passwords locally on a
Linux system?

A

By default, a one-way hash is used to store passwords.

151
Q

If an account has a User ID (UID) enumerated under 1000, what type of account is this?

A

Accounts with a UID lower than 1000 generally are system accounts.

152
Q

How can you get a list of the active logins in your system, and a count of them as well?

A

Use the w command. Besides a list of all active logins, it will also show information like how
many users are logged in, along the system load and uptime

153
Q

Using the grep command, we got the result below with information about the user emma.

A

$ grep emma /etc/passwd
emma:x:1000:1000:Emma Smith,42 Douglas St,555.555.5555,:/home/emma:/bin/ksh

154
Q

Fill in the blanks of the chart with the appropriate information using the output of the previous
command.
Username emma

A

Password x - should always be x for a valid, active user
login
UID 1000
Primary GID 1000
GECOS Emma Smith,42 Douglas St,555.555.5555
Home Directory /home/emma
Shell /bin/ksh

155
Q

Compare the results of last to w and who. What details are missing from each of the commands
compared to one another?

A

The w and who tools only list current users logged into the system, whereas last also lists users
that have disconnected. The w command lists system utilization, while who does not.

156
Q

Try issuing the commands who and w -his.

A

What information has been removed from the output of the w command with the “no
header” (-h) and “short” (-s) options?

The header is not printed, which is useful for parsing, and the login time and select CPU
information is not listed, respectively.
◦ What information has been added in the output the w command with the “ip address” (-i)
option?
This prints the IP address, instead of attempting DNS resolution, printing the hostname. This
option to w better matches the default output of the last command.

157
Q

Which file is the file that stores a user account’s one-way password hash?

A

The file /etc/shadow stores a user account’s one-way password hash, since it is not readable
by a regular, unprivileged user account, unlike file /etc/passwd.

158
Q

Which file contains the list of groups a user account is a member of? What logic could be used
to compile a list of a groups a user account is a member of?

A

The file /etc/group has a CSV list of usernames in the last field, “members”, of any line for a
group.
Any line in the file /etc/group where the user is listed in the final field, “members”, would
mean the user is a member of that group — assuming it is correctly formatted (CSV delimited).
Additionally, the user’s primary group membership in the /etc/passwd file will also have a
matching entry in the /etc/group file for both the group name and GID.

159
Q

One or more (1+) of the following files are not readable by regular, unprivileged users, by
default. Which ones?

◦ /etc/group
◦ /etc/passwd
/etc/shadow
◦ /etc/sudoers

A

/etc/shadow
/etc/sudoers

are not readable by default,
except by select services or the superuser.

160
Q

How would you change the current user’s login shell to the Korn Shell (/usr/bin/ksh) in non-
interactive mode?

A

$ chsh -s /usr/bin/ksh

161
Q

Why is the home directory of the root user not placed within /home directory?

A

the root account is required to troubleshoot and fix errors,
This includes:
- file system issues related to the /home directory.
- Root should be fully functional
even when the /home file system is not available yet.

162
Q

Answers to Guided Exercises
1. For each of the following entries, indicate the file to which it refers:

◦ developer:x:1010:frank,grace,dave

◦ root:x:0:0:root:/root:/bin/bash

◦ henry:$1$.AbCdEfGh123456789A1b2C3d4.:18015:20:90:5:30::

◦ henry:x:1000:1000:User Henry:/home/henry:/bin/bash

◦ staff:!:dave:carol,emma

Answers:
/etc/shadow
/etc/passwd
/etc/group

A

◦ developer:x:1010:frank,grace,dave
/etc/group

◦ root:x:0:0:root:/root:/bin/bash
/etc/passwd

◦ henry:$1$.AbCdEfGh123456789A1b2C3d4.:18015:20:90:5:30::
/etc/shadow

◦ henry:x:1000:1000:User Henry:/home/henry:/bin/bash
/etc/passwd

◦ staff:!:dave:carol,emma
/etc/gshadow

163
Q

Observe the following output to answer the next seven questions:
# cat /etc/passwd | tail -3
dave:x:1050:1050:User Dave:/home/dave:/bin/bash
carol:x:1051:1015:User Carol:/home/carol:/bin/sh
henry:x:1052:1005:User Henry:/home/henry:/bin/tcsh
# cat /etc/group | tail -3
web_admin:x:1005:frank,emma
web_developer:x:1010:grace,kevin,christian
dave:x:1050:
# cat /etc/shadow | tail -3
dave:$6$AbCdEfGh123456789A1b2C3D4e5F6G7h8i9:0:20:90:7:30::
carol:$6$q1w2e3r4t5y6u7i8AbcDeFgHiLmNoPqRsTu:18015:0:60:7:::
henry:!$6$123456789aBcDeFgHa1B2c3d4E5f6g7H8I9:18015:0:20:5:::
# cat /etc/gshadow | tail -3
web_admin:!:frank:frank,emma
web_developer:!:kevin:grace,kevin,christian
dave:!::
◦ What is the User ID (UID) and Group ID (GID) of carol?

◦ What shell is set for dave and henry?

◦ What is the name of the primary group of henry?

◦ What are the members of the web_developer group? Which of these are group administrators?

◦ Which user cannot log into the system?

◦ Which user should change the password the next time he will log into the system?

◦ How many days must pass before a password change is required for carol?

A

◦ What is the User ID (UID) and Group ID (GID) of carol?
The UID is 1051 and the GID is 1015 (the third and fourth fields in /etc/passwd).
◦ What shell is set for dave and henry?
dave uses /bin/bash and henry uses /bin/tcsh (the seventh field in /etc/passwd).
◦ What is the name of the primary group of henry?
The group name is web_admin (the first field in /etc/group).
◦ What are the members of the web_developer group? Which of these are group
administrators?
The members are grace, kevin and christian (the fourth field in /etc/group), but only
kevin is the administrator of the group (the third field in /etc/gshadow).
◦ Which user cannot log into the system?
The henry user account is locked (it has an exclamation mark in front of the password
hashes in /etc/shadow).
◦ Which user should change the password the next time he will log into the system?
If the third field (Date of Last Password Change) in /etc/shadow is 0, the user should
change his password the next time he will log into the system. Therefore, dave must change
his password.
◦ How many days must pass before a password change is required for carol?
60 days (the fifth field in /etc/shadow).

164
Q

Working as root, run the useradd -m dave command to add a new user account. What
operations does this command perform? Assume that CREATE_HOME and USERGROUPS_ENAB in
/etc/login.defs are set to yes.

A

The command adds a new user, named dave, to the list of users in the system. The home
directory of dave is created (by default /home/dave) and the files and directories contained in
the skeleton directory are copied to the home directory. Finally, new group is created with the
same name as the user account.

165
Q

Now that you have created the dave account, can this user login to the system?

A

cat /etc/shadow | grep dave

No, because the dave account is locked (see the exclamation mark in /etc/shadow).
dave:!:18015:0:99999:7:::
If you set a password for dave, the account will be unlocked. You can do this using the passwd command.

passwd dave
Changing password for user dave.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.

166
Q

cat /etc/group | grep 1019

identify the User ID (UID) and Group ID (GID) of dave and all members of the dave group.

cat /etc/passwd | grep dave
dave:x:1015:1019::/home/dave:/bin/sh
dave:x:1019:

A

UID 1015
GID 1019

respectively (the third and fourth fields in
/etc/passwd) and the dave group has no members (the fourth field in /etc/group is empty).

167
Q

Create the sys_admin, web_admin and db_admin groups and identify their Group IDs (GIDs).

A

groupadd sys_admin
# groupadd web_admin
# groupadd db_admin
# cat /etc/group | grep admin
sys_admin:x:1020:
web_admin:x:1021:
db_admin:x:1022:

The GIDs for the sys_admin, web_admin and db_admin groups are 1020, 1021 and 1022
respectively.

168
Q

Add a new user account named carol with UID 1035 and set sys_admin as its primary group
and web_admin and db_admin as its secondary groups.

A

useradd -u 1035 -g 1020 -G web_admin,db_admin carol
# id carol
uid=1035(carol) gid=1020(sys_admin) groups=1020(sys_admin),1021(web_admin),1022(db_admin)

169
Q

Delete the dave and carol user accounts and the sys_admin, web_admin and db_admin
groups that you have previously created.

A

userdel -r dave
# userdel -r carol
# groupdel sys_admin
# groupdel web_admin
# groupdel db_admin

170
Q

Run the ls -l /etc/passwd /etc/group /etc/shadow /etc/gshadow command and
describe the output that it gives you in terms of file permissions. Which of these four files are
shadowed for security reasons? Assume your system uses shadow passwords

A

ls -l /etc/passwd /etc/group /etc/shadow /etc/gshadow
-rw-r–r– 1 root root 853 mag 1 08:00 /etc/group
-rw-r—– 1 root shadow 1203 mag 1 08:00 /etc/gshadow
-rw-r–r– 1 root root 1354 mag 1 08:00 /etc/passwd
-rw-r—– 1 root shadow 1563 mag 1 08:00 /etc/shadow

The /etc/passwd and /etc/group files are world readable and are shadowed for security
reasons. When shadow passwords are used, you can see an x in the second field of these files
because the encrypted passwords for users and groups are stored in /etc/shadow and
/etc/gshadow, which are readable only by root and, in some systems, also by members belonging to the shadow group

171
Q

Run the ls -l /usr/bin/passwd command. Which special bit is set and what is its meaning?

A

ls -l /usr/bin/passwd
-rwsr-xr-x 1 root root 42096 mag 17 2015 /usr/bin/passwd

The passwd command has the SUID bit set (the fourth character of this line), which means that
the command is executed with the privileges of the file’s owner (thus root). This is how
ordinary users can change their password.

172
Q

Create a directory named emptydir using the command mkdir emptydir. Now, using ls, list
the permissions for the directory emptydir.
Add the -d parameter to ls to see the file attributes of a directory, instead of listing its
contents. Therefore the answer is:

A

ls -l -d emptydir

Bonus points if you merged the two parameters in one, as in ls -ld emptydir.

173
Q

Create an empty file named emptyfile with the command touch emptyfile. Now, using
chmod in symbolic notation, add execute permissions for the owner of the file emptyfile, and
remove write and execute permissions for everyone else. Do this using only one chmod
command.
Think about it this way:
◦ “For the user who owns the file (u) add (+) execute (x) permissions”, so u+x.
◦ “For the group (g) and other users (o), remove (-) write (w) and execute (x) permissions”, so
go-wx.
To combine these two sets of permissions, we add a comma between them. So the final
result is:

A

chmod u+x,go-wx emptyfile

174
Q

What will be the permissions of a file called text.txt after I use the command chmod 754
text.txt?

A

rwxr-xr–

Remember that in numeric notation each digit represents a set of three permissions, each one
with a respective value: read is 4, write is 2, execute is 1 and no permission is 0. We get the
value for a digit by adding the corresponding values for each permission. 7 is 4+2+1, or rwx, 5
is 4+0+1, so r-x and 4 is just read, or r–. The permissions for text.txt would be

175
Q

Let’s assume a file named test.sh is a shell script with the following permissions and ownership:

-rwxr-sr-x 1 carol root 33 Dec 11 10:36 test.sh

ownership:
-rwxr-sr-x 1 carol root 33 Dec 11 10:36 test.sh
◦ What are the permissions for the owner of the file?

◦ If the user john runs this script, under which user’s privileges will it be run?

◦ Using the numeric notation, which should be the syntax of chmod to “unset” the special
permission granted to this file?

A

ownership:
-rwxr-sr-x 1 carol root 33 Dec 11 10:36 test.sh
◦ What are the permissions for the owner of the file?
The permissions for the owner (2nd to 4th characters in the output of ls -l) are rwx, so the
answer is: “to read, to write to and to execute the file”.
◦ If the user john runs this script, under which user’s privileges will it be run?
Pay attention to the permissions for the group. They are r-s, which means the SGID bit is
set. The group who owns this file is root, so the script, even when started by a regular user,
will be run with root privileges.
◦ Using the numeric notation, which should be the syntax of chmod to “unset” the special
permission granted to this file?
We can “unset” the special permissions by passing a 4th digit, 0, to chmod. The current
permissions are 755, so the command should be chmod 0755.

176
Q

Consider this file:

$ ls -l /dev/sdb1
brw-rw—- 1 root disk 8, 17 Dec 21 18:51 /dev/sdb1

Which kind of file is sdb1? And who can write to it?

A

Which kind of file is sdb1? And who can write to it?
The first character of the output from ls -l shows the kind of file. b is a block device, usually a
disk (internal or external), connected to the machine. The owner (root) and any users of the
group disk can write to it.

177
Q

Consider the following 4 files:

drwxr-xr-t 2 carol carol 4,0K Dec 20 18:46 Another_Directory
—-r–r– 1 carol carol 0 Dec 11 10:55 foo.bar
-rw-rw-r– 1 carol carol 1,2G Dec 20 18:22 HugeFile.zip
drwxr-sr-x 2 carol users 4,0K Jan 18 17:26 Sample_Directory

Write down the corresponding permissions for each file and directory using 4-digit numeric
notation.

The corresponding permissions, in numeric notation, are as follows:

A

The corresponding permissions, in numeric notation, are as follows:
Another_Directory
Answer: 1755
1 for the sticky bit, 755 for the regular permissions (rwx for the user, r-x for group and
others).
foo.bar
Answer: 0044
No special permissions (so the first digit is 0), no permissions for the user (—) and just read
(r—r–) for group and others.
HugeFile.zip
Answer: 0664
No special permissions, so the first digit is 0. 6 (rw-) for the user and group, 4 (r–) for the
others.
Sample_Directory
Answer: 2755
2 for the SGID bit, 7 (rwx) for the user, 5 (r-x) for the group and others.

178
Q

Try this on a terminal: create an empty file called emptyfile with the command touch
emptyfile. Now “zero out” the permissions for the file with chmod 000 emptyfile. What will
happen if you change the permissions for emptyfile by passing only one value for chmod in
numeric notation, such as chmod 4 emptyfile? What if we use two, such as chmod 44
emptyfile? What can we learn about the way chmod reads the numerical value?
Remember that we “zeroed out” the permissions for emptyfile. So, its initial state would be:

Now, let’s try the first command, chmod 4 emptyfile:

The permissions for others were changed. And what if we try two digits, such as chmod 44
emptyfile?

A

———- 1 carol carol 0 Dec 11 10:55 emptyfile

$ chmod 4 emptyfile
$ ls -l emptyfile
——-r– 1 carol carol 0 Dec 11 10:55 emptyfile

$ chmod 44 emptyfile
$ ls -l emptyfile
—-r–r– 1 carol carol 0 Dec 11 10:55 emptyfile

Now, the permissions for group and others were affected. From this, we can conclude that in
numeric notation chmod reads the value “backwards”, from the least significant digit (others) to
the most significant one (user). If you pass one digit, you modify the permissions for others.
With two digits you modify group and others, and with three you modify user, group and others
and with four digits you modify user, group, others and the special permissions.

179
Q

Can you execute a file for which you have execute, but not read permissions (–x)? Why or
why not?

A

At first, the answer seems obvious: If you have execute permission, the file should run. This
applies to programs in binary format that are executed directly by the kernel. However, there
are programs (e.g. shell scripts) that must first be read and interpreted, so in these cases the
read permission (r) must also be set.

180
Q

Consider the permissions for the temporary directory on a Linux system, /tmp

ls -l /tmp
drwxrwxrwt 19 root root 16K Dec 21 18:58 tmp

A

User, group and others have full permissions. But can a regular user delete any files inside this
directory? Why is this?
/tmp is what we call a world writeable directory, meaning that any user can write to it. But we
don’t want one user modifying files created by others, so the sticky bit_ is set (as indicated by
the t on the permissions for others). This means that a user can delete files in /tmp, but only if
they created that file.

181
Q

file called test.sh has the following permissions: -rwsr-xr-x, meaning the SUID bit is set.
Now, run the following commands:
$ chmod u-x test.sh
$ ls -l test.sh
-rwSr-xr-x 1 carol carol 33 Dec 11 10:36 test.sh

A

hat did we do? What does the uppercase S mean?
We removed execute permissions for the user who owns the file. The s (or t) takes the place of
the x on the output of ls -l, so the system needs a way to show if the user has execute
permissions or not. It does this by changing the case of the special character.
A lowercase s on the first group of permissions means that the user who owns the file has
execute permissions and that the SUID bit is set. An uppercase S means that the user who owns
the file lacks (-) execute permissions and that the SUID bit is set.
The same can be said for SGID. A lowercase s on the second group of permissions means that
the group who owns the file has execute permissions and that the SGID bit is set. An uppercase
S means that the group who owns the file lacks (-) execute permissions and that the SGID bit is
set.
This is also true for the sticky bit, represented by the t in the third group of permissions.
Lowercase t means the sticky bit is set and that others have execute permissions. Uppercase T
means the sticky bit is set and that others do not have execute permissions.

182
Q

How would you create a directory named Box where all the files are automatically owned by
the group users, and can only be deleted by the user who created them?
This is a multi-step process. The first step is to create the directory

A

$ mkdir Box

We want every file created inside this directory to be automatically assigned to the group
users. We can do this by setting this group as the owner of the directory, and then by setting
the SGID bit on it. We also need to make sure that any member of the group can write to that
directory.
Since we do not care about what the other permissions are, and want to “flip” only the special
bits, it makes sense to use the symbolic mode

$ chown :users Box/
$ chmod g+wxs Box/

Note that if you current user does not belong to the group users, you will have to use the
command sudo before the commands above to do the change as root.
Now for the last part, making sure that only the user who created a file is allowed to delete it.
This is done by setting the sticky bit (represented by a t) on the directory. Remember that it is
set on the permissions for others (o).
$ chmod o+t Box/
The permissions on the directory Box should appear as follows:
drwxrwsr-t 2 carol users 4,0K Jan 18 19:09 Box
Of course, you can specify SGID and the sticky bit using only one chmod command:
$ chmod g+wxs,o+t Box/
Bonus points if you thought of that.

183
Q

Imagine a program needs to create a one-use temporary file that will never be needed again
after the program is closed. What would be the correct directory in which to create this file?

A

/tmp

184
Q

Which is the temporary directory that must be cleared during the boot process?

A

/run
or on some systems
/var/run.

185
Q

What is the parameter for chmod in symbolic mode to enable the sticky bit on a directory?

A

The symbol for the sticky bit in symbolic mode is t. Since we want to enable (add) this
permission to the directory, the parameter should be +t

186
Q

Imagine there is a file named document.txt on the directory /home/carol/Documents. What
is the command to create a symbolic link to it named text.txt in the current directory?

ln -s is the command to create a symbolic link. Since you should specify the full path to the
file you are linking to, the command is:

A

$ ln -s /home/carol/Documents/document.txt text.txt

187
Q

Explain the difference between a hard link to a file and a copy of this file.

A

A hard link is just another name for a file. Even though it looks like a duplicate of the original
file, for all purposes both the link and the original are the same, as they point to the same data
on disk. Changes made to the contents of the link will be reflected on the original, and vice-
versa. A copy is a completely independent entity, occupying a different place on disk. Changes
to the copy will not be reflected on the original, and vice-versa.

188
Q

imagine that inside a directory you create a file called recipes.txt. Inside this directory, you
will also create a hard link to this file, called receitas.txt, and a symbolic (or soft) link to this
called rezepte.txt.

A

$ touch recipes.txt
$ ln recipes.txt receitas.txt
$ ln -s receitas.txt rezepte.txt

The contents of the directory should be like so:
$ ls -lhi
total 160K
5388833 -rw-r–r– 4 carol carol 77K jun 17 17:25 receitas.txt
5388833 -rw-r–r– 4 carol carol 77K jun 17 17:25 recipes.txt
5388837 lrwxrwxrwx 1 carol carol 12 jun 24 10:12 rezepte.txt -> receitas.txt
Remember that, as a hard link, receitas.txt points to the same inode that recipes.txt.
What would happen to the soft link rezepte.txt if the name receitas.txt is deleted? Why?
The soft link rezepte.txt would stop working. This is because soft links point to names, not
inodes, and the name receitas.txt no longer exists, even if the data is still on the disk under
the name recipes.txt.

189
Q

Imagine you have a flash drive plugged into your system, and mounted on
/media/youruser/FlashA. You want to create in your home directory a link called
schematics.pdf, pointing to the file esquema.pdf in the root directory of the flash drive. So,
you type the command:

$ ln /media/youruser/FlashA/esquema.pdf ~/schematics.pdf
What would happen? Why?

A

The command would fail. The error message would be Invalid cross-device link, and it
makes the reason clear: hard links cannot point to a target in a different partition or device.
The only way to create a link like this is to use a symbolic or soft link, adding the -s parameter
to ln.

190
Q

Consider the following output of ls -lah:

$ ls -lah
total 3,1M
drwxr-xr-x 2 carol carol 4,0K jun 17 17:27 .
drwxr-xr-x 5 carol carol 4,0K jun 17 17:29 ..
-rw-rw-r– 1 carol carol 2,8M jun 17 15:45 compressed.zip
-rw-r–r– 4 carol carol 77K jun 17 17:25 document.txt
-rw-rw-r– 1 carol carol 216K jun 17 17:25 image.png
-rw-r–r– 4 carol carol 77K jun 17 17:25 text.txt
◦ How many links point to the file document.txt?

◦ Are they soft or hard links?

◦ Which parameter should you pass to ls to see which inode each file occupies?

A

◦ How many links point to the file document.txt?
Every file starts with a link count of 1. Since the link count for the file is 4, there are three
links pointing to that file.
◦ Are they soft or hard links?
They are hard links, since soft links do not increase the link count of a file.
◦ Which parameter should you pass to ls to see which inode each file occupies?
The parameter is -i. The inode will be shown as the first column in the output of ls, like
below:
$ ls -lahi
total 3,1M
5388773 drwxr-xr-x 2 rigues rigues 4,0K jun 17 17:27 .
5245554 drwxr-xr-x 5 rigues rigues 4,0K jun 17 17:29 ..
5388840 -rw-rw-r– 1 rigues rigues 2,8M jun 17 15:45 compressed.zip
5388833 -rw-r–r– 4 rigues rigues 77K jun 17 17:25 document.txt
5388837 -rw-rw-r– 1 rigues rigues 216K jun 17 17:25 image.png
5388833 -rw-r–r– 4 rigues rigues 77K jun 17 17:25 text.txt

191
Q

Imagine you have in your ~/Documents directory a file named clients.txt containing some
client names, and a directory named somedir. Inside this there is a different file also named
clients.txt with different names. To replicate this structure, use the following commands.
$ cd ~/Documents
$ echo “John, Michael, Bob” > clients.txt
$ mkdir somedir
$ echo “Bill, Luke, Karl” > somedir/clients.txt

You then create a link inside somedir named partners.txt pointing to this file, with the
commands:
$ cd somedir/
$ ln -s clients.txt partners.txt

So, the directory structure is:
Documents
|– clients.txt
-- somedir |-- clients.txt – partners.txt -> clients.txt
Now, you move partners.txt from somedir to ~/Documents, and list its contents.

$ cd ~/Documents/
$ mv somedir/partners.txt .
$ less partners.txt

Will the link still work? If so, which file will have its contents listed? Why?

A

This is a “tricky” one, but the link will work, and the file listed will be the one in ~/Documents,
containing the names John, Michael, Bob.
Remember that since you did not specify the full path to the target clients.txt when creating
the soft link partners.txt, the target location will be interpreted as being relative to the
location of the link, which in this case is the current directory.
When the link was moved from ~/Documents/somedir to ~/Documents, it should stop
working, since the target was no longer in the same directory as the link. However, it just so
happens that there is a file named clients.txt on ~/Documents, so the link will point to this
file, instead of the original target inside ~/somedir.
To avoid this, always specify the full path to the target when creating a symbolic link.

192
Q

Consider the following files:
-rw-r–r– 1 rigues rigues 19 Jun 24 11:12 clients.txt
lrwxrwxrwx 1 rigues rigues 11 Jun 24 11:13 partners.txt -> clients.txt

what are the access permissions for partners.txt? Why?

A

The access permissions for partners.txt are rw-r—r–, as links always inherit the same
access permissions as the target.

193
Q
A