Lesson 4.2: Terminal Applications

Beyond basic commands, Linux offers powerful terminal applications that can handle text editing, file management, system monitoring, and more. These tools often outperform their graphical counterparts in speed and efficiency.

Power User Advantage: Terminal applications use less system resources, work over SSH connections, and can be automated with scripts. They're essential for remote server management.

Text Editors

Text editors are the most common terminal applications. Ubuntu comes with several options:

nano - Beginner-Friendly Editor

nano is the easiest terminal text editor for beginners:

$ nano myfile.txt

nano shows keyboard shortcuts at the bottom of the screen:

Creating a file with nano

$ nano hello.txt # Type your content: Hello World! This is my first file created with nano. # Press Ctrl + O to save, then Ctrl + X to exit

vim - Powerful Editor

vim (Vi IMproved) is a powerful modal editor with a steep learning curve:

$ vim myfile.txt

vim has two main modes:

Basic vim workflow

$ vim myfile.txt # Press 'i' to enter insert mode # Type your content # Press Esc to return to normal mode # Type ':wq' to save and quit # Or ':q!' to quit without saving

emacs - Extensible Editor

emacs is another powerful editor known for its extensibility:

$ emacs myfile.txt

Basic emacs shortcuts:

Editor Recommendation: Start with nano for simple editing. As you become more comfortable, try vim for its power and efficiency. Many developers swear by vim once they master it.

File Management Tools

mc - Midnight Commander

Midnight Commander is a visual file manager that runs in the terminal:

$ sudo apt install mc # Install if not present $ mc

mc features:

tree - Directory Tree View

tree shows directory structure in a tree format:

$ tree Documents/ Documents/ ├── projects/ │ ├── website/ │ └── scripts/ └── notes/ ├── personal.txt └── work.txt 3 directories, 2 files

ncdu - Disk Usage Analyzer

ncdu (NCurses Disk Usage) helps find what's using disk space:

$ sudo apt install ncdu $ ncdu ~

System Monitoring Tools

htop - Interactive Process Viewer

htop is an improved version of the traditional top command:

$ sudo apt install htop $ htop

htop features:

iotop - I/O Monitoring

iotop shows which processes are using disk I/O:

$ sudo apt install iotop $ sudo iotop

nethogs - Network Monitoring

nethogs shows network usage by process:

$ sudo apt install nethogs $ sudo nethogs

Network Tools

ping - Network Connectivity

ping tests network connectivity to a host:

$ ping google.com PING google.com (142.250.191.14) 56(84) bytes of data. 64 bytes from lhr34s01-in-f14.1e100.net (142.250.191.14): icmp_seq=1 ttl=116 time=12.3 ms 64 bytes from lhr34s01-in-f14.1e100.net (142.250.191.14): icmp_seq=2 ttl=116 time=11.8 ms ^C --- google.com ping statistics --- 2 packets transmitted, 2 received, 0% packet loss, time 1002ms

curl - Web Content Retrieval

curl transfers data from URLs:

$ curl https://example.com Example Domain

Example Domain

This domain is for use in illustrative examples in documents.

wget - File Downloading

wget downloads files from the web:

$ wget https://example.com/file.zip --2024-12-10 15:45:32-- https://example.com/file.zip Resolving example.com... 93.184.216.34 Connecting to example.com|93.184.216.34|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 1024 [application/zip] Saving to: 'file.zip' file.zip 100%[=====================>] 1,024 --.-KB/s in 0s 2024-12-10 15:45:32 (1.23 MB/s) - 'file.zip' saved [1024/1024]

Text Processing Tools

less - File Viewer

less is a powerful file viewer with search capabilities:

$ less largefile.txt

less navigation:

grep - Text Search

grep searches for patterns in files:

$ grep "error" logfile.txt [2024-12-10 15:45:32] ERROR: Connection failed [2024-12-10 15:45:35] ERROR: Timeout occurred $ grep -r "function" /path/to/code/ # Recursive search $ grep -i "error" logfile.txt # Case insensitive $ grep -n "error" logfile.txt # Show line numbers

sed - Stream Editor

sed performs text transformations:

$ sed 's/old/new/g' file.txt # Replace all occurrences $ sed -i 's/old/new/g' file.txt # Replace in file $ sed '3d' file.txt # Delete line 3 $ sed -n '5,10p' file.txt # Show lines 5-10

awk - Text Processing

awk processes text files column by column:

$ awk '{print $1}' file.txt # Print first column $ awk -F: '{print $1}' /etc/passwd # Print usernames $ awk '{sum+=$3} END {print sum}' file.txt # Sum column 3

Archive and Compression Tools

tar - Archive Files

tar creates and extracts archive files:

$ tar -czf archive.tar.gz directory/ # Create compressed archive $ tar -xzf archive.tar.gz # Extract compressed archive $ tar -tzf archive.tar.gz # List contents

tar options:

zip/unzip - ZIP Files

$ zip -r archive.zip directory/ # Create ZIP $ unzip archive.zip # Extract ZIP $ unzip -l archive.zip # List contents

Development Tools

git - Version Control

git is essential for managing code:

$ git init # Initialize repository $ git add . # Stage all files $ git commit -m "Initial commit" # Commit changes $ git status # Show status $ git log # Show history

make - Build Automation

make automates compilation and build processes:

$ make # Build project $ make clean # Clean build files $ make install # Install project

Terminal Multiplexers

tmux - Terminal Multiplexer

tmux allows multiple terminal sessions in one window:

$ sudo apt install tmux $ tmux

tmux basics:

screen - Terminal Multiplexer

screen is another terminal multiplexer:

$ screen # Press Ctrl + A, then d to detach $ screen -r # Reattach session $ screen -ls # List sessions

Practice Exercises

Exercise 1: Text Editor Practice

  1. Use nano to create a file called "notes.txt"
  2. Add 3 lines of text about what you've learned
  3. Save and exit nano
  4. Use cat to verify the file contents
Click for solution
$ nano notes.txt # Type your content, then Ctrl + O, Ctrl + X $ cat notes.txt

Exercise 2: File Processing

  1. Create a file with multiple lines of text
  2. Use grep to find lines containing a specific word
  3. Use sed to replace a word in the file
  4. Use awk to extract a specific column
Click for solution
$ echo -e "apple red\nbanana yellow\norange orange" > fruits.txt $ grep "apple" fruits.txt $ sed 's/red/green/' fruits.txt $ awk '{print $1}' fruits.txt

Exercise 3: System Monitoring

  1. Install and run htop to see running processes
  2. Use ping to test connectivity to a website
  3. Use curl to retrieve a web page
  4. Use wget to download a small file
Click for solution
$ sudo apt install htop $ htop $ ping -c 4 google.com $ curl https://example.com $ wget https://example.com

Choosing the Right Tool

With so many terminal applications, here's when to use each:

For Text Editing:

For File Management:

For System Monitoring:

What's Next?

You now have a solid foundation in terminal applications! These tools will be invaluable as we move on to desktop environments and package management.

Continue to Module 5: Desktop Environments

Key Takeaways

  • nano is the easiest terminal editor for beginners
  • vim offers powerful editing once you learn its modes
  • htop provides better process monitoring than top
  • grep, sed, and awk are essential for text processing
  • tmux and screen enable persistent terminal sessions
  • Terminal apps work over SSH and use fewer resources