Bash Cheat Sheet
##FILESYSTEM | |
# append all .csv files in only one and ignore headers in subsequent files. | |
#!/bin/bash | |
OutFileName="X.csv" # Fix the output name | |
i=0 # Reset a counter | |
for filename in ./*.csv; do | |
if [ "$filename" != "$OutFileName" ] ; # Avoid recursion | |
then | |
if [[ $i -eq 0 ]] ; then | |
head -1 "$filename" > "$OutFileName" # Copy header if it is the first file | |
fi | |
tail -n +2 "$filename" >> "$OutFileName" # Append from the 2nd line each file | |
i=$(( $i + 1 )) # Increase the counter | |
fi | |
done | |
#Recursively search directory for text string | |
grep -R "classify-tables" * | |
##DOCKER | |
#check # of stopped containers via ssh | |
ssh -i habitat-routing.pem ec2-user@osrm.philadelphia.atlas.tryhabitat.com 'sudo su -c "cd ..; cd ..; cd var/lib/docker/containers && ls -1 | wc -l"' | |
##PSQL | |
#Dump and restore database, ignoring large tables | |
#CAVEAT: if the database string contains percent-signs, you need to encodeURIComponent. this script doesn't do that part. | |
TEMP_DUMP_DIR=new_out.dir | |
PROD_READ_REPLICA=YOUR_SOURCE_PG_URL | |
WAREHOUSE_WRITE_PUBLIC=YOUR_TARGET_PG_URL | |
rm $TEMP_DUMP_DIR || true \ | |
&& \ | |
pg_dump $PROD_READ_REPLICA \ | |
--verbose \ | |
--file=$TEMP_DUMP_DIR \ | |
--jobs=10 \ | |
--format=d \ | |
--no-privileges \ | |
--no-owner \ | |
--no-synchronized-snapshots \ | |
--exclude-table-data=receipt_images \ | |
--exclude-table-data=jobs \ | |
--exclude-table-data=user_locations \ | |
--exclude-table-data=vendor_receipts \ | |
--exclude-table-data=email_orders \ | |
--exclude-table-data=transaction_audit_logs \ | |
--exclude-table-data=engine_messages \ | |
&& \ | |
pg_restore $TEMP_DUMP_DIR \ | |
-d $WAREHOUSE_WRITE_PUBLIC \ | |
--verbose \ | |
--format=d \ | |
--clean \ | |
--no-owner \ | |
&& \ | |
rm -rf $TEMP_DUMP_DIR | |
##ADB | |
#View connected devices | |
adb devices | |
#Reset ADB server - good for debugging devices not being recognized / weird issues | |
adb kill-server && adb start-server | |
#Open browser URL on connected device | |
adb shell am start -a android.intent.action.VIEW -d http://www.stackoverflow.com | |
#Log all plugged in device output logs | |
adb logcat | |
#Log, but filter by process | |
adb logcat -s "browser","webkit","ReactNativeJS" | |
##GIT | |
##Search a file's previous versions for a string (the actual file, not commit message) | |
git rev-list --all scripts/script.ts | ( | |
while read revision; do | |
git grep -F 'YOUR SEARCH HERE' $revision scripts/script.ts | |
done | |
) | |
##AWS CLI | |
## | |
aws ec2 describe-security-groups | jq '.SecurityGroups[] | select(.GroupName == "atlas") | .GroupId' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment