A Comprehensive Guide to the Most Frequently used Linux Bash Commands

1. Navigation & Directory Management

These commands allow you to move around the file system, view contents, and manage folders.

  • pwd (Print Working Directory)
    • Usage: pwd
    • Meaning: Displays the absolute path of the current working directory you are in. Learn more via the GNU Coreutils Documentation.
  • ls (List)
    • Usage: ls -la (Lists all files, including hidden ones, in a detailed list format)
    • Meaning: Lists directory contents. Common flags include -l (long format) and -a (all hidden files). Check out this DigitalOcean Linux Command Cheat Sheet for more options.
  • cd (Change Directory)
    • Usage: cd /path/to/directory or cd ~ (goes to home)
    • Meaning: Changes your current working directory. Typing cd .. moves you up one level.
  • mkdir (Make Directory)
    • Usage: mkdir my_folder or mkdir -p path/to/nested/folder
    • Meaning: Creates a new directory. The -p flag creates parent directories as needed without throwing an error if they already exist.

2. File & Text Manipulation

Create, move, copy, delete, and inspect files with these core utilities.

  • touch
    • Usage: touch filename.txt
    • Meaning: Creates an empty file or updates the access/modification timestamps of an existing file.
  • cp (Copy)
    • Usage: cp source.txt destination.txt (use -r for directories)
    • Meaning: Copies files or directories from one location to another.
  • mv (Move/Rename)
    • Usage: mv old_name.txt new_name.txt or mv file.txt /path/to/destination/
    • Meaning: Moves files/directories or renames them if the destination is in the same directory.
  • rm (Remove)
    • Usage: rm filename.txt or rm -rf folder_name/
    • Meaning: Deletes files or directories. Warning: The -rf flag forces recursive deletion without prompting—use with extreme care! Read more on safety precautions via Linuxize.
  • cat (Concatenate)
    • Usage: cat filename.txt
    • Meaning: Outputs the entire contents of a file to the terminal screen. Great for quick viewing of small files.
  • less
    • Usage: less large_file.log
    • Meaning: Opens a file interactively, allowing you to scroll page-by-page through large logs without flooding your terminal. Press q to exit.
  • head / tail
    • Usage: head -n 20 file.txt or tail -f /var/log/syslog
    • Meaning: head outputs the first lines of a file (default 10), while tail outputs the last lines. The -f flag on tail is especially useful for real-time log monitoring.

3. Searching & Filtering

Quickly find files or search through text content.

  • grep (Global Regular Expression Print)
    • Usage: grep "error" logfile.txt or grep -r "search_term" ./
    • Meaning: Searches for specific patterns or strings inside files. For deep dives into text searching, check out GNU Grep Documentation.
  • find
    • Usage: find /home/user/ -name "*.txt"
    • Meaning: Searches for files and directories across the file system based on name, size, modification date, or permissions.

4. Permissions & Administration

Control access rights and execute administrative tasks.

  • chmod (Change Mode)
    • Usage: chmod 755 script.sh or chmod +x script.sh
    • Meaning: Modifies file or directory permissions (Read, Write, Execute) for user, group, and others.
  • chown (Change Owner)
    • Usage: chown username:groupname filename.txt
    • Meaning: Changes the user and/or group ownership of a file or directory.
  • sudo (Superuser Do)
    • Usage: sudo apt update
    • Meaning: Executes a command with elevated administrative (root) privileges.

5. System & Network Monitoring

Keep an eye on system resources, processes, and network connectivity.

  • ps (Process Status)
    • Usage: ps aux
    • Meaning: Displays a snapshot of currently running processes.
  • top / htop
    • Usage: top or htop
    • Meaning: Displays dynamic, real-time views of system performance, CPU usage, memory utilization, and active processes.
  • df (Disk Free) & du (Disk Usage)
    • Usage: df -h (human-readable) or du -sh folder_name/
    • Meaning: df shows available disk space on file systems, while du summarizes disk space used by specific files or directories.
  • free
    • Usage: free -m (displays in megabytes)
    • Meaning: Displays the total amount of free and used physical and swap memory in the system.
  • curl / wget
    • Usage: curl -O https://example.com/file.zip or wget https://example.com/file.zip
    • Meaning: Command-line tools used to transfer data from or to servers, commonly used for downloading files or testing APIs.

Sources

Leave a Reply

Your email address will not be published. Required fields are marked *