Cloud AI Campus
  • Career paths
  • Learning paths
  • Hands-on Labs
  • Plans
Log in Sign up
๐Ÿงช Hands-on lab · 45 min
← Linux Administration · Lesson 1 of 5

Command Line & Filesystem

How this workspace works
  • Terminal โ€” your live sandbox shell. Click "โ–ถ Run" on any code block to send it here.
  • Editor โ€” open, edit, and Save files in the sandbox. Use "โœจ Generate" to draft a file or command from a description, and "โœจ Review" for an AI critique before you run it.
  1. 1. System Architecture & Navigation
  2. 2. Create Directories & Files
  3. 3. Copy, Move, and Delete
  4. 4. Text Editing with Vi
  5. 5. Wildcards & I/O Redirection
  6. 6. Filters & Text Searching
  7. 7. Permissions, Links & Admin

Linux System Architecture & Navigation

Welcome to Linux Fundamentals! Linux is a powerful, open-source operating system that powers the vast majority of cloud infrastructure, containers, and web servers.


Linux System Architecture

Before running commands, it's essential to understand how the user interacts with the underlying operating system. The system is structured in layers:

        +-------------------------------------+
        |         User / Applications         |
        +-------------------------------------+
                          |
                          v
        +-------------------------------------+
        |        Shell  (bash, zsh, ksh)      |
        +-------------------------------------+
                          |
                          v
        +-------------------------------------+
        |   Kernel  (CPU, Memory, Devices)    |
        +-------------------------------------+
                          |
                          v
        +-------------------------------------+
        |   Hardware  (CPU, RAM, Disk, NIC)   |
        +-------------------------------------+
  • Hardware: The physical components (CPU, RAM, Disks).
  • Kernel: The core of the OS. It talks directly to the hardware and schedules tasks, allocates memory, and manages filesystems.
  • Shell: The command-line interpreter that reads your commands and passes them to the kernel.
  • Applications / User: The tools and programs you run.

Step 1: Print Present Working Directory

When working in a command-line interface, you are always positioned inside a directory. To check your current location, use pwd (Print Working Directory):

pwd

Your shell should return /root (the home directory of the root user).


Step 2: Listing Directory Contents

The ls command is used to list files and directories. It supports several flags to change its behavior:

  • Long list format (-l): Displays permissions, owner, size, and modification timestamp.
  • List hidden files (-a): Displays files starting with ., which are hidden by default.
  • Sort by modification time (-lt): Sorts files with the newest first.
  • Reverse sort by modification time (-ltr): Sorts with the oldest first (extremely useful in directories with many files to see what was modified last).
  • Append indicator (-F): Adds a trailing slash / after directories and a * after executables.
  • Recursive list (-lR): Lists all files and subdirectories recursively.

Let's try listing the contents of the root directory with the long-list indicator flag:

ls -lF /

You can view manual pages for any command using man. For example, man ls describes all options for ls.


Step 3: Verify Your Shell Connection

To complete this first step, create a marker file in your home directory:

touch step1_done

Click Verify step below to proceed!

Hint

Use `pwd` to print your working directory, and `ls` with flags like `-l`, `-a`, or `-F` to list files.

Create Directories & Files

In this step, you will practice creating directories and files using the command line.


Step 1: Create and Navigate into a Directory

To create a new directory, use the mkdir command:

mkdir mydirectory

Now, navigate into the newly created directory using the cd (Change Directory) command and confirm your path with pwd:

cd mydirectory
pwd

Step 2: Create Empty Files

The touch command is the easiest way to create empty (zero-byte) files. You can create multiple files at once by separating their names with spaces:

touch f1
touch f2 f3 f4 f5

Step 3: Create and Edit Files with cat

The cat (concatenate) command is typically used to display file contents. However, when combined with redirection operators, it can also create and append text:

  • cat > filename: Creates a new file (or overwrites an existing one).
  • cat >> filename: Appends content to the end of an existing file.

Let's create a file named f6 with some text. Typed interactively you would run cat > f6, enter your content, and press Ctrl+D on a new line to save. Here we use a here-document (<< EOF ... EOF) so the whole thing runs as a single command - everything between the markers becomes the file's contents:

cat > f6 << 'EOF'
First line of text.
EOF

Now, let's append another line of text to f6 (note the >> for append):

cat >> f6 << 'EOF'
Second line of text.
EOF

Verify the contents of f6 by printing it to the console:

cat f6

Step 4: Create Hidden Files & Directories

In Linux, any file or directory that starts with a dot . is considered hidden and will not be displayed by a standard ls command (you must use ls -a to see them).

Create a hidden file and a hidden directory inside mydirectory:

cat > .f4 << 'EOF'
This is a hidden file.
EOF
mkdir .d1

Confirm they exist by running ls -la.

Click Verify step below to check your work!

Hint

Create a directory `mydirectory`, navigate into it with `cd`, and use `touch` and `cat >` to create files.

Copy, Move, and Delete

In this step, you will learn how to copy, move (or rename), and delete files and directories. You will also practice using absolute and relative paths.


Key Definitions

  • Absolute Path: The path starting from the root directory / (e.g., /root/mydirectory/f1).
  • Relative Path: The path relative to your current working directory (e.g., ../d1 or ./f1).

Step 1: Navigate to Home and Copy Files

First, navigate back to your home directory /root:

cd ~
pwd

Copy the file f6 from mydirectory to a new file named f26 in your current directory:

cp mydirectory/f6 f26

Step 2: Create Subdirectory Structures

You can create a parent directory along with nested subdirectories in one command using the -p (parents) flag:

mkdir -p d10/sd10/sdd10

Confirm the structure was created recursively using the tree command or ls -R:

tree d10

Step 3: Copy Directories Recursively

To copy a directory and all of its files and subdirectories, you must use the -r (recursive) flag.

First, create two directories:

mkdir d1
mkdir d2

Now copy d1 to a new directory named d1copy:

cp -r d1 d1copy

Step 4: Move and Rename Files

The mv command is used for both moving files to another location and renaming them:

  1. Rename a file: Rename mydirectory/f1 to mydirectory/f10:

    mv mydirectory/f1 mydirectory/f10
    
  2. Move a file to a directory: Move mydirectory/f2 into the d1 directory:

    mv mydirectory/f2 d1/
    

Step 5: Delete Files and Directories

  • rm filename: Deletes a file.
  • rm -rf dirname: Recursively and forcefully deletes a directory and its contents (use with caution!).
  • rm -ri dirname: Deletes a directory interactively, prompting you for confirmation.
  • rmdir dirname: Deletes a directory only if it is empty.
  1. Delete the file f3 from mydirectory:

    rm mydirectory/f3
    
  2. Recursively delete the directory d2:

    rm -rf d2
    
  3. Delete the empty directory d1copy:

    rmdir d1copy
    

Click Verify step below to check your work!

Hint

Use `cp` to copy, `mv` to move/rename, and `rm`/`rmdir` to delete files and directories.

Text Editing with Vi

The vi editor is a powerful, visual text editor available by default on almost all Unix and Linux distributions. Understanding vi is a critical skill for managing configuration files on servers.


The Three Modes of Vi

vi operates in three main modes:

  1. Command Mode (or Normal Mode): The default mode when you open a file. Any key press is interpreted as a command (e.g., cursor movement, deleting lines, copying). You can always return to Command Mode by pressing the Esc key.
  2. Insert Mode (or Input Mode): The mode used for typing text. You enter this mode by pressing i, a, o, I, A, or O from Command Mode.
  3. Colon Mode (or Last Line Mode): Used for saving, exiting, searching, and replacing. You enter this mode by typing : from Command Mode.

Key Vi Commands in Command Mode

  • Entering Insert Mode:
    • i: Insert text before the cursor.
    • a: Append text after the cursor.
    • A: Go to the end of the line and enter insert mode.
    • o: Open a new line below the current line and enter insert mode.
    • O: Open a new line above the current line and enter insert mode.
  • Cursor Movements:
    • h: Move left (one character).
    • j: Move down (one line).
    • k: Move up (one line).
    • l: Move right (one character).
    • w: Move forward one word.
    • b: Move backward one word.
    • ^ / $: Go to the beginning / end of the current line.
    • 1G / G: Go to the beginning / end of the file.
  • Deleting & Editing:
    • x: Delete the character under the cursor.
    • dw: Delete the current word.
    • dd: Delete the entire line.
    • 5dd: Delete 5 lines starting from the cursor.
    • u: Undo the last operation.
    • yyp: Copy (yank) the current line and paste it below.
  • Colon Mode Commands:
    • :w: Save the file.
    • :q!: Quit without saving (discard changes).
    • :wq: Save and quit the file.
    • :se nu: Enable line numbers.
    • :%s/old/new/g: Replace all occurrences of "old" with "new".

Step-by-Step Exercise: Create a File with Vi

Let's put this into practice:

  1. Open a new file named vi_test.txt in vi (run this one yourself - it takes over the whole screen and stays open until you save and quit):

    vi vi_test.txt
    
  2. You are now in Command Mode. Press the letter i to enter Insert Mode. You should see -- INSERT -- at the bottom of the screen.

  3. Type the following text:

    Learning Vi Editor
    
  4. Press the Esc key to return to Command Mode.

  5. Type :wq and press Enter to save your changes and exit vi.

If you'd rather not drive the editor by hand, this here-document creates the same vi_test.txt non-interactively:

cat > vi_test.txt << 'EOF'
Learning Vi Editor
EOF

Verify that the file was created and contains the correct text:

cat vi_test.txt

Click Verify step below to check your work!

Hint

Run `vi vi_test.txt`, press `i` to enter Insert Mode, type your content, press `Esc` then type `:wq` to save and exit.

Wildcards & I/O Redirection

In this step, you will master wildcard matching characters and learn how to redirect standard input, output, and error streams.


Part 1: Wildcard Characters

Wildcards are special characters used to perform pattern matching on files and directories:

  • ?: Matches exactly one single character.
  • *: Matches zero or more characters.
  • [ ]: Matches a range of characters (e.g. [a-z] or [1-9]).

Let's practice creating and filtering files using wildcards:

  1. Create 5 test files:

    touch wc1 wc22 wc333 wc4444 wc55555
    
  2. List files with exactly one character after wc:

    ls wc?
    
  3. List files with exactly two characters after wc:

    ls wc??
    
  4. Clean up wc1, wc22, and wc333 using wildcards:

    rm wc?
    rm wc??
    rm wc???
    

Run ls w* to verify that only wc4444 and wc55555 remain.


Part 2: Standard Input, Output, and Error

Every command you run in Linux automatically opens three standard data streams:

| Stream | Name | File Descriptor | Description | | :--- | :--- | :--- | :--- | | stdin | Standard Input | 0 | Input from keyboard (Operator <) | | stdout | Standard Output | 1 | Output to terminal screen (Operator > or >>) | | stderr | Standard Error | 2 | Error messages output to screen (Operator 2> or 2>>) |


Part 3: Redirection Exercise

  1. Redirect Standard Output (stdout): Send the output of ls -l for the root directory / to a file called stdout.log (this overwrites the file if it exists):

    ls -l / > stdout.log
    
  2. Redirect Standard Error (stderr): Attempt to list a non-existent directory /non_existent_dir and redirect the error output (file descriptor 2) to a file named stderr.log:

    ls -l /non_existent_dir 2> stderr.log
    
  3. Verify the logs:

    cat stdout.log
    cat stderr.log
    

Click Verify step below to check your work!

Hint

Use wildcard characters like `*` or `?`, and redirect output using `>`, `>>`, or `2>`.

Filters & Text Searching

Filters are commands that accept data from standard input, process or transform it, and write the output to standard output.

By combining filters using the Pipe (|) operator, you can build complex text-processing pipelines. A pipe takes the standard output of the command on its left and passes it as standard input to the command on its right.


Part 1: Simple Filters

  • head: Displays the beginning of a file.
    • head filename: Displays the first 10 lines.
    • head -5 filename: Displays the first 5 lines.
  • tail: Displays the end of a file.
    • tail filename: Displays the last 10 lines.
    • tail -5 filename: Displays the last 5 lines.
  • wc (Word Count): Counts lines, words, and characters.
    • wc filename: Displays line count, word count, and byte/character count.
    • wc -l filename: Displays only the line count.
    • wc -w filename: Displays only the word count.
    • wc -c filename: Displays only the character count.

Part 2: Pipes in Action

Let's count how many files and directories are present in the root directory / by combining ls and wc:

ls -l / | wc -l

The output of ls -l / is piped directly into wc -l, which counts and outputs the number of lines.


Part 3: Text Searching with Grep

The grep utility searches one or more files for a search pattern or regular expression:

  • grep pattern filename: Searches for pattern.
  • -i: Ignore case (case-insensitive search).
  • -n: Display line numbers of matches.
  • -v: Invert search (display lines that do not match).
  • -c: Count the number of matching lines.

Step-by-Step Exercise

  1. Create a file named g containing a list of names:

    cat > g <<EOF
    Radha
    Afri
    afri
    ram
    sada
    Hari
    kumar
    Kamal
    EOF
    
  2. Run a case-sensitive invert match to exclude "afri" (notice "Afri" remains):

    grep -v afri g
    
  3. Run a case-insensitive invert match to exclude both "afri" and "Afri":

    grep -vi afri g
    
  4. Search for "afri" case-insensitively and save the output to filtered.txt:

    grep -i afri g > filtered.txt
    
  5. Print the contents of filtered.txt to verify:

    cat filtered.txt
    

Click Verify step below to check your work!

Hint

Pipe commands together with `|`, count lines with `wc -l`, and search text with `grep`.

Permissions, Links & Administration

This final step covers file permissions, ownership, linking, basic user/group administration, and scheduling tasks with cron.


Part 1: File Permissions & Umask

Every file and directory in Linux has an owner and a group, along with permissions for three categories of users: User (owner), Group, and Others.

Permissions are represented by letters or octal numbers:

  • r (Read) = 4
  • w (Write) = 2
  • x (Execute) = 1

For example, chmod 755 filename grants:

  • Owner: rwx (4+2+1 = 7)
  • Group: r-x (4+0+1 = 5)
  • Others: r-x (4+0+1 = 5)

Umask (User Mask) is a default template that subtracts permissions when files or directories are created. If umask is 022:

  • Directories (default max 777) get: 777 - 022 = 755 (rwxr-xr-x)
  • Files (default max 666) get: 666 - 022 = 644 (rw-r--r--)

Part 2: Hard Links vs. Soft Links

  • Hard Link: Creates a direct pointer to the file's data (same inode number).
    • Only works on files, not directories.
    • If you delete the source file, you can still access the data via the hard link.
    • ln source target
  • Soft Link (Symbolic Link): A shortcut that points to the source file name (different inode).
    • Works on both files and directories.
    • If you delete the source file, the soft link breaks.
    • ln -s source target

Part 3: User & Group Administration

System administrators manage access by creating users and grouping them:

  • groupadd -g GID groupname: Creates a new group.
  • useradd -u UID -g primary_group -m -s shell username: Creates a new user with a home directory (-m) and default shell (-s).
  • passwd username: Sets or changes the user's password.
  • userdel -r username: Deletes the user and their home directory.

Part 4: Task Scheduling with Crontab

cron is a daemon that runs scheduled tasks. Each user has a crontab file defined by five time/date fields followed by a command:

MIN HOUR DOM MON DOW CMD
 โ”‚   โ”‚    โ”‚   โ”‚   โ”‚   โ””โ”€ Command to execute
 โ”‚   โ”‚    โ”‚   โ”‚   โ””โ”€โ”€โ”€โ”€โ”€ Day of Week (0-6, 0=Sunday)
 โ”‚   โ”‚    โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Month (1-12)
 โ”‚   โ”‚    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Day of Month (1-31)
 โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Hour (0-23)
 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Minute (0-59)

For example, 0 2 * * * backup.sh runs a backup script every day at 2:00 AM.


Step-by-Step Exercise

  1. Create Links: Create both a hard link and a soft link pointing to your names file g:

    ln g g_hard
    ln -s g link_to_g
    

    Verify the inode numbers using ls -li g* link_to_g (you'll notice g and g_hard share the same inode, while link_to_g has a different one).

  2. Change File Permissions: Restrict g so that only the owner can read or write to it (permission level 600):

    chmod 600 g
    
  3. Group & User Creation: Create a group called students and add a new user named surya to it:

    groupadd students
    useradd -m -g students -s /bin/bash surya
    
  4. Set up a Cron Job: Add a cron job for the root user to run a hello command every minute. You can load it into crontab using a redirect:

    echo "* * * * * echo 'hello' > /tmp/cron_out" | crontab -
    

Click Verify step below to complete the Linux Fundamentals lab!

Hint

Manage permissions with `chmod`, create links with `ln -s`, add users/groups with `useradd`/`groupadd`, and edit crontabs.

Continue → Back to path

© 2026 Cloud AI Campus