Skip to content

Instantly share code, notes, and snippets.

@kzap
Last active August 29, 2015 14:23
Show Gist options
  • Save kzap/6523cf0c87a073e58d9a to your computer and use it in GitHub Desktop.
Save kzap/6523cf0c87a073e58d9a to your computer and use it in GitHub Desktop.
Useful Unix Commands
#sql-restore-files
for SQL in *.sql.gz; do DB=${SQL/\.sql.gz/}; echo importing $DB; zcat $SQL | mysql -u root --password='{PASSWORD}' $DB; done
#backup all directories and compress them
find ./* -maxdepth 0 -type d -exec echo "Archiving {}" \; -exec tar -cjf "{BACKUP_DIR}/{}-{DATE}.tar.bz2" \;
#find and replace in files recursive without touching files that dont match
find ./ -type f -name '*.php' -print0 | xargs -0 grep 'FIND' -l | xargs sed -i 's/FIND/REPLACE/g'
#apache max clients recommendation
ps aux | egrep "^apache.*httpd" | awk -v mem=`free -m | grep Mem | awk '{print $2}'` '{sum+=$6} END {printf "Total Processes: %13s\nTotal RAM: %23s KB\nTotal RAM: %23s MB\nAvg RAM per Proc: %17s MB\nMax Recommended Clients: %10s\n", NR,sum,sum/1024,sum/NR/1024,(mem*.7)/(sum/NR/1024)}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment