On this page

Linux Lab Practicals & Commands Manual

Fundamentals of Computer Science · Unit 1

Linux Lab Practicals & Commands Manual

Course: Fundamentals of Computer Science
Course code: 26CSE0107
Module Type: Laboratory Practical Guide & Command Reference Manual
Coverage: 5 hands-on shell lab programs with step-by-step execution, expected output, and file metadata analysis, followed by comprehensive reference lookup tables and an in-depth guide to standard and administrative Linux operating system commands.

Contents

  1. Hands-on lab programs (Programs 1 to 5)
  2. Directory and file operations commands summary
  3. Core Linux command lookup tables
  4. Basic commands of Linux Operating System: Detailed guide
  5. Unit 1 companion modules

1. Hands-on lab programs (Programs 1 to 5)

1.1 Program 1: Create a Student Directory and File

Problem Scenario:
A college teacher wants to create a directory named Student_Data. Inside this directory, the teacher wants to create a file named student.txt, store student information in it, display the file contents, and check the file details.

Linux Commands Used:

  • mkdir
  • ls
  • touch
  • cat
  • stat

Step-by-Step Lab Solution:

Step 1: Check the current directory

pwd

Purpose: Displays the current working directory.

Step 2: Create a directory

mkdir Student_Data

Purpose: Creates a new directory named Student_Data.

Step 3: Check whether the directory is created

ls

Expected Output:

Student_Data

Step 4: Move inside the directory

cd Student_Data

Step 5: Create a file

touch student.txt

Purpose: Creates an empty file named student.txt.

Step 6: Check the file

ls

Expected Output:

student.txt

Step 7: Add information to the file

echo "Name: Rahul" > student.txt
echo "Roll No: 101" >> student.txt
echo "Course: CSE" >> student.txt

Step 8: Display file contents

cat student.txt

Expected Output:

Name: Rahul
Roll No: 101
Course: CSE

Step 9: Check detailed file information

stat student.txt

Purpose: Displays detailed file information such as:

  • File size
  • File permissions
  • File owner
  • Creation time
  • Modification time

Complete Script for Program 1:

pwd
mkdir Student_Data
ls
cd Student_Data
touch student.txt
ls
echo "Name: Rahul" > student.txt
echo "Roll No: 101" >> student.txt
echo "Course: CSE" >> student.txt
cat student.txt
stat student.txt

1.2 Program 2: Create Project Directory and Project File

Problem Scenario:
A software developer wants to create a directory named Linux_Project. Inside the directory, the developer wants to create a file called project.txt, add project information, display the information, and check detailed file properties.

Perform the operations using:

  • mkdir
  • ls
  • touch
  • cat
  • stat

Step-by-Step Lab Solution:

Step 1: Create a project directory

mkdir Linux_Project

Step 2: Display all directories and files

ls

Expected Output:

Linux_Project

Step 3: Enter the project directory

cd Linux_Project

Step 4: Create a project file

touch project.txt

Step 5: Check whether the file is created

ls

Expected Output:

project.txt

Step 6: Add information to the file

echo "Project Name: Linux Commands" > project.txt
echo "Student: Amit" >> project.txt
echo "Status: Completed" >> project.txt

Step 7: Display the contents

cat project.txt

Expected Output:

Project Name: Linux Commands
Student: Amit
Status: Completed

Step 8: Display detailed information

stat project.txt

Example information shown by stat on project.txt:

File: project.txt
Size: 67
Access: (0644/-rw-r--r--)
Modify: Date and Time

Complete Script for Program 2:

mkdir Linux_Project
ls
cd Linux_Project
touch project.txt
ls
echo "Project Name: Linux Commands" > project.txt
echo "Student: Amit" >> project.txt
echo "Status: Completed" >> project.txt
cat project.txt
stat project.txt

1.3 Program 3: Teacher Creates Assignment Directory

Problem Scenario:
A teacher wants to create a directory named Assignments. Inside this directory, the teacher wants to create a file named assignment.txt, write assignment details, display the details, and check the file information.

Step-by-Step Lab Solution:

Step 1: Create directory

mkdir Assignments

Step 2: Check directory

ls

Step 3: Enter directory

cd Assignments

Step 4: Create file

touch assignment.txt

Step 5: Check file

ls

Step 6: Add assignment information

echo "Subject: Linux" > assignment.txt
echo "Assignment: Basic Commands" >> assignment.txt
echo "Submission Date: 10 September" >> assignment.txt

Step 7: Display file contents

cat assignment.txt

Step 8: Check detailed information

stat assignment.txt

Complete Script for Program 3:

mkdir Assignments
ls
cd Assignments
touch assignment.txt
ls
echo "Subject: Linux" > assignment.txt
echo "Assignment: Basic Commands" >> assignment.txt
echo "Submission Date: 10 September" >> assignment.txt
cat assignment.txt
stat assignment.txt

1.4 Program 4: Create Employee Information File

Problem Scenario:
A company wants to maintain employee information. Create a directory called Company, create an employee information file, add employee details, display the file, and check its properties.

Step-by-Step Lab Solution:

Step 1: Create directory

mkdir Company

Step 2: Display directory

ls

Step 3: Enter directory

cd Company

Step 4: Create file

touch employee.txt

Step 5: Display file list

ls

Step 6: Add employee information

echo "Employee Name: Amit" > employee.txt
echo "Employee ID: 1001" >> employee.txt
echo "Department: IT" >> employee.txt

Step 7: Display information

cat employee.txt

Step 8: Check file details

stat employee.txt

Complete Script for Program 4:

mkdir Company
ls
cd Company
touch employee.txt
ls
echo "Employee Name: Amit" > employee.txt
echo "Employee ID: 1001" >> employee.txt
echo "Department: IT" >> employee.txt
cat employee.txt
stat employee.txt

1.5 Program 5: Student Creates Notes File

Problem Scenario:
A student wants to create a directory named Notes. Inside the directory, create a file named linux_notes.txt, write three lines about Linux, display the contents, and check detailed information about the file.

Complete Lab Solution:

mkdir Notes
ls
cd Notes
touch linux_notes.txt
ls
echo "Linux is an Operating System" > linux_notes.txt
echo "Linux supports multiple users" >> linux_notes.txt
echo "Linux provides command line interface" >> linux_notes.txt
cat linux_notes.txt
stat linux_notes.txt

2. Directory and file operations commands summary

Command Purpose
mkdir Creates a new directory
ls Displays files and directories
cd Changes the current directory
touch Creates an empty file
cat Displays file contents
stat Displays detailed file information
echo Adds text to a file

3. Core Linux command lookup tables

3.1 Basic file and directory commands table

Command Purpose Example Important Options
ls List files and directories ls -l -a, -l, -h, -R, -t, -S
cd Change directory cd Documents .., ~, /
pwd Show current working directory path pwd —
cp Copy files or directories cp a.txt b.txt -r, -i, -v
mv Move or rename files/directories mv a.txt b.txt -i, -v
cat Display file contents cat file.txt -n, >, >>
less View large files with pagination less file.txt Scroll controls (↑, ↓, /word, q)
whereis Locate binary, source, and manual page whereis ls —
whatis Display one-line command description whatis ls —
mkdir Create new directory mkdir test -p, -v
rmdir Remove empty directory rmdir test —

3.2 System administration and utility commands table

Command Purpose Common Options Example
su Switch user account -, -c su -
sudo Execute command with superuser privileges -i, -u, -l sudo -i
man Display detailed manual pages -k, -f man ls
help Shell built-in command help — help cd
history Show terminal command history -c, -d, !n history
who Show currently logged-in users -a, -b who
whoami Display current logged-in username — whoami
id Show user ID (UID) and group IDs (GID) -u, -g, -G id
uname Show system and kernel information -a, -r, -s uname -a
uptime Show how long system has been running — uptime
free Display RAM memory usage -h, -m, -g free -h
tty Display terminal device name — tty
cal Display calendar -y, -m cal 2026
date Show or set system date & time +FORMAT, -s date
hostname Display or set system hostname -i, -I hostname
reboot Restart system — sudo reboot
clear Clear terminal screen — clear

4. Basic commands of Linux Operating System: Detailed guide

4.1 Navigation commands

ls — List Directory Contents

  • What it does: Displays files and directories.
  • Where it works: Any directory in the filesystem.
  • Why used: To see available files and inspect file metadata.
  • Common options:
    • ls → List names only.
    • ls -l → Long listing format showing permissions, links, owner, group, size, modification timestamp, and filename.
    • ls -a → Include hidden files (names starting with a dot .).
    • ls -lh → Human-readable sizes (auto-scaled to KB, MB, GB).
    • ls -R → Recursive listing (traverses subdirectories).

Example Output Breakdown:

ls -l

Sample Output:

total 0
drwxr-xr-x 1 kulj kulj 512 Jan 29 20:50 c_g16
  • total 0: Means no disk blocks are consumed by regular files in that directory (the directory is empty or contains only subdirectories / 0-byte files).
  • d: Represents a directory.
  • rwxr-xr-x: Permissions partitioned into Owner (rwx), Group (r-x), and Others (r-x).
  • 1: Number of hard links.
  • kulj kulj: User owner and group name.
  • 512: Size in bytes.
  • Jan 29 20:50: Last modification timestamp.
  • c_g16: Directory or file name.

cd — Change Directory

  • What it does: Moves between directories in the filesystem hierarchy.
  • Why used: Navigation.
  • Common forms:
    • cd dir → Move to named subdirectory dir.
    • cd .. → Move one level up to the parent directory.
    • cd ~ → Jump directly to the current user's home directory.
    • cd / → Jump directly to the filesystem root directory.
  • Example:
    cd /home
    

4.2 Directory-oriented commands

pwd — Print Working Directory

  • What it does: Displays the absolute path of the current working directory.
  • Why used: To identify your exact location in the filesystem.
  • Example:
    pwd
    

mkdir — Make Directory

  • What it does: Creates new directories.
  • Why used: Organizing files into structured hierarchies.
  • Common options:
    • mkdir dir → Create directory dir.
    • mkdir -p a/b/c → Create parent directories automatically if they do not exist.
  • Example:
    mkdir -p os/notes/week1
    

rmdir — Remove Empty Directory

  • What it does: Deletes empty directories only.
  • Why used: Safely cleaning up directory structures without risking accidental file deletion.
  • Example:
    rmdir temp
    
    (Note: rmdir will fail with an error if the directory contains any files or subdirectories.)

4.3 File manipulation commands

cp — Copy Files or Directories

  • What it does: Duplicates files or directories.
  • Why used: Backup, cloning, or duplicating data.
  • Common options:
    • cp file1 file2 → Copy file1 to file2.
    • cp -r dir1 dir2 → Recursive copy (copies an entire directory and all its contents).
    • cp -i → Interactive mode (prompts before overwriting).
  • Example:
    cp -r notes backup_notes
    

mv — Move / Rename Files

  • What it does: Moves files/directories or renames them if the destination is in the same directory.
  • Why used: File organization and renaming.
  • Examples:
    mv old.txt new.txt
    mv file.txt /home/user/
    

rm — Remove Files or Directories

  • What it does: Deletes files or entire directory trees permanently.
  • Warning: Extremely powerful and destructive; Linux has no default recycle bin for rm.
  • Common options:
    • rm file → Deletes specified file.
    • rm -r dir → Recursive deletion (deletes directory even if not empty).
    • rm -i → Prompts interactively before deleting each item.
    • rm -f → Force delete without prompting.
  • Example:
    rm -ri old_files
    

4.4 Viewing commands

cat — Display File Content

  • What it does: Concatenates and prints file contents directly to the terminal.
  • Why used: Viewing small files or appending simple text streams.
  • Common options & redirections:
    • cat file → View contents.
    • cat -n file → Display line numbers.
    • cat > file → Add text to file from keyboard (overwrites existing; press Ctrl+D to save).
    • cat >> file → Appends text to the end of the file.
  • Example:
    cat -n notes.txt
    

less — View Large Files

  • What it does: Interactive, scrollable terminal file viewer with pagination.
  • Why used: Safely inspect large files without flooding terminal buffer.
  • Controls inside less:
    • ↑ / ↓ or j / k → Scroll line by line.
    • Space / b → Scroll page forward / backward.
    • /word → Search forward for word.
    • n / N → Next / previous search match.
    • q → Quit viewer.
  • Example:
    less longfile.txt
    

4.5 Identification commands

which

  • What it does: Shows the full path of the shell command executable binary found in $PATH.
  • Example:
    which gcc
    

whereis

  • What it does: Finds the binary executable, source code files, and manual page files for a command.
  • Examples & Distinction:
    whereis ls
    # Returns: ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz
    
    whereis cd
    # Returns: cd:
    # Explanation: 'cd' is a shell built-in command, not an external binary executable on disk.
    

whatis

  • What it does: Displays a concise, one-line summary description of a command from its man page.
  • Example:
    whatis ls
    

4.6 Extended administration and system commands

1. su (Switch User)

  • What it does: Switch to another user account during the terminal session.
  • Syntax: su [username]
  • Common options:
    • su - → Switch to root user with root's full environment.
    • su -c "command" → Run a command as another user.
  • Example: su -

2. sudo (Superuser Do)

  • What it does: Run a command with administrative (root) security privileges.
  • Syntax: sudo command
  • Common options:
    • sudo -i → Interactive root login shell.
    • sudo -u username → Execute as a specific user.
    • sudo -l → List allowed privileges.
  • Example: sudo reboot

3. man (Manual)

  • What it does: Displays comprehensive system manual pages.
  • Syntax: man command
  • Common options:
    • -k keyword → Search manual pages by keyword.
    • -f command → Short description (equivalent to whatis).
  • Example: man ls

4. help

  • What it does: Displays help for internal shell built-in commands (such as cd, echo, history).
  • Example: help cd

5. history

  • What it does: Displays previously executed commands.
  • Common options:
    • history -c → Clears history.
    • history -d n → Deletes command entry number n.
    • !n → Re-executes command number n.
  • Example: history

6. who

  • What it does: Displays currently logged-in users.
  • Common options:
    • who -a → Show all session information.
    • who -b → Show last boot time.
  • Example: who
  • Note: If who shows no output, there are no active login sessions recorded, or the virtual environment (such as WSL) does not track sessions via the /var/run/utmp file.

7. whoami

  • What it does: Displays the username of the active user.
  • Example: whoami

8. id

  • What it does: Displays User ID (UID) and Group IDs (GID).
  • Common options:
    • id -u → Print UID only.
    • id -g → Print primary GID only.
    • id -G → Print all group IDs.
  • Example: id

9. uname

  • What it does: Displays system and kernel information.
  • Common options:
    • uname -a → All system info (kernel, hostname, release, architecture).
    • uname -r → Kernel release version.
    • uname -s → OS kernel name (returns Linux, not Ubuntu).
  • Example: uname -a

10. uptime

  • What it does: Displays system uptime, active user count, and load averages.
  • Example: uptime

11. free

  • What it does: Displays memory usage (RAM and swap).
  • Common options:
    • free -h → Human-readable output.
    • free -m → Values in megabytes.
    • free -g → Values in gigabytes.
  • Example: free -h

12. tty

  • What it does: Displays the terminal device name.
  • Example: tty

13. cal

  • What it does: Displays calendar.
  • Common options:
    • cal → Current month.
    • cal 2026 → Full year 2026.
    • cal -y → Current year.
  • Example: cal

14. date

  • What it does: Displays or sets system date and time.
  • Common options:
    • date "+%d-%m-%Y" → Custom formatted date.
    • date -s "YYYY-MM-DD HH:MM:SS" → Sets system date (requires root).
  • Example: date

15. hostname

  • What it does: Displays or sets system hostname.
  • Common options:
    • hostname -i → Local IP address.
    • hostname -I → All IP addresses.
  • Example: hostname

16. reboot

  • What it does: Restarts the operating system.
  • Example: sudo reboot

17. clear

  • What it does: Clears terminal screen.
  • Example: clear

5. Unit 1 companion modules

Saved Bookmarks

0

Request or Upload Content

Send missing topics, notes, question banks, or corrections directly to Sehjal

Click to upload or drag and drop
PDF, PNG, JPG, DOCX, ZIP (Up to 10MB)

Submitting opens FormSubmit's confirmation or error page. You can return to StudyDump with your browser Back button.