Manipulating files and directories Flashcards

1
Q

What is the command to create a directory?

A

mkdir

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

What is the command to remove an empty directory?

A

rmdir

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

What is the command to remove a directory with contents

A

rm -r

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

What is the command to create a parent directory and subdirectory?

A

mkdir -p

i.e mkdir -p parent/child

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

What is the command to create a non existing file/ update the timestamp of an existing file/directory?

A

touch

i.e touch file

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

What is the command to rename a file/directory?

A

mv

i.e mv oldname newname

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

What is the command to copy a directory and its contents?

A

cp -r

-R –recursive

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

What is the command to create a symbolic link?

A

ln -s >pathtoreference< >link<

i.e ln -s /var/spool/mail mail

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

When creating a symlink, what are the permissions?

A

Full permissions to view where the link points to, however it does not reflect the permissions of the file it is linking to.

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

How do you create a hard link?

A

ln >pathtorefrence< >link

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

How does a hard link work?

A

Links directly to an inode on the file system, inode location will exist until all referring links are removed. Permissions/time stamp are identical across links. Unlike symbolic links hard links cannot link across file systems (inc. partitions)

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

How do you view the inode for a file/directory?

A

ls -i

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

How many links will a symbolic link have vs a hard link?

A

Symbolic link will have 1 link to the location

Hard link will have 2 links because each links to an inode location

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

What is the syntax that constitutes a file permission?

A
  • |rwx|rwx|rwx (read write execute)
    type|user|group|other
    no access means -
    i.e -|r-x|-w-|rw-
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the syntax that constitutes a directory permission?

A

d|rwx|rwx|rwx (read write cdinto)
type|user|group|other
no access means -
i.e d|r-x|-w-|—

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

What is the octal notation associated with a file/folder permission?

A

d|421|421|421
d|rwx|rwx|rwx
-|421|421|421
-|rwx|rwx|rwx

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

What would the octal notation equivalent be for d|r-x|r-x|rwx?

A

d|r-x|r-x|rwx = d|5|5|7

d|4+0+1|4+0+1|4+2+1

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

What would the octal notation equivalent be for -|rwx|r–|—?

A
  • |rwx|r–|— = -|7|4|0

- |4+2+1|4+0+0|0+0+0

19
Q

How would you change the permissions of a file/folder without octal notation?

A

chmod u/g/o +/- r/w/x file/folder

i. e chmod ug+x file/folder
* have to repeat for giving unique permissions (appending and omitting)

20
Q

How could you change the permissions of a file/folder using octal notation

A

chmod nnn file/folder

i. e chmod 750 file/folder
* efficient in giving unique permissions in one command (arbitrarily set)

21
Q

What is a sticky bit?

A

In linux all users including other can delete a write protected file if they have permissions (wx) of the containing folder
Setting the sticky bit on folder allows deletion only with elevated privileges, essentially write privileges for creation but not deletion. i.e. /tmp

22
Q

How do you set the sticky bit for a folder without octal notation?

A

chmod o+t folder

*only applies to the permission of other

23
Q

How do you remove the sticky bit for a folder without using octal notation?

A

chmod o-t folder

24
Q

How do you set the sticky bit for a file using octal notation?

A

chmod 1nnn folder

i.e chmod 1770 folder

25
Q

How do you remove the sticky bit for a folder using octal notation?

A

chmod 0nnn folder

i.e chmod 0770 folder

26
Q

What is the command to change the owner of a file or directory?

A

chown user:group file

*leave either field blank to change only user/group

27
Q

How do you change the permissions of a folder recursively?

A

chmod -R >permission< directory

28
Q

How would you change the permissions of the contents of a directory excluding the folder itself?

A

chmod -R >permission< directory/*

29
Q

What is the permission hierachy for files and directories?

A

user
group
other

*first membership applies

30
Q

What is the command to remove a symbolic link?

A

unlink

i.e unlink linkename

31
Q

What is denoted by file with c as the listing?

A

Character device

32
Q

What is denoted by file with b as the listing?

A

Block device

33
Q

What is denoted by file with l as the listing?

A

Symbolic Link

34
Q

What defines default permissions for a file/directory?

A

umask

35
Q

How do you apply permissions recursively to a folder?

A

chmod -R

36
Q

What is the command to log into a group and create a file/directory with the specified group instead of the user?

A

newgrp

i. e newgrp wheel
* newgrp to logout

37
Q

When applying execute permissions to a directory recursively, how do you exclude files within the directory

A

chmod u/g/o+X

*capital symbols, only works with execute permission

38
Q

What are setuid and setgid?

A

setuid enables a file to be ran with the exact permissions as the owner of the file *i.e /usr/bin/passwd
setgid enables a file to be ran with the exact permissions as the group of the file *i.e /usr/bin/wall

39
Q

How do you modify a file to setuid and setgid with octal notation?

A

setuid - chmod 4nnn
setgid - chmod 2nnn
i.e chmod 6754 would setuid and setgid for file

40
Q

How do you modify a file to setuid and setgid with symbolic notation?

A

setuid - chmod u+s

setgid - chmod g+s

41
Q

When creating a file/directory, what will the group owner be?

A

The primary group of the user the file/directory was created with

42
Q

How do you use object notation to set unique permissions?

A

chmod u=,g=,o=

i.e chmod u=rwx,g=rwx,o=rx

43
Q

To delete a file, what permissions are required?

A

Write and execute permissions to the containing directory

*file permissions are not relevant

44
Q

How would you make the the contents of a directory always have the same group owner as the directory itself?

A

use SETGID
chmod g+s {directory}
Any new files/directories within the folder will have the same group owner