Week 1 - Setup, tools, CLI and Git

Intro to the CLI

Files and folders

Paths

Basic scripting

Node.js Setup

VSCode setup

Intro to Git

Intro to Github

Markdown

Practice

Assignment

Back to core program

Understanding paths

Working with paths is one of the most common sources of mistakes for beginners. A path tells the computer where a file or folder is located in the file system. To avoid potential future mistakes with paths, there are a few important things we must understand clearly.

Slashes: Windows vs Unix

<aside> 💡

Use the forward slash all times unless you absolutely must use the backslash for Windows support. Modern programming languages all work with forward slashes regardless the platform.

</aside>

The Root path

The root path is the top-most directory in a file system. On Unix-based systems, it's represented by /. On Windows, it's typically C:\\. All other directories and files branch out from this starting point.

cd /

Some Windows terminals (PowerShell, Git Bash) understand / and translate it as C:\\. Always use / when referring to the root folder.

For example, the path:

/users/hyf/Desktop

Can be read as: root → users → hyf → Desktop

In URLs, / also represents the root path:

<https://hackyourfuture.nl/>

Notice the similarity between the file system root and the URL root. It plays an important role when deploying a website from a file system to a URL.

Absolute and relative paths

An absolute path starts from the root and describes the full location:

/home/user/website/images/logo.png
C:\\home\\user\\website\\images\\logo.png

A relative path never starts with / . It describes a location relative to the current directory.

website/images/logo.png

In the example website/images/logo.png, this is a relative path because it doesn't start with /. It describes the location starting from your current directory: if you're in /home/user, this path would point to /home/user/website/images/logo.png.

Watch this quick explainer video to understand how a relative part works

https://youtu.be/ephId3mYu9o?si=XyjTeFZtCMqGeQdm

Key takeaways from the video

Be careful where you place the .

A common mistake is to place the . in the wrong place which will create unexpected issues. For example: ./file.txt , /.file.txt and .file.txt have three different meanings:

<aside> ⌨️

Hands on: Open the terminal, type ls -la and look at the first two items. Looks familiar?

</aside>

Examples

Study the following examples, they contain different relative paths from the following directory:

/home/users/website

Relative path Actual absolute Path
images /home/users/website/images
images/hello.png /home/users/website/images/hello.png
.. /home/users/
../project /home/users/project
../../system/logs /home/system/logs
. /home/users/website
./images /home/users/website/images
../../.. /
../project/../website/images /home/users/website/images
../../../home/users/website /home/users/website
./.. /home/users/
/.file.txt /.file.txt
.file.txt /home/users/website/.file.txt
./file.txt /home/users/website/file.txt

<aside> 💭

Understanding how to work with relative paths is key to become efficient developer

</aside>


The HackYourFuture curriculum is licensed under CC BY-NC-SA 4.0 **

CC BY-NC-SA 4.0 Icons

*https://hackyourfuture.net/*