Skip to content

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

    Computer Basics / The Linux Command Line

    Moving Around

    The room you're in is the current working directory.

    Chapter 2 of 125 min read

    The Plain Picture#

    You're walking around inside a huge building of nested rooms. At any moment you're standing in exactly one room. You can ask "where am I?", "what's in this room?", and "take me to that room".

    The Real Names#

    • The room you're in is the current working directory.

    • pwd — print working directory: "where am I?"

    • ls — list: "what's in here?"

    • cd — change directory: "take me there."

    Paths — absolute (/var/log) and relative (../logs) — are from Operating Systems Ch 10. Shortcuts:

    SymbolMeans
    /the root of the whole file system
    ~your home directory (/Users/priya on a Mac; /home/priya on Linux)
    .the current directory
    ..the parent directory (one up)
    -(with cd) the previous directory you were in

    Under the Hood#

    Terminal
    pwd                      # /Users/priya
    cd Documents/01_STUDY    # relative path: from here, go into Documents, then 01_STUDY
    ls                       # README.md  01_Basics/01_Foundations
    ls -l                    # long format: permissions, owner, size, date
    ls -la                   # also show hidden files (names starting with a dot, like .env)
    ls -lh                   # human-readable sizes (4.2K, 18M) instead of bytes
    cd ..                    # up one level → /Users/priya/Documents
    cd ~                     # home (plain `cd` does the same)
    cd -                     # back to where you just were

    Reading ls -l (the columns are explained over the next chapters):

      -rw-r--r--  1  priya     staff  2790  23 Aug 23:11  README.md
      └────┬───┘     └───┬──┘  └─┬─┘  └┬─┘  └────┬────┘  └───┬───┘
      type+permissions  owner   group  size  modified      name
      (Ch 4)                            bytes

    The first character is the type: - a normal file, d a directory, l a symbolic link (Ch 3).

    The Linux folder layout — where things live on every server#

    FolderHoldsYou'll go there to…
    /etcsystem-wide configuration filesedit nginx config, check /etc/hosts
    /var/loglogsread why something failed
    /home/<user>users' home directoriesyour files
    /rootthe root user's home
    /usr/bin, /bininstalled programs
    /usr/local, /optsoftware you installed yourself
    /tmptemporary files, often wiped on rebootscratch space
    /var/libprograms' data (databases often store files here)find PostgreSQL's data
    /procnot real files — a live window into the kernel: one folder per processcat /proc/meminfo, /proc/<pid>/
    /devdevices as files ("everything is a file", Operating Systems Ch 10)/dev/null (Ch 5)

    (macOS uses a different layout for its own folders — /Users, /Applications, /Library — but has /etc, /tmp, /usr/bin too.)

    Gotchas

    • Spaces in names break commands: cd My Notes tries to go into My with an extra argument Notes. Use quotes (cd "My Notes") or a backslash (cd My\ Notes) — or Tab-completion, which adds them for you. Better: never put spaces in file names you'll use from the terminal.

    • Linux is case-sensitive (Operating Systems Ch 10): Readme.md and README.md are different files.

    Check yourself

    4 questions
    1

    What do ., .. and ~ mean?

    Show answer

    Current directory, parent directory, home directory.

    2

    What does ls -la show that ls doesn't?

    Show answer

    Hidden files (starting with .) and the long details: permissions, owner, size, date.

    3

    Where would you look for a server's logs? Its configuration?

    Show answer

    /var/log; /etc.

    4

    What is /proc?

    Show answer

    A virtual folder where the kernel exposes live information about processes and the system as if they were files.