Lab 9: Linux Admin

Published

2026-08-26

Comprehension questions

What are the parts of a bash command?

A bash command has several key parts:

%%{init: {'theme': 'base', 'themeVariables': {'fontFamily': 'monospace'}}}}%%

graph TD
    A["command<br/><code>ls</code>, <code>cd</code>, <code>echo</code>"] --> B["options/flags<br/><code>-l</code>, <code>-a</code>, <code>-r</code>"]
    B --> C["arguments<br/><code>filenames</code>, <code>paths</code>"]
    C --> D["redirects<br/><code>&gt;</code>, <code>&lt;</code>, <code>|</code>"]

    style A fill:#d2562b,stroke:#fff,stroke-width:2px,color:#fff
    style B fill:#2a6f77,stroke:#fff,stroke-width:2px,color:#fff
    style C fill:#5b8c5a,stroke:#fff,stroke-width:2px,color:#fff
    style D fill:#e8a33d,stroke:#000,stroke-width:2px,color:#000

Bash Command Structure

Part Description Example
Command The program to run ls, cd, echo, grep
Options/Flags Modify behavior, prefixed with (single) or (double) - or --
Arguments What the command operates on files, paths, text
Redirects Send output elsewhere > file, < input, | pipe

Example: ls -la /home | grep .txt

Command: ls | Flags: -la | Argument: /home | Pipe: | | Chain: grep .txt

What is the difference between a relative and an absolute path?

The main difference is that absolute paths always start with / (and works from anywhere), while relative paths do not start with / and are interpreted from the current working directory (you can use .. to go up one level, . for current directory).

%%{init: {'theme': 'base', 'themeVariables': {'fontFamily': 'monospace'}}}}%%

graph LR
    Path["Filesystem<br>Paths"]

    Absolute["<strong>Absolute Path</strong><br/>Starts from root<br>directory /"]
    AbEx1["<code>/home/user/documents/file.txt</code>"]
    AbEx2["<code>/etc/passwd</code>"]
    AbDescr["Always same location<br>regardless of current<br>directory"]

    Relative["<strong>Relative Path</strong><br/>Relative to current<br>directory"]
    RelEx1["<code>documents/file.txt</code>"]
    RelEx2["<code>../parent-folder/file.txt</code>"]
    RelDescr["Changes meaning based<br>on where you are<br>in filesystem"]

    Path -->|"Full from root"| Absolute
    Absolute --> AbEx1
    Absolute --> AbEx2
    Absolute --> AbDescr

    Path -->|"From current location"| Relative
    Relative --> RelEx1
    Relative --> RelEx2
    Relative --> RelDescr

    style Path fill:#e8a33d,stroke:#000,stroke-width:2px,color:#000
    style Absolute fill:#d2562b,stroke:#fff,stroke-width:2px,color:#fff
    style Relative fill:#2a6f77,stroke:#fff,stroke-width:2px,color:#fff
    

Absolute vs Relative Paths

What are some ways to direct them to run in a particular place on the filesystem?

You can run use relative/absolute paths to:

  1. Change to a directory, then run the commands: cd /path/to/directory
  2. Run the script with the absolute path directly: /absolute/path/to/file.sh
  3. Run the script relative to current location: relative/path/file.sh
  4. Run the script in the current directory (explicit): ./file.sh

%%{init: {'theme': 'base', 'themeVariables': {'fontFamily': 'monospace'}}}}%%

graph LR
    Control["Ways to Control<br>Execution Location"]

    CD["Use <code>cd</code>to change<br>directory first"]
    ABS["Use the absolute path<br/>(specify full path)"]
    REL["Use the relative path<br/>(but specify from<br>current location)"]
    Dot["Run from current directory with <code>./file.sh</code>"]

    Control --> CD
    Control --> ABS
    Control --> REL
    Control --> Dot

    style Control fill:#d2562b,stroke:#fff,stroke-width:2px,color:#fff
    style CD fill:#2a6f77,stroke:#fff,stroke-width:1px,color:#fff
    style ABS fill:#2a6f77,stroke:#fff,stroke-width:1px,color:#fff
    style REL fill:#2a6f77,stroke:#fff,stroke-width:1px,color:#fff
    style Dot fill:#5b8c5a,stroke:#fff,stroke-width:1px,color:#fff

Ways to Control Execution Location

How can you copy, move, or delete a file? What about to or from a server?

Local operations include cp, mv and rm:

Command Description
cp /source/destination copy a file
cp -r source_dir destination_dir copy a directory recursively
mv source destination move or rename a file
rm filename delete a file (permanent, no recovery)
rm -r directory delete a directory and it’s contents

Server operations (via SSH) include scp, rsync, and sftp

Command Description
scp local_file user@server:/remote/path copy to server
scp user@server:/remote/file local_path copy from server
scp -r local_dir user@server:/remote/path copy directory to server
rsync -av local_dir user@server:/remote/path sync files (better for large operations)
sftp user@server interactive file transfer session

Key note: rm is permanent! There is no trash can in Linux. Use the -i flag to prompt before deletion: rm -i filename

Mind map of: operating system, Windows, MacOS, Unix, Linux, Distro, Ubuntu

%%{init: {'theme': 'neutral', 'themeVariables': {'fontFamily': 'monospace'}}}%%

mindmap
  root((Operating System))
    Commercial
      Windows
        GUI-focused
        Proprietary<br>kernel
      MacOS
        Unix-based
        Proprietary<br>kernel
        Desktop &<br>laptop
    Open Source<br>Unix-like
      Unix
        Original<br>design
        POSIX<br>standard
        BSD, Solaris
      Linux
        Free & open<br>source
        POSIX<br>compatible
        Kernel +<br>utilities
        Distros
          Ubuntu
            Debian-based
            User-friendly
            Server &<br>desktop
          CentOS
            RedHat-based
            Enterprise
          Fedora
            Cutting<br>edge
            RedHat-based
        Distro
          Linux kernel +<br>tools
          Different package<br>managers
          Different<br>defaults
          Community<br>focused

Operating System Family Tree

Key relationships between operating systems:

The Operating System isthesoftware that manages hardware and runs programs. Windows and MacOS are commercial proprietary operating systems, while Unix is the original open standard from 1970s (influenced modern systems).

Linux is a free, open-source Unix-like kernel created by Linus Torvalds, and the distro (Distribution) is the Linux kernel packaged with utilities, package manager, defaults. Ubuntu is a popular Linux distro based on Debian.

What are the 3x3 options for Linux file permissions? How are they indicated in ls -l?

The 3×3 permission matrix:

Owner (User) Group Other
Read (r) = 4 Read (r) = 4 Read (r) = 4
Write (w) = 2 Write (w) = 2 Write (w) = 2
Execute (x) = 1 Execute (x) = 1 Execute (x) = 1

How they appear in ls -l:

-rw-r--r-- 1 user group 1234 Jan 15 10:30 file.txt
^         ^^^^^^ ^^^^^^ ^^^^^^
|         |      |      |
|         |      |      +-- Other: read only
|         |      +--------- Group: read only
|         +-------------- User: read & write
+----------------------- File type (- = regular file, d = directory)

Breaking down permissions:

  • Position 1: File type (- file, d directory, l link)
  • Positions 2-4: Owner permissions (rwx)
  • Positions 5-7: Group permissions (rwx)
  • Positions 8-10: Other permissions (rwx)

Octal notation (chmod):

  • chmod 755 file: Owner: rwx (7), Group: rx (5), Other: rx (5)
  • chmod 644 file: Owner: rw (6), Group: r (4), Other: r (4)
  • chmod 700 file: Owner: rwx (7), Group: (0), Other: (0)
  • chmod 600 file: Owner: rw (6), Group: (0), Other: (0): typical for SSH keys