Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Essential Linux Shell Commands for System Administration and I/O Control

Tech 1

Shell Environment Configuration

To identify the currently active command interpreter, query the SHELL environment varible:

echo "$SHELL"

A comprehensive list of interpreters installed on the system can be retrieved via:

cat /etc/shells
# Alternatively: chsh --list

Modifying the default login shell requires appropriate user permissions using the chsh utility:

chsh -s /bin/zsh  # Set Zsh as default
chsh -s /bin/bash # Set Bash as default

Background and Foreground Job Management

Executing long-running tasks in the terminal often requires shifting them between active and suspended states.

  • Pause foreground process: Press Ctrl + Z to suspend the currently running command and return control to the prompt.
  • List suspended/runing jobs: Execute jobs to view all background tasks associated with the current terminal session.
  • Resume in background: Use bg to continue a paused job without occupying the terminal interface.
  • Return to foreground: Invoke fg to bring a background task back to active interaction.
  • Detach from terminal: Prefix commands with nohup to prevent termination when the session ends:
    nohup ./data_processing.sh > execution.log 2>&1 &
    
  • Filter processes by working directory: Locate all active processes originating from a specific path:
    ps aux | grep "$(pwd)"
    

Storage Monitoring

Inspect available and utilized filesystem volumes with human-readable formatting:

df -h

Network Port Analysis

Identify open TCP listening sockets on the local machine. The following pipeline isolates ports containing a specific numeric sequence:

netstat -tlnp | grep ":8080"

Standard I/O Stream Redirection

Understanding file descriptors is critical for managing command output:

  • 0: Standard Input (stdin)
  • 1: Standard Output (stdout)
  • 2: Standard Error (stderr)

Key redirection operators:

  • command 2>&1: Merges error output with standard output, directing both to the same stream or destination.
  • command 2> error_only.txt: Routes error messages exclusively to error_only.txt, leaving standard output visible on the terminal.
  • command 2>&1 > combined.log: Redirects standard error to the terminal while sending standard output to a file (order matters in bash).
  • command 2> '&1': Treats &1 as a literal filename rather than a stream reference, creating a file named exactly &1.

Text Processing Utilities

Pattern Matching with Extended Regex Filter lines containing multiple distinct patterns from a target file:

grep -E "timeout|connection_refused|fatal" system.log

Data Deduplication Remove duplicate entries from a dataset by combining sorting and filtering:

sort inventory_list.csv | uniq > deduplicated_results.csv

Alternatively, achieve identical results using the built-in unique flag for streamlined execution:

sort -u inventory_list.csv > deduplicated_results.csv
Tags: Linuxbash

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...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

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...

Leave a Comment

Anonymous

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