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

Files and folders

You will work extensively with files and folders to organise your work, making it easy to find things and share them with others. Understanding how to work with the file system is essential and it will help you avoid many mistakes in the future. Additionally, working with files and folders using the CLI can be much faster than dragging and dropping icons on your screen.

In the last chapter (Intro to the CLI), you already learned how to interact with the file system using the CLI. In this chapter we will highlight a few important details.

<aside> 💭

Folder and directory mean the same thing. We'll use both terms interchangeably.

</aside>

Case-sensitive file systems

A case-sensitive file system treats filenames or folders with different capitalisation as distinct files or folders. For example, on a case-sensitive system, readme.txt, Readme.txt, and README.TXT are three different files. On a case-insensitive file system, the OS treats these files as the same.

Depending on your operating system, your file system may be case-sensitive or case-insensitive.

<aside> ⚠️

A common mistake is to write a program on Windows or macOS without being strict about file and folder name casing, only to find it stops working when run on a Linux server.

Always be strict with your file and folder name casing, even on a case-insensitive file system.

</aside>

Naming tips

When naming files and folders, following these tips will help you avoid common problems and make your work easier to manage:

List of navigation commands

pwd

pwd means "Print working directory". The command prints the full path of the current directory you're in. If you ever get lost, pwd is here to help.

ls

*ls* lists all files and folders in the current directory. It can be useful to use the command ls -l to see more information about the items in the folder (size, permissions). If you want to include hidden files and folders, use ls -a .

Many developers combine both -a and -l into ls -la to display a nice list of all files and folders including hidden once.

cat

Not to be confused with the cute feline animal, cat is often used to display the contents of a file directly in the terminal. It's useful for quickly peeking at short files without leaving the terminal. The command has many other interesting abilities, such as combining two files.

cd

cd stands for “Change directory”. Use this to navigate in the file system. Combined with ls and pwd , you can easily navigate your way through.

If you want to go back to the parent folder, use cd ..

touch

touch creates a new empty file.

mkdir

mkdir creates a new empty folder. It is worth mentioning mkdir -p which will create a full list of folders.

For example:

mkdir -p my-folder/one/two/three/four

The command above will create a folder named four but also all the parent folders if they do not exist.

mv

mv will move files or folders from one place to another. The first argument is the source and the second one is the destination

mv hello.txt documents/important

Using mv you can also rename a file or a folder:

mv hello.txt hello-2.txt

cp

cp will copy a file or a folder from one place to another:

rm

<aside> ❗

Be careful! rm deletes files and folders immediately without confirmation and without any way to recover them.

</aside>

Summary of the most useful commands

Command Description
pwd Print the current working directory (the folder you are in now).
ls List the files and folders in the current directory.
ls -la List files and folders in a list with detailed information including hidden files.
cat [filename] Show the contents of a file
cd [dirname] Change directory to [dirname]
touch [filename] Create a new file
mkdir [filename] Create new directory
mkdir -p [path] Create a directory and any necessary parent directories in the path. The -p flag ensures that no error occurs if the directory already exists.
mv [source] [destination] Move file or folder from [source] to [destination]. This command can be used to rename files or folder
cp [filename] [destination] Copy a file from
rm [filename] Delete a file
rmdir [dirname] Delete an empty folder
rm -rf [dirname] Delete a folder with it’s all contents

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

CC BY-NC-SA 4.0 Icons

*https://hackyourfuture.net/*