Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Core Linux Terminal Utilities and Usage Patterns

Tech Apr 19 18

Directory Navigation and File System Enspection

  • ls: Enumerates contents within a target folder.
  • pwd: Outputs the absolute path of the current shell environment.
  • cd <path>: Transitions the shell to a specified directory.
  • cd ..: Moves up one level in the hierarchy.
  • cd -: Reverts to the previously active directory.
  • tree: Generates an ASCII-based hierarchical visualization of folders and files.

File Manipulation and Search

  • cat <file>: Streams raw text data to standard output.
  • rm <target>: Permanently deletes specified items.
  • mv <src> <dest>: Transfers files or applies a new name if the destination shares the same parent.
  • cp <src> <dest>: Creates a duplicate at the specified location.
  • locate <query>: Executes rapid filename searches via a pre-indexed database.

Text Processing and Editors

  • vim <target>: Launches a modal text editor.
    • Enter insertion state: i
    • Return to normal state: Esc
    • Trigger command mode: :
    • Commmit and exit: :wq
    • Abort and exit: :q!
  • head -n <count> <file>: Extracts the leading lines of a document.
  • tail -n <count> <file>: Extracts trailing lines. Append -f to continuous log monitoring.
  • more <file>: Paginates terminal output. Use +<n> to start at a specific line, or -<n> to restrict the viewport height.

Resource Monitoring and Metrics

  • top: Renders a real-time, interactive table of running processes and hardware utilization.
  • du -sh <path>: Calculates storage consumption (-s) using scalable units like KB, MB, or GB (-h).
  • wc: Tallies lines (-l), words (-w), or characters (-c).
  • Optimized regular file counter:
    ls -la | grep -c "^-"
    
    Logic: ls -la produces a verbose directory listing. grep -c "^-" directly matches and counts lines beginning with a dash, which denotes standard files.

I/O Redirection and Shell Customization

  • Output routing:
    • cmd > file.txt: Overwrites the target with fresh output.
    • cmd >> file.txt: Preserves existing data and appends to the end.
  • Persistent shortcuts:
    alias ll='ls -lh --color=auto'
    
  • Inline terminal execution from Vim: Prepend :! to any shell instruction (e.g., :!whoami) to run it without closing the editor.
  • Temporal calculations:
    target_date=$(date -d "72 hours ago" +"%Y-%m-%d")
    echo "Resolved value: $target_date"
    
  • Locale verification and override:
    locale
    export LC_ALL="en_US.UTF-8"
    

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

SBUS Signal Analysis and Communication Implementation Using STM32 with Fus Remote Controller

Overview In a recent project, I utilized the SBUS protocol with the Fus remote controller to control a vehicle's basic operations, including movement, lights, and mode switching. This article is aimed...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.