Week 5: Files, Directories, and Pointers Flashcards

1
Q

What is a file?

A

A container for data which is persistent and accessible by name

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

What are UNIX files?

A

Unix file types: regular, directory, device, link and
etc.

Unix files are identified by a name in a directory

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

What is a “Regular” file?

A

essentially a sequence of bytes

can access these bytes in order

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

What is a “Directory” file?

A

a file containing name and pointer (inode number)

pairs for files and subdirectories in the directory

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

What is a “Device” file?

A

access a device (like a soundcard, mouse,

terminal, or …) like it is a file

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

What are “Links”

A

hard link: create another name for a file

soft link: a pointer to another file

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

What option can be used to get file information?

A

-F

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

What does the UNIX file system represent? What represents the root?

A

An upside-down tree

/ represents root

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

What is the difference between an absolute pathname and a relative pathname?

A

Absolute: to identify where a file is, concatenate the directories
together, can be anywhere in the UNIX file system

Relative: pathnames relative to the current working
directory

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

What pathways signify home?

A

$HOME

/user/home

~

or simply cd

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

What do the following represent in file locations?

/
~
.
..

A

/ means root
~ means home
. means current directory
.. means parent directory

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

What does mkdir dirname do?

A

Makes a new directory in the current directory with the name “dirname”

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

What does rmdir do? When does it work? Not work?

A

Removes a directory, only works if the directory exists and is empty

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

What does cp text1 text2 do if:

text1 is a file

text2 is a directory?

A

Copies text1 to directory text2

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

What does cp text1 text2 do if:

text1 is a directory

text2 is a directory?

A

Nothing, you need to add the
-r option to make it recursive:

cp -r text1 text2

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

What does cp -r text1 text2 do if:

text1 is a directory

text2 is a directory?

A

Copies directory text1 and all of its contents to directory text2

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

What is the command to create a link? Format?

A

ln readme.txt unix_is_easy

Creates a link to readme.txt called unix_is_easy

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

What is a hard link?

A

An indirect pointer to another file or directory

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

What command searches through directories for a file? Format?

A

find

find PATH EXPRESSION

e.g. Find all files and directories named README
starting from the current directory:
find . –name “README”

Note: the dot before -name

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

What does ls -a do?

A

list all files including those

beginning with a . (dot)

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

What does head do?

A

head displays the

top lines of a file

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

What command can you use within a “man” veiwer to go to the next page?

A

Spacebar

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

What command can you use within a “man” veiwer to quit?

24
Q

What characters are valid as file names?

A

Almost any character is valid in a file name, the exception is the / (slash) character and null character

25
Are UNIX file names case-sensitive?
Yes
26
gcc looks for what extensions by default?
.c for C program files .h for header files .o for an object file
27
What does the file command do? file filename
Print the type of the file
28
How do you delete a file with the name -i?
rm -- -i -- means no options
29
For wildcarding, what does * mean (asterisk)
matches a sequence of zero or more characters
30
For wildcarding, what does ? mean
Matches any single character
31
For wildcarding, what does [...] mean
Matches any of the one characters between the braces
32
What do double quotes do in shell?
Stops interpretation of some | shell special characters (whitespace mostly, *, ~)
33
What do single quotes do in shell?
Stops interpretation of even more specials like $ ex: $HOME
34
What does Ctrl-V do in shell?
Quotes the next character, even if it is a control | character
35
What are the three levels of file permission?
user = the owner of the file group users = a group of people set by the user others = everyone else
36
What command shows file permission?
ls -l
37
What is this? drw-r-xr--
First character (d here) indicates file type The rest is permission in the order of user, group, others In the order of rwx (read write execute)
38
What is the syntax (using numbers) of chmod and what does it do?
Sets file permissions chmod DDD file [file ...] chmod 644 file Where the three numbers (up to 7) indicate binary numbers
39
What is the symbolic syntax of chmod?
chmod [ugoa][+-=][rwx] file [...] [ugoa] indicates who [+-=] indicates add, remove, or exactly equal to [rwx] indicates what permission(s)
40
What does the -R flag do for chmod?
It recursively changes the mode for each chmod operand that is a directory.
41
What is umask? How does it work?
Sets the default permissions for any file you will create Format is backwards to the chmod command – tells you which permissions will NOT be given umask 077 means don't let anyone but the User do anything with my files by default
42
Pointers must have a
Type
43
What does an * do for pointers?
Declare a pointer AND what the address points to
44
What does an & do for pointers?
Return the address of the variable
45
All pointer variables in a 16-bit architecture are ... bytes
2 bytes
46
All pointer variables in a 32-bit architecture are ... bytes
4 bytes
47
Pointer variables contain
The address in memory of another variable
48
All pointer variables in a 64-bit architecture are ... bytes
8 bytes
49
What does int j = *&i; do?
/* same as j = i; */
50
What does the following do? char ca[3],*cap; cap = &(ca[1]); *cap = 7;
Creates a character array with 3 elements and a character pointer called cap The pointer cap is assigned the address of the SECOND element in the array Go to the address location and make it 7
51
In pointer arithmetic, what is important
The type of the variable
52
How many bytes will the following pointer arithmetic move if the array contains integers? ``` cp = &(ca[0]); *(cp+2) = 8; ```
8 bytes (2 x 4 bytes)
53
How many bytes will the following pointer arithmetic move if the array contains characters? ``` cp = &(ca[0]); *(cp+2) = 8; ```
2 bytes (2 x 1 bytes)
54
How many bytes will the following pointer arithmetic move if the array contains double floats? ``` cp = &(ca[0]); *(cp+2) = 8; ```
16 bytes (2 x 8 bytes)
55
What is a void pointer? How do you reference it?
Declared by: void *pV; A void pointer in c is called a generic pointer, it has no associated data type. printf("c = %c\n\n",*((char*)pV)); printf(“db = %lf\n\n",*((double *)pV));
56
What is an inode number?
A pointer to a directory in UNIX