Practical Commands
Write the full command required to perform the following tasks.
1. Test connectivity to [Link].
Answer: ping [Link]
2. Show the path a packet takes to reach IP [Link] (to see where a connection
breaks).
Answer: traceroute [Link]
3. Display listening ports using the replacement for netstat.
Answer: ss -tulpn
4. Check if DNS is working by resolving [Link].
Answer: nslookup [Link]
5. Edit the network configuration file using nano.
Answer: sudo nano /etc/network/interfaces
6. Run an nginx container in the background (detached mode).
Answer: docker run -d nginx
7. List all images currently downloaded to your machine.
Answer: docker images
8. Delete a container with a specific ID.
Answer: docker rm [container_id]
9. Restart the system networking service to apply changes.
Answer: sudo systemctl restart networking
10. Display the total amount of free and used memory in a "human-readable" format.
Answer: free -h
11. Create a new empty file named [Link].
Answer: touch [Link]
12. Write the "Shebang" line for a Zsh script.
Answer: #!/bin/zsh
13. Write a command to print "Success" only if the previous command failed
(Logical OR).
Answer: [ condition ] || echo "Success"
14. Write the condition to check if the variable $number is less than 10.
Answer: [ $number -lt 10 ]
15. Write a simple for loop that counts from 1 to 3 and prints the number.
Answer:
Bash:
for i in {1..3}do
echo $idone
16. How do you define a function named welcome?
Answer:
Bash:
welcome() {
# commands here
}
17. Write the command to make [Link] executable.
Answer: chmod +x [Link]
18. Write an if statement that checks if the directory /tmp/data exists.
Answer: if [[ -d /tmp/data ]]; then ...
19. How do you access the value of the first argument passed to the script inside the
script?
Answer: $1
20. Write a command to print the exit status of the very last command run.
Answer: echo $?
21. How would you create a new directory named `Homework`?
Answer: mkdir Homework
22. How would you display the entire contents of a file named `[Link]` all at once
on the screen?
Answer: cat [Link]
23. How would you delete a directory named `old_files` that is *not* empty and
contains other files?
Answer: rm -r old_files
24. How would you copy a file named `[Link]` into the `/home/user/images`
directory?
Answer: cp [Link] /home/user/images
25. What command would you use to find out your *current* location (working
directory) in the filesystem?
Answer: pwd
26. How would you add the text "New Line" to the *end* of an existing file named
`[Link]` without erasing its current contents?
Answer: echo "New Line" >> [Link]
27. What is the command to navigate directly to the root directory?
Answer: cd /
28. How would you search for the word "Warning" (case-sensitive) inside the file
`[Link]`?
Answer: grep "Warning" [Link]
29. What is the command to delete a single file named `[Link]`?
Answer: rm [Link]
30. How would you rename a directory from `Photos` to `Pictures`?
Answer: mv Photos Pictures
31. What command would you use to show the available disk space on your system
in a "human-readable" format (e.g., GB, MB)?
Answer: df -h
32. How would you display a detailed list of all running processes for all users?
Answer: ps aux
33. How would you terminate *all* running instances of the `firefox` application by
using its name?
Answer: killall firefox
34. What command would you use to list the files in your current directory, including
any hidden files?
Answer: ls -a
35. Write a single command that lists the contents of `[Link]` and then sends that
output to the `grep` command to search for the word "Error".
Answer: cat [Link] | grep "Error"
36. Download the latest list/catalog of available software from the repositories.
Command: sudo apt update
37. Install a package named gimp along with all its dependencies.
Command: sudo apt install gimp
38. Completely remove the apache2 package, including all system-wide
configuration files.
Command: sudo apt purge apache2
39. Install a local package file named [Link] using the low-level tool.
Command: sudo dpkg -i [Link]
40. Search the local package list for any software related to "python".
Command: apt search python