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?

A

q

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
Q

Are UNIX file names case-sensitive?

A

Yes

26
Q

gcc looks for what extensions by default?

A

.c for C program files
.h for header files
.o for an object file

27
Q

What does the file command do?

file filename

A

Print the type of the file

28
Q

How do you delete a file with the name -i?

A

rm – -i

– means no options

29
Q

For wildcarding, what does * mean (asterisk)

A

matches a sequence of zero or more characters

30
Q

For wildcarding, what does ? mean

A

Matches any single character

31
Q

For wildcarding, what does […] mean

A

Matches any of the one characters between the braces

32
Q

What do double quotes do in shell?

A

Stops interpretation of some

shell special characters (whitespace mostly, *, ~)

33
Q

What do single quotes do in shell?

A

Stops interpretation of even more specials like $

34
Q

What does Ctrl-V do in shell?

A

Quotes the next character, even if it is a control

character

35
Q

What are the three levels of file permission?

A

user = the owner of the file

group users = a group of people set by the user

others = everyone else

36
Q

What command shows file permission?

A

ls -l

37
Q

What is this?

drw-r-xr–

A

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
Q

What is the syntax (using numbers) of chmod and what does it do?

A

Sets file permissions

chmod DDD file [file …]
chmod 644 file

Where the three numbers (up to 7) indicate binary numbers

39
Q

What is the symbolic syntax of chmod?

A

chmod [ugoa][+-=][rwx] file […]

[ugoa] indicates who

[+-=] indicates add, remove, or exactly equal to

[rwx] indicates what permission(s)

40
Q

What does the -R flag do for chmod?

A

It recursively changes the mode for each chmod operand that is a directory.

41
Q

What is umask? How does it work?

A

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
Q

Pointers must have a

A

Type

43
Q

What does an * do for pointers?

A

Declare a pointer AND what the address points to

44
Q

What does an & do for pointers?

A

Return the address of the variable

45
Q

All pointer variables in a 16-bit architecture are … bytes

A

2 bytes

46
Q

All pointer variables in a 32-bit architecture are … bytes

A

4 bytes

47
Q

Pointer variables contain

A

The address in memory of another variable

48
Q

All pointer variables in a 64-bit architecture are … bytes

A

8 bytes

49
Q

What does

int j = *&i;

do?

A

/* same as j = i; */

50
Q

What does the following do?

char ca[3],*cap;
cap = &(ca[1]);
*cap = 7;

A

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
Q

In pointer arithmetic, what is important

A

The type of the variable

52
Q

How many bytes will the following pointer arithmetic move if the array contains integers?

cp = &(ca[0]);
*(cp+2) = 8;
A

8 bytes (2 x 4 bytes)

53
Q

How many bytes will the following pointer arithmetic move if the array contains characters?

cp = &(ca[0]);
*(cp+2) = 8;
A

2 bytes (2 x 1 bytes)

54
Q

How many bytes will the following pointer arithmetic move if the array contains double floats?

cp = &(ca[0]);
*(cp+2) = 8;
A

16 bytes (2 x 8 bytes)

55
Q

What is a void pointer? How do you reference it?

A

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
Q

What is an inode number?

A

A pointer to a directory in UNIX