Skip to content

Bash Utility Usages

Terminal window
tar --create --file /tmp/archive.tar.gz --verbose /tmp/archive/ # Create archive
tar xzf <archive name>.tar.gz # Unpack archive

Relative symlinks can have unintended consequences - I try to avoid

Terminal window
readlink /tmp/mysymlink
ln -s /tmp/target.a /tmp/symlink_to_target.a

Can encounter errors with fuzzy matching if too many files return

Terminal window
#rm -rf ./*.dat # old style
find . -name "*.rst" -print0 -exec echo {} +
find . -name "*.rst" -print0 -exec rm -f {} +
Terminal window
ps aux | grep python| awk '{ print $2 }' # List out processes to kill

Kill processes

Terminal window
kill $(ps aux | grep python | awk '{ print $2 }')
# get hanging proces
kill -9 $(ps aux | grep python | awk '{ print $2 }')
# Or, with pkill
pkill -f python
# Or, with killall
killall -r python

View and reload HBA File

SHOW hba_file;
SHOW data_directory;
SELECT pg_reload_conf();

pg_dump and pg_restore examples

Terminal window
pg_dump -Z 6 -F c db_name > /tmp/db_dump.dump
pg_restore -F c ./db_dump.dump -d db_name -v

Improved version

Terminal window
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

Terminal window
HOST=example; ssh "$HOST" 'rsync -avP ~/ "archivehost:/tmp/archive/$HOST/home/' &
HOST=example2; ssh "$HOST" 'rsync -avP ~/ "archivehost:/tmp/archive/$HOST/home/' &
Terminal window
iperf3 -s -p 5201 # On server
iperf3 -c <server-ip> -p 5201 # On Client
iperf3 -c <server-ip> -p 5201 -u # udp
for port in {5201..5210}; do iperf3 -c <server-ip> -p $port; done # multiple ports
Terminal window
rpm -qa package # Find out where in file system package is installed
rpm -qa | grep package # Lookup where packages are installed
Terminal window
lsof /path/to/file # See What’s Using a File or Directory
lsof -u username
kill -9 $(lsof -t -i :5000)
lsof -p <PID> # List open files for process ID
Terminal window
git fetch
for 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/##' )
fi
done
Terminal window
xmllint -format -recover a.xml > b.xml