Skip to content

Bash (Terminal) Tutorial

MorrisYLin edited this page Sep 30, 2024 · 2 revisions

This is a quick tutorial on using a command line with BASH for our projects!

Starting

Open your command-line. If on Windows, we expect you to use Git Bash since it's packaged alongside git. For mac users, use the Terminal application. This guide will use Git Bash. You will type commands directly into a console or terminal to perform tasks, rather than clicking buttons in a GUI-based application.

Since a terminal is purely text-based, assume case-sensitivity and don't put extra spaces. These can make invalid commands!

Tips

  • Use the tab key to auto-complete after typing part of a directory or file name. If it doesn't work, there's either more than one option, or you typed wrong. Double tapping tab will list out the options if you're lost!

  • Adding a --help after a command like rm --help will give you a quick manual on how to use it.

  • You can open a directory from your file explorer using the "Open GIT Bash here" option after right-clicking!

Notice that the yellow text is the directory you opened with GIT Bash

openWithGitBash

What am I seeing?

image

The green text is your device and username.

The yellow ~ is your current working directory, the "~" specifically being shorthand for the "home" directory, which will typically be the root directory (highest-level folder, usually a hard drive). This will change to a full filepath as you move around.

The $ is the line you can type a command or option on. If it isn't there, your computer is probably busy with a previous command.

Basic Commands

pwd - Print working directory

This is also visible above your active typing line in the terminal, the yellow text.

pwd

cd <path> - Change directory

Any filepath you type is relative to your current one (this applies to other commands too), unless you start the filepath with a ~ to note your root directory. cd ~/Documents/Kicad/8.0/projects will be where your project files are located.

A .. means one directory above

Double tap tab to have it list options if you're lost

cd

ls <path/dir> <-l,a> - List

Will list the subdirectories and files. Can do ls <filepath/directory> to list a different directory, or add -lor -a to make it a detailed format or show hidden files respectively.

ls

touch <file.ext> - Make a file

Make sure to also type the file extension, as you don't choose a file type. Typing out multiple names will create multiple files.

touch

mkdir <dirName> - Make a directory

Typing multiple names makes multiple directories.

mkdir

mv <source> <destination>

Moves a directory or file. Can also be used to rename a file by doing mv <old.ext> <new.ext>

mv

cp <source> <destination>

Works the same as mv, except copies the file/directory.

A . means current directory

cp

rm <fileName> Remove a file

This is a VERY dangerous command as it instantly deletes the file with no recovery. There is no recycle bin, so make sure you are deleting exactly what you want!

Delete a directory and everything in it with rm -r <path/dir>. Using rm -rf with the extra f will force remove everything.

rm