You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# lsof -i tcp:8080 | awk 'FNR == 2{print $2}' | xargs kill -9functionkillByPort {
local port=$1echo"killing port ${port}"
lsof -i tcp:${port}| awk 'FNR == 2{print $2}'| xargs kill -9
echo"done . . . "
}
killByPort $1## use : sh killByPort.sh {port}# port -> 2020, 8000
Backup Script:
#!/bin/bashfunctionbackup {
local backup_dir="$1"local source_dir="$2"# Check if source directory/file existsif [ !-e"$source_dir" ];thenecho"Error: Source directory/file '$source_dir' not found."exit 1
fi# Create backup directory if it doesn't existif [ !-d"$backup_dir" ];then
mkdir -p "$backup_dir"filocal timestamp=$(date +%Y%m%d%H%M%S)local backup_filename="backup_$timestamp.tar.gz"
tar -czf "$backup_dir/$backup_filename""$source_dir"echo"Backup created: $backup_filename"
}
# Usage: backup <backup_directory> <source_file_or_directory>
backup "./backup""./example.txt"
Disk Space Checker:
#!/bin/bashfunctiondisk_space {
local partition=$1local disk_space=$(df -h $partition| awk 'NR==2 {print $4}')echo"Available disk space on $partition: $disk_space"
}
disk_space /
functionsearch_and_replace {
local search_string="$1"local replace_string="$2"local directory="$3"
grep -rl "$search_string""$directory"| xargs sed -i "s/$search_string/$replace_string/g"echo"String '$search_string' replaced with '$replace_string' in files under '$directory'."
}