Getting Familiar with the Terminal

In this activity, you’ll get more practice with terminal commands.

Terminal Commands

Directories

  • List Directory ls Displays the content of the current directory. ls -la List the detailed contents of the current directory, including hidden files.
  • Print Working Directory pwd Displays the path to the directory you’re currently in.
  • Change Directory cd / Open the / folder. This folder must be present in your current directory. cd .. Navigate to the parent directory which is indicated by ... This command essentially exits the current folder and brings you to the folder that contains it. cd ~ Navigate to the root directory.
  • Make Directory mkdir / Make a new folder with the name /
  • Remove Directory rm -r / Delete the folder / and all the files within it.
  • Copy Directory cp -r / / Copies / and its contents into /. If there is already a folder named / within /, the contents of the folder that was already present will be overwritten by the / you’re copying into the folder.
  • Move Directory mv / / Move / into /. This will not work if there is already a folder in / with the name /. mv / .. Move / into the parent directory. .. always refers to the parent directory

Files

  • Create File touch / Create a new / in the current directory. Remember to include the file extension. If there is already a file with the name /, it will just update the last modified time of the file.
  • Delete File rm / Deletes the file with the name /.
  • Copy File cp / / Copies the / into the / folder. If there is already a file named /, the file that is already present will be overwritten by the new / you’re copying in.
  • Rename File mv / / Renames a file named / into /
  • Move File mv / / Move a file named / into the / folder. If there is already a file named /, the file that is already present will be overwritten by the new / you’re moving in.

Utility

  • Clear Screen clear Clears the terminal screen so you don’t have to sift through the previous inputs.
  • Previous Command ↑ Use the up arrow to navigate to previous commands you’ve used in terminal.
  • Tab Completion [Tab ↹] Use the Tab button to autocomplete the current file or directory you’re typing in. If there’s multiple names that can be completed from what you currently have typed, it will autocomplete up to the point where the names diverge. You can use tab completion again afterwards if you’ve narrowed down which name you’re typing.
  • Closing a process PC [Ctrl] + c Mac [Control] + c This ends the current process that’s running in your terminal. This could be the manual or node or any of the many things that may take up the terminal window.

Instructions

  1. Open the terminal in this folder.
  2. Use the ls command to see the contents of this folder.
  3. Use the pwd command to find the current path you’re in.
  4. Create a new directory named Activity-1. Then list the contents of the current directory again, to make sure it worked.
  5. Navigate into the directory you just created.
  6. Create a new file named hello.md. List the contents of the current directory again.
  7. Copy the file you just made to a file named world.md.
  8. Rename the hello.md file to coding.md.
  9. Create a new directory named terminal.
  10. Move the world.md file into the terminal folder you just made.
  11. Delete the terminal folder.

Hint

Use the terminal cheat sheet to help guide you on which terminal commands should be used for each step.

Solution

To start with, let’s open up the terminal in this folder.

Let’s see what’s in the folder! Use the ls command to see the contents of this folder.

What’s the current path we’re in? Let’s find out with the pwd command. Note: Notice that the path you’re currently at is the folder where you right clicked to start git bash.

Make a new directory named Activity-1 and then list the contents of the current directory again to make sure it worked.

Navigate into the directory we just made.

Make a new file named hello.md and then list the contents of the current directory again.

Copy the file you just made to a filed named world.md.

Rename the hello.md file to coding.md.

Make a new directory named terminal.

Move the world.md file into the terminal folder we just made.

Delete the terminal folder.

We will be happy to hear your thoughts

Leave a reply