Expert assistance with Linux bash commands, shell scripting, system administration, file operations, and command-line utilities...
Expert guidance for Linux bash operations, scripting, and system administration.
ls -lah - List files with details, including hiddenfind /path -name "pattern" - Find files by namegrep -r "pattern" /path - Recursive text searchchmod +x file - Make file executablechown user:group file - Change ownershiptar -czf archive.tar.gz dir/ - Create compressed archivetar -xzf archive.tar.gz - Extract archiveps aux | grep process - Find running processestop / htop - Monitor system resourceskill -9 PID - Force kill processnohup command & - Run command in backgroundjobs - List background jobsfg %1 - Bring job to foregrounddf -h - Disk usage human-readabledu -sh dir/ - Directory sizefree -h - Memory usageuname -a - System informationlsb_release -a - Distribution infocat file | head -n 10 - First 10 linestail -f log.txt - Follow log filesed 's/old/new/g' file - Replace textawk '{print $1}' file - Print first columnsort file | uniq - Remove duplicates#!/bin/bash
set -euo pipefail # Exit on error, undefined vars, pipe failures
# Script description
readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
main() {
# Your logic here
echo "Hello, World!"
}
main "$@"
# Check command success
if ! command -v tool &> /dev/null; then
echo "Error: tool not found" >&2
exit 1
fi
# Trap errors
trap 'echo "Error on line $LINENO"' ERR
# Constants (uppercase)
readonly CONFIG_FILE="/etc/app.conf"
# Variables (lowercase)
user_input="$1"
# Arrays
files=("file1.txt" "file2.txt")
for file in "${files[@]}"; do
echo "$file"
done
if [[ -f "file.txt" ]]; then
echo "File exists"
fi
for file in *.txt; do
echo "Processing $file"
done
read -p "Enter value: " user_value
my_function() {
local arg1="$1"
echo "Received: $arg1"
}
"$variable" to prevent word splittingshellcheck script.sh to validate scripts$? to check last command statusset -x to trace executionset -e to exit on errors