Categories: TutorialsUbuntu

Ubuntu Command-Line Mastery: The Essential Guide for Power Users

The Linux terminal is a powerful tool allowing users to control their system precisely and efficiently.

Whether you’re installing software, managing files, troubleshooting issues, or securing your system, mastering essential Ubuntu commands can significantly enhance your productivity.

This guide provides a comprehensive list of must-know commands, categorized for easy reference. From package management and file operations to networking and system monitoring, each command is explained with practical examples to help you navigate the Ubuntu command line like a pro.

If you’re new to Ubuntu or looking to refine your command-line skills, this guide will be a valuable resource. Let’s dive in and explore the commands that will streamline your workflow and improve your system management.

Sponsored
1. Package Management

APT & dpkg

  • sudo apt-get install Installs a package from Ubuntu’s repositories. Automatically resolves dependencies.
    Example: sudo apt-get install nginx
  • sudo apt-get remove Removes a package but leaves configuration files intact.
    Example: sudo apt-get remove apache2
  • sudo apt-get update
    Refreshes the list of available packages from configured repositories. Always run this before upgrading.
  • sudo apt-get upgrade
    Upgrades all installed packages to their latest versions. Does not remove obsolete packages.
  • apt-cache search
    Searches package names and descriptions for a keyword.

    Example: apt-cache search “text editor”
  • apt-cache show Displays metadata about a package (version, dependencies, description).
    Example: apt-cache show firefox
  • sudo dpkg -i
    Installs a standalone .deb package file. Does not resolve dependencies.

    Example: sudo dpkg -i /tmp/google-chrome.deb
  • dpkg -l | grep Lists installed packages and filters results.
    Example: dpkg -l | grep python

Read: How to remove broken packages in Ubuntu

2. File Operations

Navigation & Manipulation

  • cd ~/Documents
    Changes the working directory to Documents in your home folder.
    • cd .. moves up one directory.
    • cd – returns to the previous directory.
  • ls -lah
    Lists files with:
    • -l: Long format (permissions, owner, size).
    • -a: Includes hidden files (starting with .).
    • -h: Human-readable file sizes (e.g., 1K, 2M).
  • cp -r dir1 dir2
    Copies directories recursively.

    Example: cp -r ~/backup /mnt/external_drive
  • mv oldname newname
    Renames files/directories or moves them to a new location.

    Example: mv report.txt /var/www/html/
  • rm -rf
    CAUTION
    : Force-deletes a directory and its contents irreversibly.

    Example: rm -rf /tmp/junk_folder
  • tar -czvf archive.tar.gz /data
    Creates a compressed tarball:
    • -c: Create archive.
    • -z: Use gzip compression.
    • -v: Verbose output.
    • -f: Specify filename.

Read: Linux directories explained

3. Text Processing

Search & Manipulation

  • grep “error” /var/log/syslog
    Searches for the word “error” in the system log. Useful flags:
    • -i: Case-insensitive search.
    • -r: Recursive search in directories.
  • sed ‘s/old/new/g’ file.txt
    Replaces all instances of “old” with “new” in a file.

    Example: sed ‘s/cat/dog/g’ story.txt > updated_story.txt
  • awk ‘{print $1}’ data.csv
    Extracts the first column from a CSV file.

    Example: awk -F’,’ ‘{print $3}’ data.csv (uses comma as delimiter).
  • diff file1.txt file2.txt
    Highlights differences between two files. Use -y for side-by-side comparison.

4. System Monitoring

Processes & Resources

  • ps aux | grep firefox
    Lists all processes (aux) and filters for “firefox”.
    • a: Show processes for all users.
    • u: Display user/CPU/memory info.
    • x: Include non-terminal processes.
  • top
    Interactive real-time view of system resources (CPU, memory, tasks). Press q to exit.
  • kill -9
    Force-terminates a process by its Process ID (use ps aux to find the PID).
  • df -h
    Shows disk space usage for all mounted filesystems in human-readable format.
  • du -sh /var/log
    Calculates the total size of /var/log:
    • -s: Summary (total size only).
    • -h: Human-readable.

Read: Linux Ubuntu/Debian monitoring tools guide for system administrators

Sponsored

5. Networking

Configuration & Diagnostics

  • ifconfig -a
    Lists all network interfaces (deprecated; use ip addr for modern systems).
  • ping google.com
    Tests connectivity to a host. Use -c 4 to limit to 4 packets.
  • traceroute example.com
    Maps the network path to a host, showing each hop’s latency.
  • ssh user@192.168.1.100
    Connects to a remote server via SSH. Use -p 2222 for non-default ports.
  • scp file.txt user@remote:/path
    Securely copies a file to a remote server. Reverse with scp user@remote:/path/file.txt ..

6. Permissions & Ownership

Security Basics

  • chmod 755 script.sh
    Sets permissions:
    • 7 (owner): read + write + execute (rwx).
    • 5 (group/others): read + execute (r-x).
  • chown user:group file.txt
    Changes ownership of a file.

    Example: sudo chown www-data:www-data /var/www/html/*
  • sudo
    Runs a command with root privileges (e.g., sudo nano /etc/hosts).
  • su –
    Switches to the root user. Use exit to return to your regular account.

Read: How to manage permissions in Linux – Guide for beginners

7. Advanced Tools

Specialized Utilities

  • locate *.conf
    Searches for files ending in .conf using a prebuilt database (update with sudo updatedb).
  • find / -name “*.log” -mtime -7
    Searches the entire system (/) for log files modified in the last 7 days.
    • -mtime -7: Modified within 7 days.
    • -size +10M: Files larger than 10MB.
  • lspci / lsusb
    Lists PCI (e.g., graphics cards) or USB devices.
  • uname -a
    Displays kernel version and system architecture.
  • lsmod
    Lists loaded kernel modules (drivers).

Pro Tips

Combine Commands
Use pipes (|) to chain commands:

grep “error” /var/log/syslog | awk ‘{print $6}’ | sort | uniq -c

Scripting Basics
Save repetitive tasks to a script:

#!/bin/bash

tar -czvf backup_$(date +%F).tar.gz ~/Documents

  1. Avoid Catastrophes
    • Use rm -i to confirm deletions.
    • Test dd commands with status=progress to monitor disk writes.

 

The post Ubuntu Command-Line Mastery: The Essential Guide for Power Users appeared first on net2.

Ubuntu Server Admin

Recent Posts

Ubuntu Weekly Newsletter Issue 876

Welcome to the Ubuntu Weekly Newsletter, Issue 876 for the week of January 19 –…

3 days ago

How to utilize CPU offloads to increase storage efficiency

Canonical Ceph with IntelⓇ Quick Assist Technology (QAT) Photo by v2osk on Unsplash When storing…

4 days ago

Breaking the Rules: RPC Pattern with Apache Kafka and Karafka

Introduction Using Kafka for Remote Procedure Calls (RPC) might raise eyebrows among seasoned developers. At…

4 days ago

How to Install PalWorld on Ubuntu VPS (Easy 5 Minute Guide)

This article provides a guide for how to install PalWorld on Ubuntu VPS server. How…

5 days ago

How to Resolve Unmet Dependencies Error on Ubuntu

Using APT to manage software on Ubuntu (or similar Linux systems) is generally simple. It…

6 days ago

Top 7 Best Ubuntu VPS Hosting Providers for 2025

This article provides a breakdown of the top 7 best Ubuntu VPS Hosting providers for…

6 days ago