Topic 4 - Unix Files and Directories Flashcards Preview

CS 2211 - Unix > Topic 4 - Unix Files and Directories > Flashcards

Flashcards in Topic 4 - Unix Files and Directories Deck (68):
1

What is a computer file?

A container for a sequence of bytes

2

What are the 4 types of files?

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

3

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

The shell remembers the current directory for you

4

What is the cmd for determining the current directory?

pwd (print working directory)

5

cmd for changing directories?

cd

6

The cmd "ls" does what?

listing the contents of a directory

7

How is the Unix filesystem organized?

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

8

Whats the symbol for the root directory?

/

9

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

cd /

10

Examples of file names in unix:
a.out(
data@
readme.txt
tmp/
Are the letters *,@, and / part of the file name?

No, just indicators to give more information about the file

11

A typical Unix file system spans _____ disks?

Many

12

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

No

13

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

df.

14

Definition of Absolute Pathnames?

- 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

15

What does ~ mean?

Refers to the $HOME directory

16

What does "cd" with no arguments do?

Changes the working directory to your home directory

17

Define Relative Pathnames

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

18

what does " .. " mean?

Start from parent directory

19

What does " . " mean?

Start from the current directory

20

How do you create a new directory?

mkdir

21

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

rmdir

22

How do you move a file or directory?

mv

23

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

cp [filename]

24

How do you copy a directory?

Use a recursive copy: "cp -r" to copy the directory

25

Pushd does what?

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

26

Popd does what?

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

27

dirs does what?

Keeps track of what you have so far in the stack

28

How do you reveal hidden files?

ls -a

29

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

head command

30

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

tail command

31

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

the Slash ( / ) - used for pathnames

32

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

a.b.c

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

Give an example of an extension for executable files.

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

34

How can you determine if a file is executable?

using the "file" command --> file filename

35

Give 3 examples of Wildcard Characters:

1) *
2) ?
3) [...]

36

What does the wildcard * do?

matches a sequence of zero or more characters:
a*.c --> matches abbb.c, aaaa.c, aldkfjaklf.c

37

What does the wildcard ? do?

matches any single characters

38

What does the wildcard [...] do?

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

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

the slash ( / ) in the pathnames

40

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

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

41

What do double quotation marks do?

- 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

What do single quotation marks do?

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

43

What do Back Quotes do?

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

44

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

Index Node (ie. inode) for each file

45

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

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

46

Ls -i displays ____?

The inode number of each file.

47

Ls -l displays _____?

Displays permissions AND the number of existing links per file.

48

Each hard link acts like a _______?

a pointer to the actual file.

49

Whats a symbolic link?

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

50

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

will not

51

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

Will

52

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

will not

53

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

will not

54

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

The symbolic pointer will point to an unknown file

55

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

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

56

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

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

How do you view Permissions?

the command ls -l

58

what does "r" mean?

read permission

59

what does "w' mean?

write permission

60

what does "x" mean?

execute permission

61

How do you change / assign permissions?

Command: chmod

62

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

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

63

Describe the numeric method for chmod command.

Numeric method: chmood DDD file [file..]
1 2 4 = --x -w- r--

64

Describe the symbolic method for chmod command.

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

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

command: umask

66

Describe the umask command:

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

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

read permission
write permission
execute permission

68

What does the -R option in chmod do?

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.