Terminal tutorial#
Welcome to the world of the Terminal! In this tutorial, you will learn the fundamentals of using the Terminal, a powerful tool for interacting with your computer through text commands. We will cover essential commands and tips to help you navigate and perform tasks efficiently.
You can learn more about what a Terminal is and the most useful commands here.
Opening a terminal#
Each operating system opens terminals in a different way.
Search for powershell
in the Windows taskbar search or
press Win-R buttons (simultaneously), then type
powershell
in the small run window appearing, press Enter.
This should open a Terminal looking something like this:
Search for cmd
in the Windows taskbar search
or press Win-R buttons (simultaneously), then type
cmd
in the small run window appearing, press Enter.
This should open a Terminal looking something like this:
Open the Launchpad icon in the Dock, or press Command-Space; type Terminal
and click on it.
See more detailed explanation here.
This should open a Terminal looking something like this:
Note: This depends on the distribution you are using. Nearly all Linux distributions has the Terminal icon near the Desktop.
Try one of the following options:
Press Ctrl-Alt-T simultaneously.
Press the Win key which should open up a search box, type
terminal
and press EnterOpen a file explorer and right-click a folder, there should be an option name
Open in Terminal
which will open that folder in the terminal.
This should open a Terminal looking something like this:
1. Where am I?#
To find out your current directory (location), you can use the
pwd
command on Windows.
Type and enter
pwd
in your Terminal.
This should look something like this in your Terminal:
2. What’s in here?#
To list the contents of your current directory in PowerShell, you can use the ls
cmdlet.
If you want to see only files and not directories, use ls -Force
.
1. Type and enter in your Terminal:
ls
2. Type and enter in your Terminal:
ls -Force
This should look something like this in your Terminal:
To list the contents of your current directory in Windows Command Prompt, you can use the dir
command. If you want to see hidden files and directories as well, use dir /a
.
1. Type and enter in your Terminal:
dir
2. Type and enter in your Terminal:
dir /a
This should look something like this in your Terminal:
3. Changing directories#
Warning 1:
Note that instead of MyFolder
you should use one of the folders listed in the previous exercise.
Warning 2 (for Windows):
Note when typing the directory name of subfolders, that Windows uses backslashes \
and not forward slashes /
To navigate to a different directory, you can use the cd
command followed by the path to the desired
directory, and to navigate one step backwards, you can use the cd ..
command.
Type and enter in your Terminal:
cd MyFolder
Type and enter in your Terminal:
cd ..
This should look something like this in your Terminal:
Warning 1:
Note that instead of MyFolder
you should use one of the folders listed in the previous exercise.
Warning 2 (for Windows):
Note when typing the directory name of subfolders, that windows uses backslashes \
and NOT forward slashes /
To navigate to a different directory, you can use the cd
command followed by the path to the desired
directory, and to navigate one step backwards, you can use the cd ..
command.
Type and enter in your Terminal:
cd MyFolder
Type and enter in your Terminal:
cd ..
This should look something like this in your Terminal:
Warning:
Note that instead of MyFolder
you should use one of the folders listed in the previous exercise.
To navigate to a different directory, you can use the cd
command followed by the path to the desired
directory, and to navigate one step backwards, you can use the cd ..
command.
Type and enter in your Terminal:
cd MyFolder
Type and enter in your Terminal:
cd ..
This should look something like this in your Terminal:
A good trick to use in Visual Studio Code is to open a folder in your sidebar, and copy the names of folders/directories that you would like to work in. This is done by completing the steps below:
Press the icon in the top left of the screen that looks like 2 pieces of paper on top of each other
Press “open folder”
Visual studio code will now open your files. Select the folder that you would like to work with by clicking on it
Now you should see all the files and subfolders contained in the folder taht you selected on the left side of the screen
You can now right click a folder and press “copy path”
type cd in your terminal and paste the path that you just copied
In general it is a good idea to change your directory, to the place of whatever you are working with. For example, if a large dataset is in a specific folder, you can change your directory to that folder.
4. How can I create a new folder?#
To create a new folder you can use mkdir
on your Terminal. Then, you can use ls
to see
if the folder was successfully created.
Type and enter in your Terminal:
mkdir NewPythonFolder
Type and enter in your Terminal:
ls
This should look something like this in your Terminal:
5. How can I delete a folder or a file using a Terminal?#
You can use rm
to delete a file or rm -r
to delete a folder using the Terminal.
Type and enter in your Terminal:
rm -r NewPythonFolder
Type and enter in your Terminal:
ls
This should look something like this in your Terminal:
6. Which Python version?#
To check which Python version you have you can use python --version
To enter Python in your Terminal you can use python
To exit Python in your Terminal you can use exit()
Type and enter in your Terminal:
python --version
Type and enter in your Terminal:
python
Type and enter in your Terminal:
exit()
This should look something like this in your Terminal:
To check which Python version you have you can use python --version
To enter Python in your Terminal you can use python
To exit Python in your Terminal you can use exit()
Type and enter in your Terminal:
python --version
Type and enter in your Terminal:
python
Type and enter in your Terminal:
exit()
This should look something like this in your Terminal:
To check which Python version you have you can use python3 --version
Note that this might change depending whether you have more than one Python version installed
To enter Python in your Terminal you can use python3
To exit Python in your Terminal you can use exit()
Type and enter in your Terminal:
python3 --version
Type and enter in your Terminal:
python3
Type and enter in your Terminal:
exit()
This should look something like this in your Terminal: