Topic 4 - Unix Files and Directories Flashcards

1
Q

What is a computer file?

A

A container for a sequence of bytes

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

What are the 4 types of files?

A

1) Regular normal file
2) Directory
3) Link
4) Device (Unix treats a device like a file

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

Does the shell remember the current directory for you or do you have to remember the current directory on your own.

A

The shell remembers the current directory for you

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

What is the cmd for determining the current directory?

A

pwd (print working directory)

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

cmd for changing directories?

A

cd

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

The cmd “ls” does what?

A

listing the contents of a directory

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

How is the Unix filesystem organized?

A

As un upside-down tree; top of the filesystem is the root

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

Whats the symbol for the root directory?

A

/

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

How do you change from the current directory to the root directory?

A

cd /

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
Examples of file names in unix:
a.out(
data@
readme.txt
tmp/
Are the letters *,@, and / part of the file name?
A

No, just indicators to give more information about the file

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

A typical Unix file system spans _____ disks?

A

Many

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

As a user, do you need to know which physical disk is used to store your things?

A

No

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

What is the cmd for reporting on all mounted file system?

A

df.

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

Definition of Absolute Pathnames?

A
  • start from the root directory ie. /
  • string together all directory names that are in your path to the file
  • separate each directory name by a single slash
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What does ~ mean?

A

Refers to the $HOME directory

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

What does “cd” with no arguments do?

A

Changes the working directory to your home directory

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

Define Relative Pathnames

A

Specifying pathnames relative to the current working directory using . and ..

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

what does “ .. “ mean?

A

Start from parent directory

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

What does “ . “ mean?

A

Start from the current directory

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

How do you create a new directory?

A

mkdir

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

How do you remove a directory? (as long as it exists and is EMPTY)

A

rmdir

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

How do you move a file or directory?

A

mv

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

How do you copy a file from one directory to another?

A

cp [filename]

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

How do you copy a directory?

A

Use a recursive copy: “cp -r” to copy the directory

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

Pushd does what?

A

changes the current working directory, and also remembers the previous one by pushing it on to ta stack

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

Popd does what?

A

change the current working directory back to the last directory placed on the stack by pushd

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

dirs does what?

A

Keeps track of what you have so far in the stack

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

How do you reveal hidden files?

A

ls -a

29
Q

How you display the first few lines of a file? (Default 10)

A

head command

30
Q

How do you display the last few lines of a file (default 10)

A

tail command

31
Q

What is the only invalid character in a Unix file name?

A

the Slash ( / ) - used for pathnames

32
Q

Which ones are not legal Unix file names?
a
a.
.a

a.b.c

A

None, they’re all legal - Unix does not enforce file name extensions. Just remember: any name beginning with a dot is hidden where “ls” command cannot see them but the “ls -a” command can.
(Note: the . and .. are reserved for current and parent directories)

33
Q

Give an example of an extension for executable files.

A

Executable files usually have no extensions. This does make distinguishing executable files from data files a bit difficult.

34
Q

How can you determine if a file is executable?

A

using the “file” command –> file filename

35
Q

Give 3 examples of Wildcard Characters:

A

1) *
2) ?
3) […]

36
Q

What does the wildcard * do?

A

matches a sequence of zero or more characters:

a*.c –> matches abbb.c, aaaa.c, aldkfjaklf.c

37
Q

What does the wildcard ? do?

A

matches any single characters

38
Q

What does the wildcard […] do?

A

Matches any single character between the braces:
b[aei]t –> matches bat, bet, or bit, not baet, or bt
You can use a hyphen: [A-Z] to match a range. in this example, it’ll match the alphabet of capital letters

39
Q

What acts as a boundary for wildcards to ensure matching does not go beyond filenames into the file path?

A

the slash ( / ) in the pathnames

40
Q

Using * or ?, can you match a dot (.) at the beginning of a filename? Anywhere else in the filename? Comment on your answer.

A

No. Yes. A dot ( . ) at the beginning of a filename must be matched explicitly i.e. with a literal “.”

41
Q

What do double quotation marks do?

A
  • Stops the interpretation of some shell special characters (whitecaps and wild cards)
  • Forces the shell to deal with whatever between the two quotes as one token
42
Q

What do single quotation marks do?

A

Does everything double quotation marks do plus stops variable expansion ($HOME, etc.)

43
Q

What do Back Quotes do?

A

Text between back quotes leads to executing the text as a command and returning the results instead

44
Q

What is the name of the single control structure Unix creates for each file?

A

Index Node (ie. inode) for each file

45
Q

Wha happens when a file is created in terms of its inode?

A

When the file is created, there is one link to the file’s inode.

46
Q

Ls -i displays ____?

A

The inode number of each file.

47
Q

Ls -l displays _____?

A

Displays permissions AND the number of existing links per file.

48
Q

Each hard link acts like a _______?

A

a pointer to the actual file.

49
Q

Whats a symbolic link?

A

“ln -s” is an indirect pointer to another file or directory

50
Q

Removing any one of a file’s hard links except one ______ [will or will not] remove the contents of the file?

A

will not

51
Q

Removing all of a file’s hard links ______ [will or will not] remove the contents of the file?

A

Will

52
Q

Removing a file’s symbolic link ______ [will or will not] affects the file

A

will not

53
Q

Removing the symbolic link ________ [will or will not] remove the contents of the file.

A

will not

54
Q

What happens when you remove the original file that has a symbolic pointer?

A

The symbolic pointer will point to an unknown file

55
Q

Who can do what when it comes to these 3 actions:

1) Creating a symbolic link to directories or files
2) Creating hard links to files
3) Creating hard links to directories

A

1) Any user
2) Any user
3) Only the super user / root user

56
Q

File Permissions: How does Unix divide up users in terms of who has what permissions with files?

A

3 Divison –> Owner User, Group User, Other users

1) Owner user: owner of the file
2) Group user: each file is assigned to one and only one group (superuser sets up groups)
3) Other users: everyone else

57
Q

How do you view Permissions?

A

the command ls -l

58
Q

what does “r” mean?

A

read permission

59
Q

what does “w’ mean?

A

write permission

60
Q

what does “x” mean?

A

execute permission

61
Q

How do you change / assign permissions?

A

Command: chmod

62
Q

What are the 2 syntaxes / methods you can use with the chmod command?

A

2 syntaxes / methods you can use: 1) numeric method 2) symbolic method.

63
Q

Describe the numeric method for chmod command.

A

Numeric method: chmood DDD file [file..]

1 2 4 = –x -w- r–

64
Q

Describe the symbolic method for chmod command.

A

Symbolic method; chmod [ugoa][+-=}[wrx] file[ […]
Relative: chmod u+rwx file – gives owner user R,W,X
Absolute: chmod g=r file –> gives group users R, makes sure it has nothing else
Relative and Absolute permission assignment can be appended with commas:
chmod u=rwx, g-w,o-rwx file

65
Q

How do you set default permissions for any file you will create?

A

command: umask

66
Q

Describe the umask command:

A

value is opposite to that of the chmod command:
tells which permissions will not be given - umask 077 means do not let anyone but the owner user to do anything with my files by default
Generally, set umask once in your .cshrc file and never set it again

67
Q

Directory permissions are different from file permissions:
Listing file names requires:_____
Creating file names requires: _____
Accessing files information (if you know the name) requires:_____

A

read permission
write permission
execute permission

68
Q

What does the -R option in chmod do?

A

useful when working with directories: it recursively changes the mode for each chmod operand that is a directory and all sub-directories and files receive those permissions.