Flashcards in Topic 4 - Unix Files and Directories Deck (68):
What is a computer file?
A container for a sequence of bytes
What are the 4 types of files?
1) Regular normal file
4) Device (Unix treats a device like a file
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
What is the cmd for determining the current directory?
pwd (print working directory)
cmd for changing directories?
The cmd "ls" does what?
listing the contents of a directory
How is the Unix filesystem organized?
As un upside-down tree; top of the filesystem is the root
Whats the symbol for the root directory?
How do you change from the current directory to the root directory?
Examples of file names in unix:
Are the letters *,@, and / part of the file name?
No, just indicators to give more information about the file
A typical Unix file system spans _____ disks?
As a user, do you need to know which physical disk is used to store your things?
What is the cmd for reporting on all mounted file system?
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
What does ~ mean?
Refers to the $HOME directory
What does "cd" with no arguments do?
Changes the working directory to your home directory
Define Relative Pathnames
Specifying pathnames relative to the current working directory using . and ..
what does " .. " mean?
Start from parent directory
What does " . " mean?
Start from the current directory
How do you create a new directory?
How do you remove a directory? (as long as it exists and is EMPTY)
How do you move a file or directory?
How do you copy a file from one directory to another?
How do you copy a directory?
Use a recursive copy: "cp -r" to copy the directory
Pushd does what?
changes the current working directory, and also remembers the previous one by pushing it on to ta stack
Popd does what?
change the current working directory back to the last directory placed on the stack by pushd
dirs does what?
Keeps track of what you have so far in the stack
How do you reveal hidden files?
How you display the first few lines of a file? (Default 10)
How do you display the last few lines of a file (default 10)
What is the only invalid character in a Unix file name?
the Slash ( / ) - used for pathnames
Which ones are not legal Unix file names?
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)
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.
How can you determine if a file is executable?
using the "file" command --> file filename
Give 3 examples of Wildcard Characters:
What does the wildcard * do?
matches a sequence of zero or more characters:
a*.c --> matches abbb.c, aaaa.c, aldkfjaklf.c
What does the wildcard ? do?
matches any single characters
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
What acts as a boundary for wildcards to ensure matching does not go beyond filenames into the file path?
the slash ( / ) in the pathnames
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 "."
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
What do single quotation marks do?
Does everything double quotation marks do plus stops variable expansion ($HOME, etc.)
What do Back Quotes do?
Text between back quotes leads to executing the text as a command and returning the results instead
What is the name of the single control structure Unix creates for each file?
Index Node (ie. inode) for each file
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.
Ls -i displays ____?
The inode number of each file.
Ls -l displays _____?
Displays permissions AND the number of existing links per file.
Each hard link acts like a _______?
a pointer to the actual file.
Whats a symbolic link?
"ln -s" is an indirect pointer to another file or directory
Removing any one of a file's hard links except one ______ [will or will not] remove the contents of the file?
Removing all of a file's hard links ______ [will or will not] remove the contents of the file?
Removing a file's symbolic link ______ [will or will not] affects the file
Removing the symbolic link ________ [will or will not] remove the contents of the file.
What happens when you remove the original file that has a symbolic pointer?
The symbolic pointer will point to an unknown file
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
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
How do you view Permissions?
the command ls -l
what does "r" mean?
what does "w' mean?
what does "x" mean?
How do you change / assign permissions?
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.
Describe the numeric method for chmod command.
Numeric method: chmood DDD file [file..]
1 2 4 = --x -w- r--
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
How do you set default permissions for any file you will create?
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
Directory permissions are different from file permissions:
Listing file names requires:_____
Creating file names requires: _____
Accessing files information (if you know the name) requires:_____