---
# System prepended metadata

title: Linux and Bash scripting in-class test

---

# Linux and Bash scripting in-class test

## Instructions
1. This test takes 1 hour only
2. Answer all questions
3. This is an open-book test


## Questions

1. What is the best possible way to direct the shell for running a command in the background`

```
A. Put an & symbol at the end of the command line. 
B. Run the command after placing it inside a script.
C. Press Ctrl+c after you have keyed in the command.
D. Press Ctrl+d after you have keyed in the command.
 
```

2. What difference does the expression 2>&1 make to the result of the below command

$ find / -name test.txt > names 2>&1
```

```
A. Send the standard error to a file called &1
B. Append the standard error to a file called &1
C. Send the output of the find command to /dev/null
D. Send the standard error to the same place as the output.
 
```

3. Which of the following command would ask for confirmation before deleting files?

```
A. rm -a
B. rm -i
C. rm -chk
D. rm -r
```


4. From the following options, which one would run the ls command after printing the current date?

```
A. date $ ls -l
B. date; ls -l
C. date – ls -l
D. date > ls -l
```

5. What is the correct option that provides the command to sort a file named textfile on column 5?
```
A. sort -n 5 textfile
B. sort -k 5 textfile
C. sort -c 5 textfile
D. sort -c5 textfile
```


6. Which of the commands would search for the string “Linux” at the end of the line in a file called textfile?

```
A. grep ‘Linux# ‘ textfile
B. grep ‘ Linux! ‘ textfile
C. grep ‘ Linux$ ‘ textfile
D. grep ‘ Linux^’ textfile
```

 
7. What is the command to list the hidden files in your HOME directory?

```
A. ls -hn
B. ls -h
C. ls -la
D. ls -la ~/
```

8. What is the shortest command to take you back to the home directory?

```
A. cd ~
B. cd $HOME
C. cd
D. .
```


9. Which of the following best defines the purpose of the following operator >>?

```
A. Forwards the output of one command, so that it becomes the input for another.
B. It sends both input and output to the same file.
C. It’ll overwrite the contents of the target file.
D. Appends data to a file without overwriting it.
```


10. What is the command to start a job that will keep on running even after closing the session?
```
A. hup command
B. nohup command
C. jobc command
D. hup.out command
```


11. Where does Linux store the commands executed recently

```
A. .bashrc_history
B. .history
C. .bash_history
D. .bash_list_history

```


12. The output below was obtained by Mary after the `ls -l` command. Help Mary understand what the output means by describing what the content of each column means.

```
drwxrwxr-x    9 mary  user        4096 14 Feb  2019 variant_calling
-rwxr-xr-x    1 mary  user       18822  4 Apr  2018 vcfutils_1.pl
-rwxr-xr-x    1 mary  user       20533  4 Apr  2018 vcfutils_2.pl
```


13. How would Mary make use of the commands `chown`, `chgrp`, and `chmod`?

```



14. Inspect the code block below and interprete what you'd expect the output to be. Give a brief description of what each line of code executes while taking note of the syntax.

```

```
We have a file, we want to check that it exists, is readable and that it isn’t empty. If our file meets these criteria, we want to print “File is good” and if not, print “File is bad”.


15. Type the command `man cat` and press `Enter`. Inspect the output and list and briefly describe the sections of the output.



16. Programmers often meet errors. Some errors are easy to spot and fix while some are more coomplicated than that. Luckily, online programming communities exist to help us overcome these errors or at least point us in the right direction. Execute `copy file1.txt file1_copy.txt` on the commandline. Write down the error obtained. Make use of a search engine and one online programming community to get an interpretation of the eroor obtained.

E

17. Write a loop in Bash that counts from 1 to 30 while printing each number on one line
    ```
    
18. Given the file `nrf1_seq.fa`, copy and paste the commands below, execute and interprete the output.

```
1. grep --color -o 'ACATTT*GA' nrf1_seq.fa
    

2. grep -i '[[:lower:]]' nrf1_seq.fa 
    


       
4. grep -E --color -o 'T{5,8}' nrf1_seq.fa
    
color patterns only matching starting with a T with in 5 to 8 counts.
    
5. grep --color -o 'T\{5,8\}' nrf1_seq.fa 
    
color matching regions starting with a T with in 5 to 8 counts.
    
6. grep --o 'T\{15,18\}\|GGGG' nrf1_sT with in 15 to 18 counts and ending with GGGG 
    

7. sed -n '5000s/CACCC/XXXXX/' nrf1_seq.fa

8. sed -n '/^>[[:upper:]]+[[:digit:]]+\.
[[:digit:]]+/p' nrf1_seq.fa 


    
9. sed -n '5000p' nrf1_seq.fa no output


10.grep -o -E --color '^>[[:upper:]]+[[:digit:]]{5}\.[[:digit:]]+' nrf1_seq.fa | tr -d '>'
    

    


```
                                                                  



