Learn

Essential commands

Terminal

ls, pwd, mkdir, rm, cp, mv, cat, echo: the everyday Swiss Army knife.

A terminal without commands is like an empty text editor. This lesson gives you the eight commands that cover 80% of what you do on a daily basis.

Know where you are and what is there

Before doing anything, two reflexes:

shell
pwd

pwd (print working directory) prints the current folder. Use it whenever you wonder "where am I right now?".

shell
ls
ls -la

ls lists the files in the current folder. With -l you get details (permissions, size, date). With -a you also see hidden files (those starting with .). Both together: -la.

Create and delete

shell
mkdir my-project
touch notes.txt

mkdir creates a folder. touch creates an empty file (or updates its timestamp if the file already exists).

shell
rm notes.txt
rm -r my-project

rm deletes a file. To delete a folder and all its contents, add -r (recursive).

Copy and move

shell
cp notes.txt notes-backup.txt
cp -r my-project my-project-backup

cp copies a file. To copy an entire folder, add -r.

shell
mv notes.txt documents/notes.txt
mv old-name.txt new-name.txt

mv moves a file from one place to another. It also serves as a rename: if the destination is in the same folder, it is a rename.

Read and display

shell
cat notes.txt

cat prints the contents of a file in the terminal. Handy for small text files.

shell
echo "hello"
echo "PORT=3000" >> .env

echo prints text. With >> it appends that text to the end of a file (you will cover redirections in detail in the next lesson).

Get help

shell
man ls
ls --help

man <command> opens the full manual. --help gives a quick summary. Quit man with the q key.

Full bash reference (ss64.com)

Check off steps to unlock what comes next

Back to course