Master Linux Like a Pro: Essential Commands and Practices

2025-02-12

Linux is a powerful operating system widely used in IT, DevOps, and cloud computing. Mastering Linux commands can significantly enhance your productivity, troubleshooting skills, and ability to manage servers and cloud environments. Below is a comprehensive guide to essential Linux commands, along with practical examples and verified codes.

File & Directory Management

  • ls: List directory contents
    ls -l /home/user
    
  • cd: Change directory
    cd /var/log
    
  • cp: Copy files or directories
    cp file1.txt /backup/
    
  • rm: Remove files or directories
    rm -r old_directory
    
  • mkdir: Create a new directory
    mkdir new_folder
    

File Viewing & Editing

  • cat: Display file content
    cat /etc/hosts
    
  • nano: Simple text editor
    nano file.txt
    
  • grep: Search text using patterns
    grep "error" /var/log/syslog
    
  • sed: Stream editor for filtering and transforming text
    sed 's/foo/bar/g' file.txt
    
  • awk: Pattern scanning and processing language
    awk '{print $1}' file.txt
    

Process Management

  • ps: Display active processes
    ps aux
    
  • top: Display and manage processes in real-time
    top
    
  • kill: Terminate processes
    kill -9 1234
    

Disk Management

  • df: Report file system disk space usage
    df -h
    
  • du: Estimate file space usage
    du -sh /home/user
    
  • mount: Mount a file system
    mount /dev/sdb1 /mnt
    

Networking

  • ifconfig: Configure network interfaces
    ifconfig eth0
    
  • ping: Test network connectivity
    ping google.com
    
  • ssh: Secure shell for remote login
    ssh user@remote_host
    
  • scp: Securely copy files between hosts
    scp file.txt user@remote_host:/path/
    

User & Group Management

  • useradd: Add a new user
    useradd newuser
    
  • passwd: Change user password
    passwd newuser
    
  • whoami: Display current user
    whoami
    

System Monitoring

  • uptime: Show system uptime
    uptime
    
  • free: Display memory usage
    free -m
    
  • lscpu: Display CPU architecture information
    lscpu
    

Package Management

  • apt: Package handling utility for Debian-based systems
    apt install nginx
    
  • yum: Package manager for RPM-based systems
    yum install httpd
    

Containerization & Orchestration

  • docker: Manage Docker containers
    docker run -d nginx
    
  • kubectl: Kubernetes command-line tool
    kubectl get pods
    

Automation & CI/CD

  • ansible: Automation tool
    ansible-playbook playbook.yml
    
  • terraform: Infrastructure as code tool
    terraform apply
    

Cloud Services

  • aws: AWS CLI tool
    aws s3 ls
    
  • gcloud: Google Cloud CLI tool
    gcloud compute instances list
    

Logging & Monitoring

  • prometheus: Monitoring and alerting toolkit
    prometheus --config.file=prometheus.yml
    
  • grafana: Analytics and monitoring platform
    systemctl start grafana-server
    

What Undercode Say

Mastering Linux commands is essential for anyone working in IT, DevOps, or cloud computing. These commands not only improve productivity but also enhance your ability to troubleshoot and manage systems effectively. Here are some additional tips and commands to further your Linux expertise:

1. Scripting: Automate repetitive tasks using shell scripts.

#!/bin/bash
echo "Hello, World!"
  1. Permissions: Manage file permissions using `chmod` and chown.
    chmod 755 script.sh
    chown user:group file.txt
    

3. Networking: Use `netstat` to monitor network connections.

netstat -tuln

4. Logs: Analyze system logs using `journalctl`.

journalctl -xe

5. Backups: Create backups using `tar`.

tar -czvf backup.tar.gz /path/to/backup
  1. Security: Harden your system with `ufw` (Uncomplicated Firewall).
    ufw enable
    ufw allow ssh
    

7. Performance: Monitor system performance with `vmstat`.

vmstat 1

8. Updates: Keep your system updated.

apt update && apt upgrade -y
  1. Remote Access: Use `tmux` or `screen` for persistent remote sessions.
    tmux new -s mysession
    

  2. File Transfer: Use `rsync` for efficient file transfers.

    rsync -avz /source/ user@remote:/destination/
    

By incorporating these commands and practices into your workflow, you can become a Linux power user. For further reading, check out the following resources:

Linux is a versatile and powerful tool, and mastering it will open up countless opportunities in the tech world. Keep practicing, and you’ll soon be navigating Linux like a pro!

References:

Hackers Feeds, Undercode AIFeatured Image

Scroll to Top