using python to interact with the operating system week 6 answers
Practice Quiz: Interacting with the Command Line
1. Which of the following commands will redirect errors in a script to a file?
- user@ubuntu:~$ ./calculator.py >> error_file.txt
- user@ubuntu:~$ ./calculator.py 2> error_file.txt
- user@ubuntu:~$ ./calculator.py > error_file.txt
- user@ubuntu:~$ ./calculator.py < error_file.txt
2. When running a kill command in a terminal, what type of signal is being sent to the process?
- SIGINT
- SIGSTOP
- PID
- SIGTERM
3. What is required in order to read from standard input using Python?
- echo file.txt
- cat file.txt
- The file descriptor of the STDIN stream
- Stdin file object from sys module
4. _____ are tokens delivered to running processes to indicate a desired action.
- Signals
- Methods
- Functions
- Commands
5. In Linux, what command is used to display the contents of a directory?
- rmdir
- cp
- pwd
- ls
6. Which of the following commands will output a list of all files in the current directory?
- echo *.py
- echo ?.py
- echo a*
- echo *
7. Which module can you load in a Python script to take advantage of star [*] like in BASH?
- Glob
- ps
- Free
- stdin
8. Conditional execution is based on the _____ of commands.
- environment variables
- parameters
- exit status
- test results
9. What command evaluates the conditions received on exit to verify that there is an exit status of 0 when the conditions are true, and 1 when they are false?
- test
- grep
- echo
- export
10. The opening square bracket ([), when combined with the closing square bracket (]), is an alias for which command?
- glob
- test
- export
- if
11. Which command does the while loop initiate a task(s) after?
- done
- while
- n=1
- do
12. Which line is correctly written to start a FOR loop with a sample.txt file?
- do sample.txt for file
- for file in sample.txt; do
- for sample.txt in file; do
- for sample.txt do in file
13. Which of the following Bash lines contains the condition of taking an action when n is less than or equal to 9?
- while [ $n -le 9 ]; do
- while [ $n -lt 9 ]; do
- while [ $n -ge 9 ]; do
- while [ $n -ot 9 ]; do
14. Which of the following statements are true regarding Bash and Python? [Check all that apply]
- Complex scripts are better suited to Python.
- Bash scripts work on all platforms.
- Python can more easily operate on strings, lists, and dictionaries.
- If a script requires testing, Python is preferable.
15. The _____ command lets us take only bits of each line using a field delimiter.
- cut
- echo
- mv
- sleep