💻

PS 15 Linux Commands

Nov 21, 2024

Linux Command Line Basics

Introduction

  • Linux command line tools are often used in terminal programs like Xterm.
  • Commands in Linux are also applicable in Mac OS due to shared Unix heritage.
  • Ubuntu is used here as the example Linux distribution.
  • man command: Use man to access the manual page for detailed command syntax (e.g., man grep).

Basic Navigation and File Operations

  • Terminal Access: Open via Applications > Terminal.
  • List Directory Contents:
    • ls: Lists files and directories.
    • ls -l: Provides a detailed view including permissions and file sizes.
    • ls -l | more: Paginate long lists.
  • Print Working Directory:
    • pwd: Shows the current directory path.
  • Rename Files:
    • mv source destination: Renames or moves files.
    • Example: mv first.txt second.txt.
  • Copy Files:
    • cp source destination: Copies files.
    • Example: cp second.txt third.txt.
  • Remove Files:
    • rm file: Deletes files.

File Permissions

  • Understanding Permissions:
    • Permissions are denoted by a string of characters (e.g., rw-r--r--).
    • r: Read, w: Write, x: Execute.
    • Permissions are set for User, Group, and Others.
  • Change Permissions:
    • chmod: Change file permissions using numeric (e.g., 744) or symbolic notation (e.g., a-w).
  • Change Ownership:
    • chown: Change file owner, requires sudo for elevated permissions.
    • Example: sudo chown new_owner file.

Working with Processes

  • Process Management:
    • ps: View current processes.
    • ps -e | more: View all system processes with pagination.
    • Interactive Process Viewer:
      • top: Dynamic view of all processes; shows resource usage.
      • Quit with q.

Installing and Managing Software

  • Package Management:
    • apt-get install package: Installs software on Debian-based systems.
    • yum: Similar function for Red Hat-based systems.
  • Network Configuration:
    • ip address: View IP configuration.
    • Use sudo ip address add to modify IP settings.

Disk and Storage Management

  • Disk Usage:
    • df: Displays disk space usage.
    • df -h: Human-readable format (e.g., GB, MB).

Searching and Finding Files

  • Search:
    • grep pattern file: Search for text patterns.
  • Find Files:
    • find . -name "*.txt": Find files by name from a starting directory.*

Network Tools

  • Domain Resolution:
    • dig domain: Find IP addresses associated with a domain.

File Editing and Utilities

  • Concatenate Files:
    • cat file1 file2 > both.txt: Concatenates files.
  • Editing Files:
    • nano file: Full-screen text editor, supports basic operations like copy-paste.
    • Save in Nano with Ctrl-O and exit with Ctrl-X.

These commands and utilities form the foundation for managing Linux systems through the command line, offering tools for file management, process control, software installation, and system diagnostics.