Ch 3 Essential File Mgmt Tools Flashcards

1
Q

What is the layout of the Linux file system defined by?

A

The FHS - Filesystem Hierarchy Standard

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

Where can you find documentation for the FHS?

A

man 7 file-hierarchy

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

Name the most significant directories to know for the FHS

A

“bdrm shoves trump” or “dumb mothers rsvp”

/
/b - boot
/r - root
/o - opt
/s - sys
/e - etc
/m - mnt
/s - srv
/m - media
/r - run
/p - proc
/h - home
/d - dev
/t - tmp
/u - usr
/v - var

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

What is the / directory?

A

root directory, where the file system tree starts

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

What is the /boot directory?

A

it contains all files and directories needed to boot the Linux kernel

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

What is the /dev directory?

A

it contains device files that are used for accessing physical devices. This is essential during boot (need to see the hard drive, /dev/sda!)

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

What is the /etc directory for?

A

it contains confgiuration files that are used by programs and services on your server. essential during boot

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

What is the /home directory for?

A

user for local user home directories, e.g. /home/elise, home/leelemur

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

What is the /media or /mnt directory for?

A

cntain directories that are used for mounting devices in the file system tree (like a CD player)

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

What is the /opt directory for?

A

Used for optional packages that may be installe don your server

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

What is the /proc directory for?

A

used by the proc file system. This is a file system structure that gives access to kernel informaiton

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

What is the /root directory for?

A

specifies the home directory of the root user

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

What is the /run directory for?

A

Contains process and user-specific information that has been created since the last boot

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

What is the /srv directory for?

A

May be used for data by services like NFS, FTP, and HTTP

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

What is the /sys directory for?

A

Virtual Filesystem:
The /sys directory is part of the sysfs virtual filesystem, which is managed by the kernel.
Device Information:
It contains information about devices, including their drivers, configuration, and status.
Kernel Subsystem Access:
/sys provides access to various kernel subsystems, allowing users to read and potentially modify their configuration.
Not a Replacement for /dev:
While /sys provides device information, it’s not meant to be a replacement for the /dev directory, which provides access to devices through device nodes.
Forensic Tool:
The /sys directory can be valuable for forensic investigations, offering insights into kernel operations and hardware configurations, according to Medium.

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

What is the /tmp directory for?

A

Purpose:
/tmp provides a location for programs to store temporary files, such as intermediate results, cached data, or files created during the execution of a process.
Temporary Nature:
Files in /tmp are not intended to be preserved across reboots, so they are typically cleared during system startup.
Memory-Based Storage:
Many Linux systems mount /tmp as a tmpfs, which means files are stored in RAM, making access very fast but also ensuring they are lost on reboot.
Common Use Cases:
Programs may use /tmp to store data while they are running, then delete it when the program is finished. For example, an application might use /tmp to store temporary files during a long operation, such as an image processing task.
Difference from /var/tmp:
While both /tmp and /var/tmp are used for temporary storage, /var/tmp is often backed by physical storage and is more likely to retain files across reboots, making it suitable for data that should be preserved through a system restart.

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

What is the /usr directory for?

A

History:
Originally, /usr was intended to hold user home directories, but it evolved to its current role.
Purpose:
It’s designed to store files not required for the system’s fundamental functionality, often used for applications installed by users or the system administrator.
Structure:
/usr contains several subdirectories, each with a specific purpose:
/usr/bin: Contains executable user programs.
/usr/lib: Holds shared libraries.
/usr/share: Stores shared data, like documentation and fonts.
/usr/include: Contains header files for compiling software.
Relationship to other directories:
While /bin and /sbin contain basic system binaries, /usr/bin, /usr/sbin, and /usr/local/bin hold additional user and system-specific executables, respectively.

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

What is the /var directory for?

A

Contains files that may change in size dynamically, such as log files, mail boxes, and spool files (aaaah so var maybe like “variable size”)

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

What is a mount?

A

a mount is a connection between a device and a directory

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

The linux filesystem hierarchy, starting at the /, may be distributed across many different devices and even many different computer systems….how?

A

These devices are mounted into the root directory

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

What is involved in the mounting process?

A

a device connects to a specific directory. Once this has happened (it has been mounted), the device’s contents are accessible

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

Linux lets you use multiple mounts (and therefore potentially different filesystems) on a filesystem. What’s a drawback of all files being on just one filesystem?

A

1) high activity in one area may fill the entire filesystem, which hurts the processes running
2) if all files are on the same devices, its harder to secure and determine security of different areas of the file system. When you mount a separate file system, you can add mount options that can add extra security
3) it’s harder to add addnl storage space if a file system is already filled

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

How does linux avoid the pitfalls of everything being on one filesystem?

A

organize the filesystem into
1. diff devices
2. diff shares on other computers
3. logical volumes
4. disk partitions

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

What directories are commonly mounted on dedicated devices?

A

/boot, /boot/EFI, /var, /home, /usr

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

Why is /boot often on a separate device?

A

Separating this partition provides advantages such as reducing bootloader complexity and preventing accidental deletion of boot files when modifying other partitions

Why is /boot often a separate partition?
Bootloader Requirements:
The bootloader (like GRUB) needs to be able to read and access the kernel and initrd during the initial boot process. Separating /boot allows for simpler bootloader implementations.
Dual-Booting:
If you have multiple operating systems installed, keeping /boot as a separate partition prevents accidental deletion of the bootloader when one of the operating systems is modified or deleted.
File System Complexity:
Having /boot as a separate partition simplifies the overall file system structure, making it easier to manage and maintain.
Kernel Updates:
During kernel updates, the new kernel is typically installed in the /boot partition. This separation ensures that the boot process can continue even if there’s a problem with other parts of the file system.
Security:
Boot files are often considered critical for system integrity, and keeping them separate can enhance system security.

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

Why does /boot/EFI sometimes need to be on its own device?

A

If the system uses EFI when booting (extensible firmware interface), then a dedicated mount is required for boot, to give access to all files required in the earliest stages of booting

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

Why does the /var directory sometimes go on its own device?

A

because it grows dynamically and in an uncontrolled way – like with log files. Having it stored separately from the rest of the file system keeps the rest of the filesystem from being filled

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

Why is /home sometimes on its own device?

A

for security reasons

by being on a separate device, it can get mounted with options like noexec and nodev

its also beneficial when reinstalling a the OS, because then you can reuse that home directory in the new filesystem

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

Why is the /usr directory sometimes on its own device?

A

because it contains OS files only, which users dont need write access for. by making it on a separate device, admins can more easily make it a read-only mount

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

What command gives you an overview of all devices and their mount points?

A

mount

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

What is /proc/mounts and what is it for

A

It’s for the mount command.

the kernel writes to this file, and it shows everything that is mounted

it also shows kernel interfaces

it also shows the mount options with the mount

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

What does the df -Th command do?

A

shows all available disk space on mounted devices – includes most system mounts

-h flag gives human-readable output
-T flag shows which file system TYPE is used on diff mounts

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

What does findmnt do?

A

shows mounts and the relationships that exist between them

is more abbreviated and less overwhelming than the mount command

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

What default byte size is the output of the df command?

A

kibibytes

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

What flag is needed to modify the df command to display a different size than kibibytes?

A

-m for mebibytes

-h to see human readable format (KiB, MiB, GiB, TiB, PiB

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

What is the ? for in context to file mgmt?

A

match any one character, e.g. ls c?t will show output of cut and cat

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

What is the [auo] for in the context of file mgmt?

A

ls c[auo]t would match cat, cut, cot

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

What’s a command that can be used to remove a directory that isn’t rm -rf?

A

rmdir

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

What does ls -l do?

A

lists with file properties, like creation date and permissions

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

ls -a

A

show hidden files too

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

ls -lrt

A

=t show commands sorted based on mod date
show most recent files last with the -r

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

ls -R

A

list recursively from this location

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

cp -R

A

copy recursively

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

cp -a

A

preserve original permissions when copying (a for archive mode)

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

what files don’t get copied over with a regular cp command?

A

hidden files

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

what are three ways to ensure hidden files are copied over?

A
  1. cp /somedir/.* /tmp

copy all files starting with a dot

  1. cp -a /somedir/ .

copies the entire directory of /somedir to the current directory. This creates a sudirectory called /somedir in the current directory

  1. cp -a /somedir/. .

copies all files to the current dir (this is a dot space dot, not a dot dot)

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

Why does the rm -rf command prompt the user to confirm the delete?

A

because rm is an alias to rm -i, because of the /root/.bashrc config. The -f flag removes that alia from the bashrc

however, for safety, it’s good to have the prompt

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

What’s a way to cd to your home directory, using an environmental variable?

A

cd /home/$USER

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

What are links for files, broadly?

A

They are like aliases but for a file

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

What types of links are there?

A

hard links and symbolic links (symlinks)

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

What is an inode?

A

It’s where administrative data about a file is stored

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

Is there an inode for every file in linux?

A

yes

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

What data is stored in the inode, specifically?

A
  • the data block where the file contents are stored
  • the creation, access, and modification date
  • permissions
  • file owners
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
54
Q

What impt info is NOT stored in an inode?

A

the name of the file

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

What does an inode know instead of knowing its filename?

A

It konws how many names are associated with it (or rather, hard links)

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

Every file has what, instead of a name?

A

a hard link – but really, this is used as the name

57
Q

When you name a file, what is that name?

A

a hard link to that file

58
Q

Can a file have more than one hard link?

59
Q

What’s the advantage of multiple hard links for one file/inode?

A

This allows you to have a file available in multiple locations

a change made in the file in one location changes it at all the other hard link locations!!!

60
Q

Every hard link for the same inode, points to the same…

A

data block

61
Q

What are three restrictions for hard links?

A
  • they must exist on the same device (or partition, or logical volume, etc)
  • you can’t hardlink a directory
  • when the last name/hard link is removed from a file, the access to the file’s data is also removed
62
Q

if one hard link to a file is removed, what happens to other hard links for the same file?

A

they are unaffected

63
Q

What’s another name for a symlink?

A

A symbolic link or a hard link

64
Q

How does a symlink relate to an inode?

A

it does not link directly to an inode, only the name of a file

65
Q

What’s a disadvantage of symlinks?

A

when the original file is removed, the symlink becomes invalid and stops working

66
Q

What’s an advantage of symlinks?

A

they can link to files on other devices and on directories (unlike hardlinks)

67
Q

What command is used to make links?

68
Q

cp, ln, and mv all use what order for files?

A

source name first, then destination name,

69
Q

What is the command for making a soft link?

70
Q

What restriction is there for creating a hard link?

A

you have to be the own of the item you want ot link to

71
Q

what does ln /etc/hosts . do?

A

Creates a hard link to /etc/hosts in the current directory

72
Q

what does ln -s /etc/hosts do?

A

create a symlink to the file /etc/hosts in the current directory (points to the hardlink)

73
Q

what does ln -s /home /tmp do?

A

creates a sym link to the directory /home in the directory /tmp

74
Q

How do you find out if a file is a hardlink or a softlink?

75
Q

What’s the first character in a file property if it’s a soft link?

76
Q

What does ls -l show for a soft link?

A

the name of the item it links to, after the filename

77
Q

What does ls -l show for a hard link?

A

a counter for the number of hard links an inode has

78
Q

What is the \ doing in the command \ls -l ?

A

the \ means that the alias form of ls isn’t used

79
Q

What file creates an archive of files?

80
Q

What was the tar command originally designed for?

A

to stream files to a tape without any compression of the files – and so it still doesn’t compress anything by default

81
Q

What must be paired to tar to get it to actually compress files?

A

1) use a specific compression tool
2) specify an option that compresses the archive while it is created

82
Q

What is the tar command an acronym for?

A

The Tape ARchiver

83
Q

what’s the current utility of tar?

A

to write file to an archive file

84
Q

what four things must you be able to do with tar on the RHCSA exam?

A

1) create an archive
2) list contents of an archive
3) extract an archive
4) compress and uncompress archives

85
Q

What is the command to create an archive?

A

tar -cf archivename.tar /files-you-want-to-archive

86
Q

What permissions are needed to archive files?

A

you need read permissions for the files and execute permissions on the directory the file is in

87
Q

What does the command tar -cvf /root/ homes.tar/home do? (run as root)

A

Write the contents of the /home directory and everything below it to the /root directory

88
Q

Is order of flag options in the tar command important?

89
Q

Is the - necessary in tar flag options?

90
Q

What tar flag allows you to add a file to an existing archive?

91
Q

What does

tar -rvf /root/homes.tar /etc/hosts
(run as root)

do?

A

add /etc/hosts to the /root/homes.tar archive

92
Q

tar uses what template?

A

tar [dest] [source]

93
Q

What tar flag is used to update an existing archive file?

94
Q

What does

tar -uvf /root/homes.tar /home

do?

A

write newer versions of all files in /home to the /root/homes.tar archive

95
Q

What does the tar -t flag do?

A

shows contents of the archive

96
Q

What does the command

tar -tvf /root/homes.tar

do?

A

lists the contents of the archive file

97
Q

Does an archive file need to end in .tar?

A

No, but it is wise to, so that you know you’re dealing with an archive file

98
Q

How can you find out if a file is an archive file if it doesn’t have a .tar ending?

A

the file command

99
Q

What tar command extracts contents of an archive?

A

tar -xvf /root/homes.tar

100
Q

What tar flag extracts?

101
Q

What are two ways you can make sure an archive’s contents go exactly where you want them to (and not your current working directory) when you extract an archive?

A
  1. before extracting, cd to where you want it to extract to
  2. use the -C flag. e.g., -C /targetdir
102
Q

What does the command

tar -xvf homes.tar -C /tmp

do?

A

extract (verbosely) the homes archive and plop its contents into the /tmp directory

103
Q

What is the star command for?

A

the star utility was designed to offer support for archiving nondefault file attributes, such as access control lists (permissions mgmt…) or SELinux file content

104
Q

Should star or tar be used for archiving?

A

Now tar can do everything star can do and more now, and star is no longer included in default installs

105
Q

What if you only wanted to extract one file out of an archive?

A

use a command like

tar -xvf /archivename.tar file-you-want-to-extract

following the pattern

tar -extract [archive] [file from archive]

106
Q

What does the command

tar -xvf /root/etc.tar /etc/hosts

do?

A

extracts the file /etc/hosts from the /root/etc.tar archive (Which you could run after running tar -t to get contents of the archive)

107
Q

How do compression algorithms work, broadly?

A

They take advantage of the redundancy in files

108
Q

Does the tar command automatically compress files?

A

no, not unless you specify compression

109
Q

With the old version of tar, if you wanted to compress the archive, what did you do?

A

follow the archive creation with a compression algorithm command, like gzip or bzip2,

thus creating an archive.tar.gz file

110
Q

What are three compression algs/commands?

A

bzip2, gzip, xz

111
Q

What command uses bzip2 decompression?

112
Q

What command uses gzip decompression?

113
Q

what are the tar flag options for bzip2, gzip, and xz? (to use for compression, not decompression)

A

-j (bzip2)
-z (gzip)
-J (xz)

114
Q

What flags are used for tar and decompression?

A

flags are not necessarily as tar automatically recognizes compressed content

115
Q

What is this flag for tar?
-c

A

create an archive

116
Q

What is this flag for tar?
-v

A

show verbose output for tar

117
Q

What is this flag for tar?
-t

A

show the content of an archive

118
Q

What is this flag for tar?
-z

A

compress/decompress the archive while creating is using GZIP

119
Q

What is this flag for tar?
-j

A

compress/decompress the archive while creating it using BZIP2

120
Q

What is this flag for tar?
-J

A

compress/deconompress the archive using xz

121
Q

What is this flag for tar?
-x

A

extract an archive

122
Q

What is this flag for tar?
-u

A

update an archive – only newer files will be written to the archive

123
Q

What is this flag for tar?
-C

A

change the working directory before running the command

124
Q

What is this flag for tar?
-r

A

append a file to an archive

126
Q

/usr/include

A

Contains header files for compiling software.

127
Q

/usr/share

A

Stores shared data, like documentation and fonts.

128
Q

/usr/lib

A

Holds shared libraries

129
Q

/usr/bin

A

Contains executable user programs.

130
Q

How are /opt and /usr distinct?

A

In Linux, /usr and /opt serve distinct purposes for managing software installations. /usr typically houses system-wide applications and libraries, often installed by the system’s package manager, while /opt is designed for storing optional, add-on, or self-contained software packages, usually provided by third-party vendors.

/usr:
This directory contains system-wide applications, libraries, and other files that are essential for the operation of the Linux system. It’s often mounted read-only and is managed by the system’s package manager. Files within /usr are generally distributed as part of the operating system itself or through official repositories.

/opt:
This directory is intended for installing optional, add-on software that isn’t part of the main operating system distribution. It’s commonly used for installing pre-packaged software bundles or applications that come with their own directory structure. /opt is often used for software that doesn’t rely on the standard system libraries and is designed to be self-contained.

131
Q

What makes /sys distinct from /dev?

A

SHORT
/dev directory allows access to the device via the device files (or device nodes)
/sys directory allows the viewing of the device information and details

LONG
The /sys filesystem (sysfs) contains files that provide information about devices: whether it’s powered on, the vendor name and model, what bus the device is plugged into, etc. It’s of interest to applications that manage devices.

The /dev filesystem contains files that allow programs to access the devices themselves: write data to a serial port, read a hard disk, etc. It’s of interest to applications that access devices.

A metaphor is that /sys provides access to the packaging, while /dev provides access to the content of the box.

The files in /sys are not device nodes, but symbolic links and regular files. Those regular files are special in that reading or writing to them invokes file-specific functions in the kernel, like device nodes. The difference is that files in /sys work this way because of the filesystem they are on, whereas device nodes work this way due to their device node characteristics (the file type indicating a (block or character) device, and the device major and minor number indicating which device it is).

The reason for /dev existing independently of /sys is partly historical: /dev dates back to the dawn of Unix, while /sys is a much more recent invention. If Linux was designed today with no historical background, /dev/sda might be /sys/block/sda/content.

132
Q

Example path in /sys

A

/sys/block/*/device/serial (with * replaced by nvme0n1 or sda or hda

133
Q

What makes /proc distinct from /sys?

A

The /proc and /sys filesystems in Linux are both pseudo-filesystems that provide access to kernel data, but they differ in their primary purpose and content. /proc primarily focuses on providing information about processes running on the system, including their status, resources, and other relevant details. /sys, on the other hand, offers a window into the kernel’s hardware configuration and exposes settings that can be modified to manage the system.
Here’s a more detailed comparison:
/proc:
Focus: Process information.
Content: Each running process has a subdirectory under /proc named after its process ID (PID). This subdirectory contains files that provide information about that process, such as its current working directory, memory usage, and other details.
Example: The ps command uses /proc to retrieve process information.
Purpose: To query real-time information about processes running on the system.
/sys:
Focus:
Hardware configuration and kernel settings.
Content:
/sys exposes various files and directories that represent hardware devices, drivers, and kernel settings.
Example:
You can use /sys to check the status of a USB device or configure its parameters.
Purpose:
To allow administrators and applications to interact with and manage the hardware and kernel.
In essence, /proc is a snapshot of the running processes, while /sys provides a means to interact with and configure the system’s hardware and kernel.

134
Q

Example subdirectories in /sys

138
Q

findmnt –fstab -t nfs

What does this command do?

A

findmnt –fstab -t nfs Prints all NFS filesystems defined in /etc/fstab. findmnt –fstab /mnt/foo Prints all /etc/fstab filesystems where the mountpoint directory is /mnt/foo. It also prints bind mounts where /mnt/foo is a source.