Chapter 6: Basic Ubuntu Linux Commands π§ΒΆ
Prerequisites: Basic Operating System concepts
Mentor's Note: In Linux, the Terminal is your magic wand. While most people use a mouse to click icons (GUI), power users and developers use the Command Line (CLI) to talk directly to the computer's soul. It's faster, more powerful, and once you master it, you'll feel like a wizard! π§ββοΈ
π The Scenario: The Universal Translator π£οΈΒΆ
Imagine you are visiting a foreign country. You can point at things (GUI), but it's much more efficient if you speak the local language (CLI).
- The Shell: This is your Translator. You give it a command in English-like words, and it translates them into "0s and 1s" for the computer's CPU.
- The Terminal: This is the Microphone you use to speak to the translator.
- The Result: Total control over the computer without ever needing a mouse! β
π Main Topics CoveredΒΆ
- Starting Up the Terminal
- Shells in Linux
- Command Syntax
- General Purpose Commands
- Working with Directories
- Working with Files
- Manipulating Files and Directories
- File Permissions
- I/O Redirection and Piping
- Filters
π¨ Visual Logic: The Shell ArchitectureΒΆ
graph TD
A[User π§βπ»] -- Commands --> B[Shell π]
B -- Translation --> C[Kernel βοΈ]
C -- Control --> D[Hardware π₯οΈ]
D -- Result --> C
C -- Response --> B
B -- Output --> A
π Understanding ShellsΒΆ
A Shell is a command-line interpreter.
- Available Shells: Use cat /etc/shells to see all shells installed.
- Default Shell: Use echo $SHELL to see your default (usually /bin/bash).
- Switching Shells: Type csh to enter C Shell, exit to return.
- Internal vs External: Use type [command] to check if a command is built-in or a separate program.
π οΈ Complete Command ReferenceΒΆ
π 1. General Purpose CommandsΒΆ
| Command | Purpose | Logic/Example |
|---|---|---|
cal |
Display calendar | cal 01 2024 (Specific month) |
date |
Display system date | date +%D (Date), date +%T (Time) |
bc |
Command line calculator | Use bc -l for precision math |
echo |
Display message/variable | echo "Hello $USER" |
passwd |
Change password | passwd (Self) or passwd user |
clear |
Clear terminal screen | Wipes previous output |
π 2. Help & Help SystemsΒΆ
| Command | Purpose | Example |
|---|---|---|
--help |
Brief help flag | mv --help |
man |
Full manual pages | man ls |
whatis |
One-line description | whatis cat |
apropos |
Search by keyword | apropos copy |
π 3. Directory ManagementΒΆ
| Command | Purpose | Example |
|---|---|---|
pwd |
Print working directory | Shows absolute path π |
mkdir |
Create directory | mkdir -p a/b/c (Nested) |
cd |
Change directory | cd ~ (Home), cd - (Back) |
rmdir |
Remove empty folder | rmdir old_docs |
π 4. File OperationsΒΆ
| Command | Purpose | Details |
|---|---|---|
cat |
Create/View/Concat | cat > f (New), cat >> f (Append) |
rm |
Remove file/folder | -i (Ask), -r (Recursive), -f (Force) |
ls |
List contents | -a (Hidden), -l (Long), -t (Time) |
cp |
Copy data | cp file1 file2 |
mv |
Move or Rename | mv old.txt new.txt |
more |
Paging | View files one page at a time |
wc |
Word count | -l (Lines), -w (Words), -c (Chars) |
π 5. File Analysis & ComparisonΒΆ
| Command | Purpose | Example |
|---|---|---|
cmp |
Compare two files | Finds first byte of difference |
diff |
Show differences | Shows exactly what lines differ |
grep |
Pattern matching | grep "Surat" address.txt |
π File PermissionsΒΆ
Linux uses a 3-part system: User (u), Group (g), and Others (o).
Octal ValuesΒΆ
- 4: Read (
r) - 2: Write (
w) - 1: Execute (
x) - 0: None (
-)
Common Modes:
- 777: Everyone can do everything (Insecure! β οΈ)
- 755: Owner can write, everyone else can only read/run.
- 644: Owner can write, everyone else read only.
π Wildcard Characters (The Search Shortcuts)ΒΆ
*: Any number of characters (including none).?: Exactly one character.[abc]: Any one of a, b, or c.[!abc]: Any character except a, b, or c.[p-s]: Any character in the range p to s.
β‘ I/O Redirection & PipingΒΆ
| Symbol | Action | Analogy |
|---|---|---|
> |
Redirection (Overwrite) | Pouring water into a new bucket πͺ£ |
>> |
Redirection (Append) | Adding water to an existing bucket π° |
< |
Input Redirection | Sucking water from a bucket π₯€ |
\| |
Pipe | Connecting two pipes together π |
π§ͺ Filter Commands (The Sifters)ΒΆ
Filters take input, process it, and output the result.
- head -n: Show first n lines.
- tail -n: Show last n lines.
- cut: Vertical slicing. cut -d "," -f 1 (Get 1st field of CSV).
- paste: Join files side-by-side.
- sort: Sort lines (use -r for reverse).
- tr: Translate characters. cat f | tr 'a' 'A'.
π― Practice & ImplementationΒΆ
The best way to learn Linux is by doing. We have prepared a comprehensive 50-problem practice set for you.
Go to Chapter 6 Practice Sheet β
π‘ Interview & Board Tip πΒΆ
"Board examiners love asking about Case Sensitivity. Remember:
MyFile.txtandmyfile.txtare two different files in Linux! Also, always know the difference betweenrm(files) andrmdir(folders)."