Linux Commands Basic for beginners

 


Linux commands are essential for interacting with the operating system via the terminal. Below is a concise overview of basic Linux commands, their purposes, and examples to help you get started.

Key Concepts
  • Linux commands are case-sensitive and typically entered in lowercase.
  • Commands are often combined with options (flags) and arguments.
  • Use man <command> (e.g., man ls) to access the manual for any command.
Basic Linux Commands and Examples
  1. Navigating the File System
    • pwd: Prints the current working directory.
      • Example: pwd
        • Output: /home/user
    • ls: Lists files and directories in the current directory.
      • Example: ls -l
        • Output: Detailed list with permissions, owner, size, etc. (e.g., drwxr-xr-x 2 user user 4096 May 23 15:30 documents)
    • cd: Changes the current directory.
      • Example: cd /home/user/documents
        • Moves to the documents directory.
      • Example: cd ..
        • Moves up one directory level.


  1. File and Directory Management
    • mkdir: Creates a new directory.
      • Example: mkdir my_folder
        • Creates a directory named my_folder.
    • rm: Removes files or directories.
      • Example: rm file.txt
        • Deletes file.txt.
      • Example: rm -r my_folder
        • Deletes my_folder and its contents recursively.
    • cp: Copies files or directories.
      • Example: cp file.txt /home/user/backup/
        • Copies file.txt to the backup directory.
    • mv: Moves or renames files/directories.
      • Example: mv file.txt newfile.txt
        • Renames file.txt to newfile.txt.
      • Example: mv file.txt /home/user/documents/
        • Moves file.txt to the documents directory.


  1. Viewing and Editing Files
    • cat: Displays file contents.
      • Example: cat file.txt
        • Outputs the contents of file.txt.
    • less: Views file contents interactively (scrollable).
      • Example: less file.txt
        • Opens file.txt for viewing; press q to quit.
    • nano: Simple text editor.
      • Example: nano file.txt
        • Opens file.txt for editing; save with Ctrl+O, exit with Ctrl+X.
    • touch: Creates an empty file or updates a file’s timestamp.
      • Example: touch newfile.txt
        • Creates an empty file named newfile.txt


  1. File Permissions
    • chmod: Changes file permissions.
      • Example: chmod 755 script.sh
        • Grants owner full permissions (read, write, execute) and others read/execute permissions.
    • chown: Changes file ownership.
      • Example: chown user:group file.txt
        • Changes the owner of file.txt to user and group to group.
  2. System Information
    • whoami: Displays the current user.
      • Example: whoami
        • Output: user
    • df: Shows disk space usage.
      • Example: df -h
        • Output: Disk usage in human-readable format (e.g., GB).
    • top: Displays real-time system processes.
      • Example: top
        • Shows running processes; press q to quit.
    • uname: Displays system information.
      • Example: uname -a
        • Output: Kernel and system details.
  3. File Searching and Filtering
    • find: Searches for files/directories.
      • Example: find /home -name "*.txt"
        • Finds all .txt files in /home.
    • grep: Searches text within files.
      • Example: grep "error" log.txt
        • Finds lines containing “error” in log.txt.
    • wc: Counts lines, words, or characters.
      • Example: wc -l file.txt
        • Output: Number of lines in file.txt.
  4. Process Management
    • ps: Lists running processes.
      • Example: ps aux
        • Shows all processes with details.
    • kill: Terminates a process by ID.
      • Example: kill 1234
        • Stops the process with PID 1234.
    • killall: Terminates processes by name.
      • Example: killall firefox
        • Stops all Firefox processes.
  5. Networking
    • ping: Checks connectivity to a host.
      • Example: ping google.com
        • Tests connection to google.com.
    • curl: Transfers data from/to a server.
      • Example: curl https://example.com
        • Downloads content from example.com.
    • wget: Downloads files from the web.
      • Example: wget https://example.com/file.txt
        • Downloads file.txt.
  6. Piping and Redirection
    • | (pipe): Sends output of one command as input to another.
      • Example: ls -l | grep txt
        • Lists files and filters for those containing “txt”.
    • >: Redirects output to a file (overwrites).
      • Example: echo "Hello" > file.txt
        • Writes “Hello” to file.txt.
    • >>: Appends output to a file.
      • Example: echo "World" >> file.txt
        • Appends “World” to file.txt.
Tips for Beginners
  • Combine Commands: Use pipes (|) to chain commands, e.g., cat file.txt | grep "pattern".
  • Use Tab Completion: Press Tab to auto-complete commands or file names.
  • Learn Shortcuts: Ctrl+C stops a command, Ctrl+D exits a shell.
  • Practice Safely: Be cautious with rm -rf, as it deletes files permanently.

Comments

Popular posts from this blog

CRUD SPRING REACTIVE WEBFLUX +Mongo DB

Top 7 Digital Transformation Companies

100 perusahaan perangkat lunak (software) populer dari Eropa dan Amerika yang memiliki kehadiran atau operasional di Indonesia.

Regression Testing dalam UAT Environment?

TOP 8 Framework Populer menggunakan bahasa .NET

Python Date and Time Manipulation

Daftar Kata Kunci (Keyword) dalam Bahasa Pemrograman Python

TOP 5 Trends Programming 2024

20 Data Center Terbesar di Dunia

Tahukah Kamu bagaimana algoritma social media facebook dan instagram bekerja ?