Linux file system Flashcards

1
Q

What is the -l flag in the ls linux command?

A

Long listing

Shows metadata about files, including permissions

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

What are the components of the ls -l listing?

A

File type (e.g. d or -)
Permissions (rw-r–r–)
Extended attributes (.)
User owner
Group owner

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

What does the filetype - mean?

A

No special type (normal file)

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

How is filetype formatted in the ls -l command?

A

The first symbol, in front of permissions:

Filetype: -
-rw-r–r–

Filetype: d (directory)
drw-r–r–

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

What is XFS?

A

Default filesystem format in Red Hat Linux 7, 8 and 9

High-performing, journaling file system

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

How are file permissions formatted?

A

In 3 sets of permissions

rw-r–r–:
Owner: rw-
User group of the owner: r–
Others: r–

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

What are the representations in symbolic mode?

A

u: user owner
g: group owner
o: Others

r: read
w: write
x: execute

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

How does the system run through when a user interacts with a file?

A
  1. First check if user is the owner. If so, grant owner permissions, run no further checks.
  2. Next, the users group membership is validated to see if they belong to the owner group. If so, group permissions are granted. No further checks.
  3. “other” permissions are applied if the two previous checks fail.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does a user’s permission expression contain?

A

Expression include 3 basic types of permission: r, w, x

Each character indicates if a permission is granted

symbol: granted
-: not granted

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

How can permissions be represented in numeric mode?

A

a 3-digit value represents specific file permissions, called octal values.
First digit is owner, second is group, third is other.

r: 4
w: 2
x: 1

If the owner has value 7, it means the permissions are as such:
rwx = 4+2+1 = 7

If the group has value 4, the permissions are:
r– = 4+0+0 = 4

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

What does the read permission allow a user?

A

Access file content, e.g. through using the command cat or less or an editor.

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

What is the cat command?

A

Concatenate files and print on the standard out

If we use cat on multiple files, the file contents will be concatenated and sent to stdout

cat file1 file2

result:
file1 contents
file2 contents

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

What permissions are required to copy a file?

A

read

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

What does the write permission allow a user?

A

Modify content of file

Allows the user to use the redirect or append operators in the shell (> and&raquo_space;) to change the contents of a file

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

What does the execute permission allow a user?

A

Allows to execute the contents of a file.
Allows to run bash script, python files and interpreted languages.

The contents are typically commands or compiled binary applications.

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

What is the redirect operator in shell?

A

command > filename

Redirect the output of a command to for example a file.

File is created if it does not exist, and overwritten if it does.

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

What is the append operator in shell?

A

command&raquo_space; filename

Used to append the stdout of a command to a file.

Can be used to e.g. append data to a log file.

File is created if it does not exist, data appended if it does.

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

What is the default stdin device (standard input)

A

Keyboard

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

What is the default stdout device (standard output)

A

Screen or particular terminal window

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

What is redirection of output?

A

When we want to put output of a command in a file (>) or issue another command on the output of one command.

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

What does the | (pipe) operator do?

A

Sends the stdout of one command as stdin of another command.

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

What is the difference between the > and the&raquo_space; operator?

A

> replaces content of a file, whereas&raquo_space; appends to the content of a file

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

How can the contents of a file be executed when we do not have the execute permissions?

A

Use an interpreter that has execute permissions to read a file with instructions for the interpreter to execute.

Example: Invoking a bash shell script:
bash script.sh

The executable being run is bash
script.sh is only being read by the Bash interpreter

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

How does read permissions work for directory files?

A

Allows the user to read the contents of the directory.

This means that the user can view the contents (or files) stored within the directory. Required for e.g. “ls -l” to work

25
Q

How does write permissions work for directory files?

A

Allows a user to modify the contents of the directory, meaning adding or removing files from directory.

26
Q

How does execute permissions work for directory files?

A

Execute provides access to the directory.

It authorizes a user to look at extended info on files (ls -l), but also allows you to change working directory (cd), or pass through this directory on the way to a subdirectory.

27
Q

What permission is required for a user to be allowed to move (mv) or remove (rm) files from a directory?

A

Write

28
Q

What permission is required for a user to be allowed to create new files (touch) or copy (cp) files into a directory?

A

write

29
Q

What is the touch command?

A

Creates a file if the FILE argument does not exist

For an existing file, updates the access and modification times of the FILE argument

30
Q

What happens if a user has write permissions to a directory, but not execute permissions?

A

Can no longer add files to a directory because the user cannot access the directory’s metadata to store the information for a new, additional file.

TODO: Try this in practice, create a directory with -w- permissions and check if a file can be accessed.

31
Q

How can file and directory permissions be modified?

A

chmod command

32
Q

What is the chmod command?

A

Change mode, changes permissions of a file or directory.

Numeric mode:
chmod 744 filename.txt

Symbolic mode: Enter a user class and the permissions you want to grant them

chmod ug+rwx file.txt
This gives rwx permissions for owner (u) and owner’s group (g)

chmod o+r file.txt
Gives r permissions for others

33
Q

How can you define permissions for all users at once?

A

chmod a

34
Q

What is the chown command?

A

Change a file’s owner and/or group

If a username or ID is given, this username is made the owner of the file, the file’s group is not changed.
chown root file.txt

If the username is followed by a colon and a groupname or ID, the file group is changed.
chown root:staff file.txt

If the username is followed by only a colon, the user owner is changed and the file’s group is changed to the group of the new owner.

If only a colon and a group is provided, only the file’s group is changed (functions the same as chgrp)

If only a colon is provided, or the operand is empty, nothing changes for the file.

35
Q

What is the chgrp command?

A

Changes the group of a file.

chgrp staff file.txt

36
Q

What are special file permissions?

A

Provides additional privileges over the standard rwx permissions

37
Q

What is SUID?

A

The special permission for the user access level. A file with SUID always executes as the user who owns the file, no matter who is passing the command.

To add SUID, the x permission is replaced by s for the owner.

-rwsr-xr-x

38
Q

What does +-= mean in chmod?

A

Add, remove and set exact permission

chmod a+r file.txt
Every user gets the r permission

chmod go-w file.txt
Write permission is removed from group and others

39
Q

What is the SGID permission?

A

If s is set on a file, allows it to be executed as the file group of the file.

If s is set on a directory, any files created in the directory will have their group ownership set to that of the directory owner.

drwxrwsr–
Directory: s replaces x for the group permissions

-rwxrws—
File: s replaces x for the group permissions

40
Q

When is an uppercase S used for SUID?

A

The owning group does not have execute permissions

41
Q

What is the sticky-bit permission?

A

Does not affect individual files, but at directory level, it restricts file deletion.

Only the owner (and root) can remove the file within the directory.

drwxrwxrwt

t replaces x

42
Q

How is special permissions added using chmod?

A

Symbolic:
chmod g+s filename (SGID)

Numeric:
SUID: 4
SGID: 2
Sticky: 1
chmod X### filename
X: special permission digit

43
Q

What is the l file type?

A

Symbolic link

Special files that refers to another file or directory in the system.

Shortcuts that points directly to the original file.

Allows multiple access point to a single file

44
Q

What is the -ld flag to “ls -ld”?

A

If the supplied name is a directory, show info of the directory itself, and not the content of the directory

45
Q

How can you add a new group in a system?

A

groupadd GROUPNAME

46
Q

How can you add a new user to a system?

A

useradd USERNAME

47
Q

How does the mv command work?

A

mv SOURCE DEST

DEST or DIRECTORY

Renames SOURCE file to DEST

Moves SOURCE to DIRECTORY/SOURCE

48
Q

Who can change the permissions of a file/directory?

A

The owner

49
Q

What is the su command?

A

Run a command with a substitute user and group ID

Runs a command as another user

su - username
-: starts shell as login shell, which resets all environment variables and creates them again.

50
Q

What is the difference between su and sudo commands?

A

Sudo: Acronym for superuser do or substitute user do

Runs an elevated prompt without need to change identity.
Let’s a user issue commands as another user, does not switch user.

Su: acronym for switch user or substitute user

Basically switching to this user, requires password of user

51
Q

What command is used to stop running commands as a different user (after running su)

A

exit

52
Q

What are root able to do?

A

remove any or all files

Change permissions of any or all files

Change the runlevel of the system

Alter user accounts

Mount or unmount filesystems

Remove or install software

Create, remove and alter file systems

53
Q

How can you switch to root using su?

A

su -

-: provides root environment (path and shell variables)

Should not switch to root using su, as the terminal will become root - too much power.

54
Q

When do you not need to provide a password when running su username?

A

When username is not root, and you are running as root when issuing su username

55
Q

What does the command “find -perm 775” do?

A

No path is added so the command look in the current directory for files with 775 permission level

56
Q

What does the command “find -perm -775” do?

A

The find command returns anything with permissions greater than or equal to 775.

Looks recursively, so not only in the current directory, but also sub-directories

57
Q

What does -type f mean in “find -perm -755 -type f” ?

A

Only targets files, not directories

58
Q

What does {} \; mean in “find -perm -755 -type f -exec chmod 600 {} \;”

A

It tells the find command that it should execute chmod individually for each file matching the find-criteria

59
Q

What is the -exec option of the find command?

A

Allows us to run a command on the result from “find”