Essential Linux Shell Commands for System Administration and I/O Control
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 + Zto suspend the currently running command and return control to the prompt. - List suspended/runing jobs: Execute
jobsto view all background tasks associated with the current terminal session. - Resume in background: Use
bgto continue a paused job without occupying the terminal interface. - Return to foreground: Invoke
fgto bring a background task back to active interaction. - Detach from terminal: Prefix commands with
nohupto 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 toerror_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&1as 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