Home > Undergraduate > Open Source Tools and Scripting >    Labs

  CITS4407/CITS2003 OPEN SOURCE TOOLS AND SCRIPTING
 
 

Lab 2: Shell Basics

Solutions

  1. What does open source mean? How is that different from free-to-use?
  2. Open source: Source code is freely available (eg Firefox). Free to use: you can use it for free, but you can't have the source code (eg. google search).

  3. What are the two meanings of / in the file path /lab/week2/thing.txt?
  4. The first / means "root", the top level directory of the unix file structure. The other /s are separators which separate the directories and file in the path.

  5. What is the absolute path of the home directory of the user stud?
  6. /home/stud

  7. What is the file called .? How is this different to a file called .stuff?
  8. . is the current directory. .stuff is a hidden file.

  9. Create a directory called week2 in the mounted directory if you haven't already. Then create a file in week2 using the following command:
    /usr/games/cowsay "MOO" > lol.txt
  10. To create and move to the directory:
    cd ~/perm
    mkdir week2
    cd week2

  11. Print the first 3 lines of lol.txt using a command ("print" means "display in the terminal", not "send to a printer").
  12. head -n3 lol.txt

  13. Print the last line of lol.txt using a command
  14. tail -n1 lol.txt

  15. How many lines are in lol.txt?
  16. wc -l lol.txt

  17. What is the difference between cat lol.txt and head lol.txt? Would this change on a larger file?
  18. No difference because lol.txt is only 8 lines long and head prints 10 lines by default. If lol.txt was longer or if head -n was used with n of less than 8, the output of head would be shorter than that of cat.

  19. How many files are in /lab/week2? Don't count . or .. (why are we ignoring these?).
  20. 6 files. Don't forget to list hidden files with ls -a. We are ignoring . or .. because they are the current and parent directory, not files "in" the directory.

  21. What does the -p option mean for ls?
  22. ls -p puts a / at the end of directory names. You can find this out using man ls.

  23. List the contents of /lab/week2 in size order. Which is largest?
  24. ls -S will sort files by size. Use ls -alS to include hidden files and show the file sizes. Alice_in_Wonderland.txt is the largest.

  25. What command would you use to copy Alice_in_Wonderland.txt from /lab/week2 to your mounted directory?
  26. cp /lab/week2/Alice_in_Wonderland.txt ~/perm/week2
    or
    cp /lab/week2/Alice_in_Wonderland.txt ~/perm/week2/Alice_in_Wonderland.txt

  27. How many words are in Alice_in_Wonderland.txt?
  28. wc -w Alice_in_Wonderland.txt

  29. Open Alice_in_Wonderland.txt using the less. Using less, answer the following:
    1. What chapter begins on line 1252?
    2. Pig and Pepper
    3. What food is described as rich and green?
    4. soup
    5. How many times does the word "verdict" appear?
    6. 4
  30. You've decided you don't want to keep a whole book in your mounted directory. How can you remove Alice_in_Wonderland.txt from your mounted directory?
  31. rm Alice_in_Wonderland.txt



Department of Computer Science & Software Engineering
The University of Western Australia
Last modified: 8 February 2022
Modified By: Daniel Smith

UWA