Skip to content

Enough Terminal (for now)

To get started with the terminal you will need to know how to:

  1. Open the terminal
  2. List files
  3. Move to other folders
  4. Make folders

With these tools you will have enough to get started. You can explore more by looking at the In Depth sections which will go through all the things you may want to know about the terminal. However, you can probably skip most of that for now, so you can move on to build and run your own programs. Check back here later when you have time to explore what you can do with the terminal.

Open a terminal

We have seen how to do this in the Open the Terminal page. So you can do this already!

List files

When you open the terminal, you are navigating around within the file system (i.e. within your files and folders). You can use the ls command to list the files within the current folder. Passing in the -l option will present this list with some additional details.

Terminal window
ls -l

Move to other folders

Your shell will be loaded with a default current folder, but we can move to other folders to make it easy to interact with the files there. Learn to move around within the file system will be an important starting point. The cd command is used to change the current folder. The name stands for change directory - folder are called directories within the file system.

Terminal window
# Move to the /usr/bin folder
cd /usr/bin
# At this point you will be in /usr/bin
# You can list the files and folders located here
ls -l

Try this out by finding the folder where your documents are located. We can then move into this folder, and list its contents.

Let’s now move to your Documents folder:

  • Linux and macOS: cd ~/Documents
  • Windows with MSys: cd /c/Users/username/Documents
  • Windows with WSL: cd /mnt/c/Users/username/Documents

In Linux and macOS, the ~ symbol is a shortcut to indicate your home folder.

For Windows (MSYS2), you need to put the full path as MSys has its own “home” folder. Replace username with your username, and this should work. Similarly, for Windows (WSL) the default home folder will not match your Windows’ home. In this case you have to access the Windows file system using the /mnt/c folder for the c-drive or /mnt/d for the d-drive etc.

:::tip [Give it a go]

Open your terminal. Use cd to move into your Documents folder. Then use ls -l and check that what you see matches the files you can see using the graphical environment.

:::

Make a folder

When we create programs you will want to keep the program’s files together. We can do this by creating a folder for each project. In the terminal you can use the (mkdir)[/book/part-0-getting-started/2-computer-use/2-trailside/05-manipulating-files/#making-a-directory-mkdir] command to make a new folder (make a directory in file system terminology).

Terminal window
# This will create a new folder called - MyNewFolder
mkdir MyNewFolder
# You can see the folder if you list the files
ls -l
# We can now move into this folder
cd MyNewFolder

Have a go at this yourself. Create a Code folder in our Documents folder. We can then use this for all of our code projects later on. Make sure to check that the folder exists where you expect in your File Explorer or Finder.

These are the only commands you need to master for now. I encourage you to explore the ideas in this chapter further as you have time, but for now this should be enough for us to build upon in the next chapter.