Skip to content

Try “polymorphism”, “TCP handshake” or “git rebase”.

    Computer Basics / The Linux Command Line

    Working With Files

    Everything you'd do with paper documents: read one, flip through it, glance at the last page, make a copy, move it to

    Chapter 3 of 124 min read

    The Plain Picture#

    Everything you'd do with paper documents: read one, flip through it, glance at the last page, make a copy, move it to another folder, throw it away, leave a sticky note pointing to it.

    The Real Names and Commands#

    Reading#

    Terminal
    cat notes.txt            # print the whole file (short files only)
    less app.log             # page through a big file: space = next page, / = search, q = quit
    head -n 20 app.log       # first 20 lines
    tail -n 50 app.log       # last 50 lines
    tail -f app.log          # FOLLOW: keep printing new lines as they're written — live logs. Ctrl+C to stop
    wc -l app.log            # count lines (wc = word count; -l = lines)
    file mystery.bin         # guess what kind of file it is

    tail -f is the command you'll use most during incidents: run it, reproduce the bug, watch the error appear.

    Creating, copying, moving, deleting#

    Terminal
    touch empty.txt                  # create an empty file (or update an existing file's date)
    mkdir notes                      # make a directory
    mkdir -p notes/2026/biology      # make every missing folder along the path
    cp notes.txt backup.txt          # copy a file
    cp -r notes/ notes_backup/       # copy a directory and everything inside (-r = recursive)
    mv notes.txt archive/            # move
    mv old.txt new.txt               # rename (a move within the same folder)
    rm backup.txt                    # delete a file
    rm -r notes_backup/              # delete a directory and everything inside
    Terminal
    ln -s /opt/studybuddy/releases/v42 /opt/studybuddy/current

    A symbolic link (symlink) is a tiny file that points to another path — like a shortcut. ls -l shows it as current -> /opt/studybuddy/releases/v42. Deployment tools use this trick: to switch versions, just re-point current, which is instant, and rolling back is just as easy.

    Gotchas

    • rm has no Trash and no undo. rm -rf (recursive, force — no questions asked) on the wrong path is how people delete production. Before any rm -r, run ls on the exact same path first to see what it will delete. Never run rm -rf $SOMEVAR/ in a script without checking the variable isn't empty — an empty variable turns it into rm -rf /.

    • cp and mv silently overwrite an existing file at the destination. Add -i to be asked first.

    • cat on a huge log file floods your terminal and can hang your SSH session. Use less, head or tail.

    Check yourself

    5 questions
    1

    How do you watch a log file live as new lines are written?

    Show answer

    tail -f file.log.

    2

    How do you create a/b/c/ in one command if none of them exist?

    Show answer

    mkdir -p a/b/c.

    3

    How do you rename draft.txt to final.txt?

    Show answer

    mv draft.txt final.txt.

    4

    Why do deployment tools use a symlink called current?

    Show answer

    Switching or rolling back versions becomes an instant re-pointing of one link.

    5

    What should you always do before rm -r some/path?

    Show answer

    ls some/path to see exactly what will be deleted — rm can't be undone.