Assignment 01: Linux Architecture and Command Line Basics
Recommended Local Environment Setup
While you will utilize the university’s lab servers for formal evaluations, establishing a local Linux environment on your personal machine is fundamentally required for this course. System-level education demands experimentation.
Local Installation Options:
- Virtual Machine (Safest Method): Install virtualization software such as Oracle VirtualBox or VMware, and set up a Linux distribution like Ubuntu or Fedora.
- Windows Subsystem for Linux (WSL): For Windows users, installing WSL provides a robust and deeply integrated Linux terminal environment.
- Bare Metal Installation: Dual-booting your machine to run Linux natively offers the most authentic performance and hardware interaction.
A Note on System Experimentation: To truly comprehend operating system architectures, you must be willing to push boundaries. Do not fear causing system errors or misconfigurations within your virtual environments; dismantling and breaking existing structures is a mandatory step in learning how to engineer new, stable systems.
Part 1: System Navigation and Directory Architecture
Tutorial:
The Linux file system is a hierarchical tree structure, beginning at the root directory (/). Understanding your current location and navigating this tree is the foundational skill of system administration.
Commands to Explore:
pwd: This command helps to display the current path.ls: This command will display all file and directory names.Use
ls -ato show all files including hidden files.An information listing of files is obtained when
lsis used with the-l(long) option.The
-doption forces the listing of a directory itself rather than its contents.mkdir: This command helps to create the directory.cd: This command helps to change directory.
Action Items:
- Open your terminal and identify your absolute path.
- Create a new directory named using your student identification number.
- Change your working directory to this newly created folder.
- Execute a long listing of all hidden files in your current directory.
Variant Task:
Consult the manual pages (using man ls) to find the flag that sorts directory contents by file size. Create three empty files, add varying amounts of text to them, and demonstrate sorting them by size using the ls command.
Part 2: File Creation, Viewing, and Moving
Tutorial: In UNIX/Linux, everything is treated as a file. The ability to quickly generate, copy, move, and review text files from the command line is essential for system configuration.
Commands to Explore:
cat: Through thecatcommand you can create, append new data, and display the contents of a file.Use
cat > filenameto create a blank file, and pressctrl+dafter ending the writing to save and exit.Use
cat >> filenameto append data into an old file.more: This works on a primary command likelsorcatso that the list will display page by page.cp: This command creates duplicate files from one location to another.mv: This command helps to rename a file or directory, or move a file from one location to another.
Action Items:
- Create a file named
sys_info.txtand write a brief sentence about your operating system. - Append your current system date to the file using the append operator.
- Create a duplicate of this file named
sys_backup.txt. - Rename
sys_backup.txttosys_archive.txtusing the move command.
Variant Task:
Create a new subdirectory named archives. Move sys_archive.txt into this new directory using a single command containing absolute paths for both the source and destination.
Part 3: Text Editing and Standard Input/Output
Tutorial:
Mastery of command-line text editors is non-negotiable for manipulating configuration files directly on a server. The vi editor is universally available on UNIX systems.
Commands to Explore:
vi: Thevieditor has three modes: Input mode, Command mode, and ex mode.Press
ito insert text to the left of the cursor.Use
ddto delete an entire line, andporPto put the copied text below or above the current line.In ex mode,
:wsaves the file,:wqsaves and exits, and:q!quits editing mode after abandoning changes.wc: Through this command you can count the word, line, and character count of a file. The-loption counts the lines of a file.echo&date: Through theechocommand you can display messages, and through thedatecommand you can display the current date.
Action Items:
- Open a new file named
student_record.datusingvi. - Enter insert mode and type three lines of mock student data using a pipe (
|) as a delimiter (e.g.,01|John Doe|CSE). - Save the file and exit the editor.
- Use the
wccommand to count the number of characters and lines instudent_record.dat.
Variant Task:
Re-open student_record.dat in vi. Yank (copy) the first line using the yy command and paste it at the bottom of the file using the p command. Exit without saving using the appropriate ex mode command.
Part 4: File Manipulation, Formatting, and Slicing
Tutorial: Often, you will deal with massive log files or data sets. Linux provides utilities to slice, filter, and format data directly from the shell without requiring complex scripts.
Commands to Explore:
head&tail: Theheadcommand displays the top of the file, while thetailcommand displays the end of the file.cut: Through this command you can slice a file vertically based on characters or fields. You can use the-doption to define a field separation delimiter.paste: Through this command you can paste more than one file vertically.pr: Through this command you can display a file with a suitable header, footer, and formatted text. The-hoption adds a heading.sort&uniq: Thesortcommand sorts entire lines according to ASCII coding, and theuniqoption eliminates duplicate records.
Action Items:
- Using
student_record.dat, extract only the student names (the second field) using thecutcommand and save the output tonames.dat. - Sort
names.datin reverse alphabetical order (consult manual for the reverse flag) and overwrite the file. - Display the final sorted list using the
prcommand, adding a formal heading titled “Sorted Student Roster”.
Variant Task:
Display student_record.dat with line numbers using the nl command. Use options -w3 to specify the width and -s" " to specify the separator.
Part 5: Advanced Pattern Matching and Pipelines
Tutorial:
The true elegance of the UNIX philosophy is that tools are designed to do one thing well and to work together seamlessly. By using standard input/output redirection and the pipe operator (|), you can chain commands to execute complex operations.
Commands to Explore:
grep: Through thegrepcommand you can match patterns from files; it acts as a global regular expression printer.The
-coption displays a count of the number of occurrences.The
-noption displays the line number along with the lines.The
-voption displays all but the lines matching the expression.tee: Theteecommand uses standard input and standard output, breaking the input into two components where one is saved in a file and the other connects to standard output.cmp: This command compares files byte by byte.
Action Items:
Run a
grepsearch onstudent_record.datto find all records associated with the “CSE” department.Execute the
whocommand to see current logged-in users.Pipe the output of
whointotee, saving the data to a file namedcurrent_users.txtwhile simultaneously viewing it on your terminal screen.
Comprehensive Culminating Task: Construct a single pipeline of commands that accomplishes the following sequentially:
- Lists all files in the
/etcdirectory using a long listing. - Filters the output to only show lines containing the word “network”.
- Counts the exact number of lines resulting from that filter.
- Echoes a final sentence stating: “There are [Number] network-related configurations.” (Hint: Use command substitution with backticks, e.g., `
command`).
Resources & Further Reading
- The Linux Command Line (by William Shotts): Read Chapter 2: Navigation and Chapter 3: Exploring the System for a deep dive into the UNIX file hierarchy.
- OverTheWire - Bandit Wargame: OverTheWire: Bandit is a brilliant, gamified platform where you must use basic Linux commands to find passwords and advance to higher levels. Highly recommended for hands-on CLI practice.
- Official Linux Manual: Get comfortable reading raw documentation. Bookmark man7.org and search for
ls,cd, andchmod.
📎 Attached Resources
- >> PB_IPC-UNIX.pdf (application)
- >> PB_OS-LAB-Assignments.pdf (application)