← back to home

// 01 — survival kit

NAVIGATION

Before anything else, you need to know how to move around. Linux is just folders and files — once you know how to see where you are, list what's there, and go where you want, you're already doing it.

7 commands ~15 min beginner

WHERE ARE YOU?

In Linux you're always "inside" a folder. When you open a terminal, you start in your home directory. The first thing to know is how to find out where you are right now.

pwd print working directory

Shows the full path to the folder you're currently in. Run this any time you feel lost.

example
user@machine:~$ pwd /home/user
The ~ symbol is just a shortcut for your home directory. /home/user and ~ mean the same thing.

LOOKING AROUND

Now that you know where you are, you need to see what's in the current folder.

ls list

Lists everything in the current folder. Add -la to see hidden files and details like permissions and sizes.

basic list
user@machine:~$ ls Desktop Documents Downloads notes.txt script.sh
with details and hidden files
user@machine:~$ ls -la total 48 drwxr-xr-x 8 user user 4096 Apr 20 10:00 . drwxr-xr-x 3 root root 4096 Apr 19 09:00 .. -rw-r--r-- 1 user user 220 Apr 19 09:00 .bash_logout drwxr-xr-x 2 user user 4096 Apr 20 09:45 Desktop -rw-r--r-- 1 user user 84 Apr 20 10:00 notes.txt -rwxr-xr-x 1 user user 512 Apr 20 09:55 script.sh
Files starting with a dot (like .bash_logout) are hidden. They only show up with ls -a or ls -la. Most config files are hidden this way.
Open your terminal and run ls -la right now. You'll probably see some hidden files you didn't know were there.

MOVING AROUND

cd (change directory) is the command you'll use most. You type it, a path, and you're there.

cd change directory

Moves you into a different folder. Learn the shortcuts — they save a lot of typing.

common patterns
# go into a folder user@machine:~$ cd Documents # go back one level (the parent folder) user@machine:~/Documents$ cd .. # go home from anywhere user@machine:/etc/nginx$ cd user@machine:~$ # go back to the previous folder (like browser back) user@machine:~$ cd - /etc/nginx # use an absolute path (starts with /) user@machine:~$ cd /var/log

Absolute vs Relative Paths

This trips up a lot of beginners. There are two ways to write a path:

# Absolute path — always starts with / # works from anywhere, always points to the same place cd /home/user/projects/myapp # Relative path — based on where you currently are # if you're in /home/user, these two are the same cd projects/myapp
Practice: run cd / to go to the root of the system, then run ls to see the top-level folders. Then run cd (no argument) to jump back home.

CREATING THINGS

mkdir make directory

Creates a new folder. Use -p to create nested folders in one command.

# create a single folder user@machine:~$ mkdir myproject # create nested folders all at once user@machine:~$ mkdir -p myproject/src/components
touch create empty file

Creates a new empty file. If the file already exists, it just updates its timestamp (doesn't overwrite it).

user@machine:~$ touch notes.txt user@machine:~$ touch src/index.js src/styles.css

COPY, MOVE & DELETE

cp copy

Copies a file or folder. Use -r (recursive) when copying a folder — it copies everything inside too.

# copy a file user@machine:~$ cp notes.txt notes-backup.txt # copy a file into a folder user@machine:~$ cp notes.txt Documents/ # copy an entire folder user@machine:~$ cp -r myproject myproject-backup
mv move / rename

mv does double duty: it moves files and renames them. Same command, just depends on what you pass as the destination.

# rename a file user@machine:~$ mv notes.txt journal.txt # move a file into a folder user@machine:~$ mv journal.txt Documents/ # move a folder somewhere else user@machine:~$ mv myproject /home/user/code/
rm remove

Deletes files and folders. Linux has no recycle bin — rm is permanent. Use -r to delete a folder and everything in it.

# delete a file user@machine:~$ rm notes-backup.txt # delete a folder and everything inside it user@machine:~$ rm -r myproject-backup
There is no undo. rm deletes files permanently. There's no trash. Double-check your path before you run it — especially with -r.

QUICK REFERENCE

$ pwd # where am I? $ ls # what's here? $ ls -la # what's here (with details + hidden) $ cd folder # go into folder $ cd .. # go up one level $ cd # go home $ mkdir name # create folder $ touch file.txt # create empty file $ cp file.txt copy.txt # copy file $ cp -r folder/ backup/ # copy folder $ mv old.txt new.txt # rename file $ mv file.txt folder/ # move file $ rm file.txt # delete file (permanent) $ rm -r folder/ # delete folder (permanent)
Practice run: open a terminal, create a folder with mkdir practice, go into it with cd practice, create a file with touch hello.txt, then list it with ls. You just did everything in this lesson.