Introduction to Unix/Linux

From WLCS

Introduction

Before we get into programming, we need a few fundamental "survival skills" which we will use to control our environment. You will need to be able find your way around the Unix/Linux operating system.

Now let's begin!

Objectives

  • You will be able to:
    • open a command-line terminal
    • draw an example file tree structure
    • list the files and directories (folders) using the ls command
    • navigate through the file system using the cd command
    • create a directory / folder using the mkdir command
    • remove / delete a directory using the rmdir command
    • create a text file using the nano program
    • copy a file using the cp command
    • move a file or directory using the mv command
    • remove / delete a file using the rm command
    • display the contents of a file using the cat command

Resources

Procedures

  • As a class, we will perform the following procedures
  1. Open a command-line terminal: Applications -> Utilities -> Terminal
  2. List the files and directories in your current location: ls
  3. Create a directory named programs: mkdir programs
  4. Change directory and go into the programs directory: cd programs
  5. Create directories named gvr, python, deleteMeLater
    1. mkdir gvr
    2. mkdir python
    3. mkdir deleteMeLater
  6. List the files and directories: ls
  7. Travel back UP the directory tree (go back up): cd ..
  8. List the files and directories: ls
  9. Create a text file named test.txt: nano test.txt
    1. Add some text to the file: blah blah blah
    2. Save the file before you leave nano: Ctrl-O
    3. Exit nano: Ctrl-X
  10. Display the contents of the test.txt file: cat test.txt
  11. Copy the test.txt file to a new filed named testCopy.txt: cp test.txt testCopy.txt
  12. List the files to see if copying worked: ls
  13. Remove the test.txt file: rm test.txt
  14. Go into the programs directory: cd programs
  15. Remove / delete the deleteMeLater directory: rmdir deleteMeLater
  16. Go back up in the directory tree
  17. If you list the files, what are you going to see?
  18. Go back up in the directory tree
  19. If you list the files, what are you going to see?
  20. Move the testCopy.txt file into the programs directory: mv testCopy.txt programs/
  21. Display the contents of the testCopy.txt file: cat programs/testCopy.txt
  • Tab completion
    • Type the first several letters of a file or directory and then press tab
    • Example: cd pro<TAB>
  • Now that we have gone through several commands, you should create a cheatsheet for them.
    1. Open a new text document
    2. For each of the commands below:
      • Describe the command and what it does (mv - moves a files or directory )
      • Give an example of using each (mv test.txt programs/)
        • ls
        • cd
        • cd ..
        • mkdir
        • rmdir
        • cp
        • mv
        • rm
        • cat

Evaluation (10 pts)

  • The evaluation for this lesson will consist of a performance exercise:
  1. Create a directory named sports in your home directory.
  2. Create subdirectories in the sports directory named baseball, football, basketball, and soccer.
  3. Create a file named stars.txt in the baseball directory. Add the names of three baseball stars, one per line, to this file. If you don't know the names of any baseball stars, just make up three names.
  4. Repeat the previous step in each of the other subdirectories of the sports directory.
  • Demo to Mr. Bui your new files and directories (5 pts)
  • Show Mr. Bui your cheat sheet (5 pts)

Challenge