Lab 1 - Linux Commands I

Updated 4 Oct 2026

****## Instructions

  • Attendance will be checked at the beginning of the Lab class
  • Login credentials:
    • Username: student
    • Password: Siit@1992
  • The ✔ sign identifies exercises
    • Some exercises require a TA's signature to check your result
  • After finishing all exercises, show this Lab Sheet to a TA to get the full score
  • You will have a 10-minute quiz towards the end of the Lab class (or when appropriate)

Exercise 1: Using Shell via Terminal Emulator

1.1 Shell and Terminal Emulator

  • Shell: A program that takes keyboard commands and passes them to the operating system to carry out
  • When using a graphical user interface, we need a terminal emulator to interact with the shell
  • To open a terminal: Search for it on the Ubuntu desktop and double click on Terminal

1.2 Understanding the Shell Prompt

When you see: seksan@ubuntu:~$

  • seksan identifies the log-in user name
  • $ is called a shell prompt
    • The $ sign denotes a user-level account
    • If a root or super-user is logging in, the shell prompt will be represented by the # sign
  • The directory where we currently are is shown in front of the $ sign
    • The ~ sign means our default directory, which is /home/UserName
    • We can check where we are by typing pwd

1.3 Exiting Terminal

  • To exit from Terminal, type exit and press Enter

Exercise 2: Navigating in the Linux System

2.1 Filesystem Tree

  • Like Windows, Linux organizes files in a hierarchical directory structure
  • Files are organized in a tree-like pattern of directories (folders)
  • The first directory in the filesystem is called the root directory (/)
  • The root directory contains files and subdirectories, which contain more files and subdirectories, and so on

Filesystem structure:

/
├── bin/
├── dev/
├── etc/
├── usr/
│   ├── bin/
│   ├── man/
│   ├── lib/
│   ├── local/
│   ├── sbin/
│   └── share/
├── home/
├── lib/
├── sbin/
├── tmp/
└── var/
    ├── log/
    └── tmp/

2.2 Current Working Directory

  • To display the current working directory, use: pwd (print working directory)

2.3 Listing Directory Contents

  • To list files and directories in the current working directory: ls

✔ Exercise:

$ pwd
# Record what you see
 
$ ls
# Record what you see

2.4 Changing the Current Directory

  • To change working directory: cd followed by the pathname
  • Pathname: The route we take along the branches of the tree to get to the directory we want
  • Pathnames can be specified in two ways:

Absolute Pathnames

  • An absolute pathname begins with the root directory (/)
  • Follows the tree branch by branch until the path is completed

✔ Exercise:

$ cd /usr/games
$ pwd
# Record what you see
 
$ ls
# Record what you see

Analogy: Absolute paths are like giving someone your complete address starting from the country: "Thailand, Bangkok, SIIT Campus, Building 2, Room 101". No matter where you are, this address always works.

Relative Pathnames

  • A relative pathname starts from the current working directory
  • Uses special symbols:
    • . (dot) = current directory
    • .. (dot dot) = parent directory

Examples:

  • cd .. - Go to the parent directory

    • Note: There is a space between cd and ..
    • Example: If you're in /usr/games, typing cd .. takes you to /usr
  • cd ./ChildDirectory - Go to a child directory

    • Example: If you're in /usr, typing cd ./games takes you to /usr/games

Exercise 3: Exploring the Commands

3.1 Showing Command History

  • To see commands used in the past: history

3.2 Recall Previous Typing

  • Press the UP arrow key to recall what you have typed previously

3.3 Commands' Options and Arguments

  • Commands are often followed by one or more options (modify behavior) and arguments (items upon which the command acts)
  • Most commands look like this:
    command -options arguments\boxed{\text{command -options arguments}}

Analogy: Think of a command like ordering food: "coffee" is the command, "-large" is the option (size), and "with milk" is the argument (what to add).

3.4 Getting a Command's Documentation

  • Use either help or man to know how to use a command
  • Note: Many commands support only help or man but not both

The help command:

  • Example: To know how to use the cd command
$ help cd

The man command:

  • Example: To know how to use the ls command
$ man ls

Analogy: help and man are like instruction manuals. help gives you a quick guide, while man (manual) gives you the full detailed documentation.


Exercise 4: More with the Command ls

4.1 Displaying Contents of a Specific Directory

  • Type the command: ls /PathNames

✔ Exercise:

$ ls /usr/games
# Record the result

4.2 Displaying Contents in Long Format

  • Type the command: ls -l

Understanding the output:

For example, consider the line:

-rwxr-xr-x 1 root root 1563 May 6 2015 espdiff
  • 1st field (-rwxr-xr-x) - Access permissions of this file/directory (explained in Exercise 7)
  • 2nd field (1) - Number of links of this file/directory to others
  • 3rd field (root) - File/directory owner's name
  • 4th field (root) - Group name that owns this file/directory
  • 5th field (1563) - Size in bytes
  • 6th - 8th fields (May 6 2015) - Month, date, year that this file/directory was modified
  • 9th field (espdiff) - Name of this file/directory

4.3 More ls Options

OptionLong OptionDescription
-a--allList all files, even those with names that begin with a period, which are normally not listed (i.e., hidden)
-d--directoryOrdinarily, if a directory is specified, ls will list the contents of the directory, not the directory itself. Use this option in conjunction with the -l option to see details about the directory rather than its contents
-F--classifyThis option will append an indicator character to the end of each listed name (for example, a forward slash if the name is a directory)
-h--human-readableIn long format listings, display file sizes in human-readable format rather than in bytes
-lDisplay results in long format
-r--reverseDisplay the results in reverse order. Normally, ls displays its results in ascending alphabetical order
-SSort results by file size
-tSort by modification time

Exercise 5: Manipulating Files and Directory

Important: Assume that now you are at your home directory /home/student

  • Note: You will see ~ in front of your shell prompt $ when you are at your home directory

5.1 Creating Directories

The command mkdir is used to create directories:

  • Creating a directory: mkdir DirName
  • Creating multiple directories: mkdir DirName1 DirName2

✔ Exercise:

# Create the directories L, NewDir2, and NewDir3 in your home directory
# Show the result to a TA and get the signature
 
TA's Signature: ________________________

Analogy: mkdir is like creating new folders on your desktop. You can create one folder or multiple folders at once by listing their names.

5.2 Copying Files and Directories

The command cp is used to copy files or directories:

Copying a file to the current working directory:

$ cp /PathName/file .

(Note: there is a dot at the end representing the current directory)

Copying a file in the same directory:

$ cp file1 file2

Copying a file from the current directory to another directory:

$ cp file /Pathname/filename

✔ Exercise:

# Copy the file dmesg to the directory NewDir1 as a name dmesg_copy
# Show that there is a file name dmesg_copy in the directory NewDir1 to a TA
 
TA's Signature: ________________________

Analogy: cp is like using Ctrl+C and Ctrl+V. You copy a file from one location and paste it to another location, optionally giving it a new name.

  • Note: There are more options and ways to copy files and directories, which are not shown here

5.3 Moving Files

The command mv is used to move files within a directory or to another directory:

$ mv file /PathName/DirName

✔ Exercise:

# Move the files dmesg and dmesg_copy from the home directory to the directory NewDir2
# Show that there are the files dmesg and dmesg_copy in the directory NewDir2 to a TA
 
TA's Signature: ________________________

Analogy: mv is like cutting and pasting (Ctrl+X, Ctrl+V). The file is removed from its original location and placed in the new location.

  • Note: There are more options and ways to move files and directories, which are not shown here

5.4 Removing Files and Directories

The command rm is used to remove/delete files and directories:

Removing files:

$ rm /PathName/FileName

Removing directories:

$ rm -r /PathName/DirName

✔ Exercise:

# Remove the files (passwd and passwd_copy) and the directories (NewDir1, NewDir2, NewDir3) from your home directory
# Show that there are no more such files and directories to a TA
 
TA's Signature: ________________________

Analogy: rm is like dragging files to the trash/recycle bin and emptying it permanently. Be careful - unlike Windows, there's no recycle bin to recover from!

  • Note: There are more options and ways to remove files and directories, which are not shown here

Exercise 6: Other Important Commands

6.1 Viewing File Contents

  • The command less is used to view text files
  • In a Linux system, there are many files that contain human-readable text
  • The command less provides a convenient way to examine them

Syntax:

$ less FileName
  • Note: Press q to quit the less program

Analogy: less is like opening a text file in read-only mode. You can scroll through and read it, but you can't edit it. Press 'q' to close the viewer.

6.2 Display Texts on the Terminal

The command echo is used to print texts on the terminal:

To print texts without quotes:

$ echo YourSentence

To print texts with double quotes:

$ echo "Your Sentence"

Analogy: echo is like a parrot - it repeats exactly what you tell it to say. Useful for displaying messages or checking variable values.


Exercise 7: File Permissions

7.1 Reading, Writing, and Executing

  • Access rights to files and directories are defined in terms of:
    • Read access
    • Write access
    • Execution access

To see your files and directories:

$ ls -l

Understanding File Attributes:

The first 10 characters of the listing are the file attributes:

-rwxr-xr-x
  • First character: File type
  • Remaining nine characters: File mode (read, write, execute permissions)
    • Permissions for: file's owner, file's group owner, and everybody else

File Types

AttributeFile Type
-A regular file
dA directory

Permission Attributes

AttributeFilesDirectories
rAllows a file to be opened and readAllows a directory's contents to be listed if the execute attribute is also set
wAllows a file to be written to or truncated; however, this attribute does not allow files to be renamed or deleted. The ability to delete or rename files is determined by directory attributesAllows files within a directory to be created, deleted, and renamed if the execute attribute is also set
xAllows a file to be treated as a program and executed. Program files written in scripting languages must also be set as readable to be executedAllows a directory to be entered; e.g., cd directory

Permission Attribute Examples

File AttributesMeaning
-rwx------A regular file that is readable, writable, and executable by the file's owner. No one else has any access
-rw-------A regular file that is readable and writable by the file's owner. No one else has any access
-rw-r--r--A regular file that is readable and writable by the file's owner. Members of the file's owner group may read the file. The file is world readable

Analogy: File permissions are like locks on doors. 'r' means you can look through the door, 'w' means you can change what's inside, and 'x' means you can enter (for directories) or run (for programs). The three groups (owner, group, others) are like having different keys for the homeowner, family members, and guests.

7.2 Change File Mode

  • To change the mode (permissions) of a file or directory: chmod
  • We use octal numbers to set the pattern of desired permissions

Octal to Permission Mapping:

OctalBinaryFile Mode
0000---
1001--x
2010-w-
3011-wx
4100r--
5101r-x
6110rw-
7111rwx

✔ Exercise:

# Follow the example below:
# Copy a file "/var/log/dmesg" and change its permissions so that only the owner can read and write
 
$ cp /var/log/dmesg .
$ ls -l
$ chmod 600 dmesg
$ ls -l
 
# Show that you have changed the permissions of the file dmesg to a TA
TA's Signature: ________________________

Understanding the chmod example:

  • chmod 600 dmesg means:
    • Owner: 6 = 110 = rw- (read + write)
    • Group: 0 = 000 = --- (no permissions)
    • Others: 0 = 000 = --- (no permissions)

Analogy: Think of chmod like setting a combination lock. Each number (0-7) represents a different level of access. 6 (rw-) is like having both a key and ability to change the lock, 4 (r--) is just looking through a window, and 0 is being completely locked out.


Exercise 8: IMUNES Tutorial

8.1 Understanding User Interface Layout of IMUNES

To start IMUNES:

$ sudo imunes

(If it fails, you may need to start docker first using sudo service docker start)

IMUNES GUI components:

  • Canvas: Workspace in the middle
  • Menubar: On the top
  • Toolbox: On the left side
  • Statusbar: At the bottom

Working modes:

  • Edit mode (default): Build and configure network topologies
  • Execute mode: Network simulation

The toolbox contains tools for building network topologies and adding annotations:

  • Available in edit mode
  • In execute mode, tools (except Select tool) are shaded and cannot be used

Building the Network Topology

Link:

  • A tool used to create network links between nodes

L2 - Link layer nodes:

  • LAN switch: A link layer element that forwards incoming packets to connected nodes using the table of destination addresses and its ports
  • External interface: Provides the possibility to connect a virtual node with the physical interface (e.g., to give the node access to the Internet)

L3 - Network layer nodes:

  • External connection: Provides the possibility to connect your host PC with a virtual node by creating an interface on your computer
  • Router: A network layer element capable of packet forwarding using routes obtained by dynamic routing protocols (available through quagga or xorp by default installation or any other standard FreeBSD routing daemon)
  • Host: A network layer element that does not forward packets and has static routes. It starts standard network services via portmap and inetd
  • PC: A network layer element that does not forward packets and has static routes. Unlike host, it does not start any network services
  • NAT64: A router node capable of enabling translation between IPv4 and IPv6 protocols using a form of network address translation (NAT)

The View Menu

Contains options for showing/hiding links and nodes parameters on the canvas:

  • Icon size: Change the size (normal or small) of all network elements
  • Show [network element parameter]: Show or hide information such as interface names, IPv4/IPv6 addresses, etc.
  • Show Topology Tree: Show or hide the tree with a list of all network topology elements
  • Show Background Image: Show or hide background image
  • Show Annotations: Show or hide annotations (text, oval, rectangle)
  • Show Grid: Show or hide grid
  • Zoom In, Zoom Out: Magnify or reduce the size of the display
  • Themes: Choose one of the themes from the submenu

The Experiment Menu

Used to start and terminate an experiment. Also enables attaching to a running experiment:

  • Execute: Start an experiment and switch to execute mode. IMUNES creates and configures the virtual network. All events during that process will be shown in the statusbar
  • Terminate: Terminate an experiment and switch to edit mode. IMUNES will shut down all network elements and terminate active services on each node. Termination is finished when the message about successful cleanup shows up in the statusbar
  • Restart: Terminate and restart the running experiment
  • Attach to experiment: Opens a window with the list of running experiments on the current computer. Allows resuming running experiments

8.2 How to Build, Configure and Simulate Simple Network Topology

Scenario:

  • Personal computers (office-pc1 and office-pc2) from network 192.168.1.0/24 are connected to LAN switch (office-switch)
  • LAN switch is connected to router (office-router)
  • Server (office-host) from network 192.168.2.0/24 is directly connected to the router
  • Personal computers from the first network have route only to network 192.168.2.0/24
  • Server from the second network has the default route
  • RIP routing is enabled on the router to serve and receive dynamic route updates

8.2.1 Adding and Deleting Network Elements

To draw a node:

  1. Click on the corresponding node tool
  2. Click on the workspace to place it

To connect nodes:

  1. Click on the Link tool
  2. Click and hold on the source node
  3. Go to the destination node

Exercise:

  • Draw a router, a host, a LAN switch, and two PCs
  • Using the Link tool:
    • Connect the LAN switch to the router
    • Connect each PC to the LAN switch
    • Connect the host directly to the router

8.2.2 Configuring a Simple Network

Although preconfigured parameters are usually sufficient, we will set up our own parameters:

To open the network element configuration window:

  • Right-click on the network element
  • Select the "Configure" label from the menu

Configuration steps:

Switch:

  • Change node name to office-switch

PC/HOST:

  • Change host node name to office-host
  • Change PC node names to office-pc1 and office-pc2
  • To change IPv4 address:
    1. Left-click on the "Interfaces" tab
    2. Select interface eth0 from the list of interfaces
    3. Change the IPv4 address field
    4. Click "Apply"
  • Set host IPv4 address to 192.168.2.5/24
  • Set PC IPv4 addresses to 192.168.1.5/24 and 192.168.1.7/24
  • IP address fields require CIDR notation (IPv4 address followed by / and network length)

Static routes:

  • PCs and Hosts use static routing
  • Preconfigured routing table contains only the default route
  • Every static route consists of:
    1. Destination network: IP address followed by / and network prefix
    2. Next hop network interface IP address: IP address without / and without network prefix

Static route configuration:

  • Add static route on office-pc1 and office-pc2:
    • For network 192.168.2.0/24
    • Through gateway 192.168.1.1
  • On office-host:
    • Change default gateway address to 192.168.2.1

Router:

  • Change node name to office-router
  • Set IPv4 addresses on network interfaces:
    • 192.168.1.1/24 on interface eth0
    • 192.168.2.1/24 on interface eth1

8.2.3 Start the Experiment

After the network topology is completely built and properly configured:

  1. Start experiment with: Experiment > Execute from menubar
  2. IMUNES will switch from edit mode to execute mode
  3. IMUNES creates and configures the virtual network (takes a few seconds)
  4. All events during the process will be shown in the statusbar
  5. If successful, status bar shows "exec mode" with experiment ID

8.2.4 Test Network Connectivity

After starting the experiment, test the connection:

Select node and open shell to execute commands:

Check interface information:

$ ifconfig

Test connection from office-pc1 to office-host:

$ ping 192.168.2.5
  • If no problem, you should see reply from office-host

Test connection from office-host to office-pc2:

$ ping 192.168.1.7
  • If no problem, you should see reply from office-pc2

✔ Exercise:

# Show that you have completed all tasks to a TA
 
TA's Signature: ________________________

After finishing:

  • Terminate the experiment: Experiment > Terminate
  • You can save the topology with all configuration: File > Save

Bash Commands Summary

  • pwd - Print working directory (show current location)
  • ls - List directory contents
  • ls -l - List in long format (detailed view)
  • ls -a - List all files (including hidden)
  • cd <directory> - Change directory
  • cd .. - Go to parent directory
  • cd ~ - Go to home directory

File/Directory Manipulation

  • mkdir <dirname> - Create directory
  • cp <source> <destination> - Copy files/directories
  • mv <source> <destination> - Move or rename files/directories
  • rm <filename> - Remove file
  • rm -r <dirname> - Remove directory recursively

File Viewing

  • less <filename> - View file contents (press q to quit)
  • echo <text> - Display text on terminal

Information Commands

  • history - Show command history
  • help <command> - Get help for a command
  • man <command> - Get manual page for a command

Permissions

  • chmod <mode> <file> - Change file permissions
    • Example: chmod 600 file (owner: rw-, group: ---, others: ---)

System Commands

  • exit - Exit terminal
  • ifconfig - Show network interface configuration
  • ping <address> - Test network connectivity

Difference Between cd ./home, cd /home, and cd home

1. cd /home - Absolute Path

  • Starts with / (root directory)
  • Goes to /home directory from the root
  • Works regardless of your current location
  • Like giving a complete address: "Start from the country level, go to the home folder"

Example:

# No matter where you are:
$ pwd
/usr/local/bin
 
$ cd /home
$ pwd
/home

Analogy: It's like typing a complete GPS coordinate or full address. No matter where you currently are in the world, this address will take you to the exact same location.

2. cd ./home - Relative Path with Explicit Current Directory

  • ./ means "current directory"
  • Goes to home folder inside your current directory
  • Only works if home folder exists in your current location
  • Like saying: "From where I am right now, go to the home folder"

Example:

$ pwd
/usr
 
$ cd ./home      # Looks for /usr/home
# If it exists, you go to /usr/home
# If it doesn't exist, you get an error
 
$ pwd
/usr/home

Analogy: It's like saying "Go to the coffee shop in THIS building." It only works if there's a coffee shop in your current building.

3. cd home - Relative Path (Shorthand)

  • Same as cd ./home but without the ./
  • Goes to home folder inside your current directory
  • The ./ is implied/assumed
  • Most commonly used form for relative paths

Example:

$ pwd
/usr
 
$ cd home        # Same as cd ./home
$ pwd
/usr/home

Analogy: It's like saying "Go to the coffee shop" when you're already inside a building. Everyone assumes you mean the coffee shop in the current building.


Quick Comparison Table

CommandTypeMeaningWorks From Any Location?
cd /homeAbsolute pathGo to /home from root✅ Yes
cd ./homeRelative pathGo to home in current directory❌ No (only if home exists here)
cd homeRelative pathGo to home in current directory (shorthand)❌ No (only if home exists here)

Key Symbols Summary

SymbolMeaningExample
/Root directory OR path separator/home/student
~Home directorycd ~ goes to /home/username
.Current directorycd ./folder
..Parent directorycd .. goes up one level
-Previous directorycd - goes to last location

References