Bash Utility Usages
tar examples
Section titled “tar examples”tar --create --file /tmp/archive.tar.gz --verbose /tmp/archive/ # Create archivetar xzf <archive name>.tar.gz # Unpack archive
Symlinking
Section titled “Symlinking”Relative symlinks can have unintended consequences - I try to avoid
readlink /tmp/mysymlinkln -s /tmp/target.a /tmp/symlink_to_target.a
Remove files - rm too long error
Section titled “Remove files - rm too long error”Can encounter errors with fuzzy matching if too many files return
#rm -rf ./*.dat # old stylefind . -name "*.rst" -print0 -exec echo {} +find . -name "*.rst" -print0 -exec rm -f {} +
Kill Procs
Section titled “Kill Procs”ps aux | grep python| awk '{ print $2 }' # List out processes to kill
Kill processes
kill $(ps aux | grep python | awk '{ print $2 }')# get hanging proceskill -9 $(ps aux | grep python | awk '{ print $2 }')# Or, with pkillpkill -f python# Or, with killallkillall -r python
Postgres Commands
Section titled “Postgres Commands”View and reload HBA File
SHOW hba_file;SHOW data_directory;SELECT pg_reload_conf();
pg_dump and pg_restore examples
pg_dump -Z 6 -F c db_name > /tmp/db_dump.dumppg_restore -F c ./db_dump.dump -d db_name -v
Quick and dirty backups
Section titled “Quick and dirty backups”Improved version
hosts=("example" "example2")for h in "${hosts[@]}"; do echo "Runnning $h" ssh "$h" 'rsync -avP ~/ archivehost:/tmp/archive/$HOST/home/'done
Simple version using excel to generate lists
HOST=example; ssh "$HOST" 'rsync -avP ~/ "archivehost:/tmp/archive/$HOST/home/' &HOST=example2; ssh "$HOST" 'rsync -avP ~/ "archivehost:/tmp/archive/$HOST/home/' &
Iperf3 usage
Section titled “Iperf3 usage”iperf3 -s -p 5201 # On serveriperf3 -c <server-ip> -p 5201 # On Clientiperf3 -c <server-ip> -p 5201 -u # udpfor port in {5201..5210}; do iperf3 -c <server-ip> -p $port; done # multiple ports
RPM Commands
Section titled “RPM Commands”rpm -qa package # Find out where in file system package is installedrpm -qa | grep package # Lookup where packages are installed
Lsof commands
Section titled “Lsof commands”lsof /path/to/file # See What’s Using a File or Directorylsof -u usernamekill -9 $(lsof -t -i :5000)lsof -p <PID> # List open files for process ID
Cleanup remote git branches
Section titled “Cleanup remote git branches”git fetchfor branch in $(git branch -r --merged | grep -v HEAD | grep -v develop | grep -v master | grep -v master | sed /\*/d); do if [ -z "$(git log -1 --since='Jun 15, 2020' -s ${branch})" ]; then echo -e `git show --format="%ci %cr %an" ${branch} | head -n 1` \\t$branch remote_branch=$(echo ${branch} | sed 's#origin/##' ) fidone
Format xml file in place
Section titled “Format xml file in place”xmllint -format -recover a.xml > b.xml