cmpt 214 part1: L00,L01,L02,L03,A1,Lab 1,L010 Flashcards
Midterm cmpt 214 part 1
What is used to control access to a UNIX system?
A combination of a User ID and a password.
How is the UNIX filesystem structured?
It uses a hierarchical structure with directories and subdirectories.
What is meant by the UNIX filesystem being a single-root directory structure?
All files and directories stem from a single root directory, denoted by /. Every file or directory in UNIX can be traced back to the root.
How do you represent the absolute path of a file?
Absolute paths start from the root /, e.g., /home/user/file.txt.
What is the working directory in UNIX?
The working directory is the current directory where you are operating. You can find it using the pwd (print working directory) command.
What is an absolute path?
An absolute path starts from the root / and specifies the location of a file or directory fully, e.g., /home/user/documents.
What is the difference between external programs and built-in commands in UNIX?
Built-in commands are part of the shell itself (e.g., cd, echo), while external programs are separate executables stored in the filesystem (e.g., grep, ls, cat).
How can you check if a command is built-in?
Use the type command, e.g., type cd will tell you if cd is a shell built-in.
Command: let vs. $((…)) for Arithmetic
Q: How do you use let for arithmetic in UNIX?
Q: How do you use $((…)) for arithmetic in UNIX?
A: let is used for arithmetic evaluation. Example: let result=5+3 assigns 8 to the variable result.
A: $((…)) also performs arithmetic. Example: result=$((5 + 3)) assigns 8 to the variable result.
Redirection
Q: What is input redirection?
Q: What is output redirection?
Q: How do you append output to a file?
A: Input redirection takes input from a file instead of the keyboard. Example: command < input.txt.
A: Output redirection sends the output of a command to a file instead of the screen. Example: command > output.txt.
A: Use»_space; to append output. Example: echo “Text”»_space; file.txt.
Mounting Filesystems
Q: What does mounting a filesystem mean in UNIX?
A: Mounting means making a filesystem accessible under a directory. For example, mount /dev/sda1 /mnt mounts the /dev/sda1 partition at /mnt.
Pipelines
Q: What is a pipeline in UNIX?
A: A pipeline uses the | symbol to pass the output of one command as input to another. Example: cat file.txt | grep “keyword”.
Pipeline Example: tr
Q: How does the tr command work in a pipeline?
A: tr translates or deletes characters. Example: cat file.txt | tr ‘a-z’ ‘A-Z’ converts all lowercase letters to uppercase.
Recap of Key Spacing Rules:
Spaces required:
Between commands and their arguments.
Inside conditionals and loops.
Around comparison operators and arithmetic with expr.
**Spaces not allowed:
In variable assignments (x=5).
Inside arithmetic expansion ($((5+3))).
Between function names and parentheses (my_function()).
cat vs. echo
Q: What’s the difference between cat and echo?
A: cat is used to display file contents, whereas echo outputs text or the value of a variable to the terminal.
Command: cat
Q: What does the cat command do in UNIX?
: The cat command concatenates and displays the content of files.
Q: How would you use cat to display the content of a file named “file.txt”?
cat file.txt
Filesystem Layers
Q: Name the layers of the UNIX system.
A: Hardware, Drivers, Kernel, Utilities, and User Applications.
Q: What tools can be used to monitor processes in UNIX?
A: top and htop.
Command Structure
Q: What is the general format for UNIX commands?
A: command -[options] [arg1] [arg2] … [argn] RETURN.
(return-> keystroke for excution into the terminal)
Help and Manual Pages
Q: How can you display a help message for a UNIX command?
Help and Manual Pages
Q: How can you display a help message for a UNIX command?
: By using command –help.
:by using the man command (e.g., man ls)
Bash Scripting
Q: How do you make a Bash script executable?
A: By using the command chmod +x scriptname.sh.
Q: What is the purpose of #!/bin/bash in a Bash script?
A: It specifies that the script should run in the Bash shell.
Q: How do you assign and access variables in Bash?
A: Use = for assignment and $ for access (e.g., x=5, echo $x).