Skip to content

Instantly share code, notes, and snippets.

Last active December 20, 2021 00:15
What would you like to do?
Bash Commands
#!/usr/bin/env bash
# split strings
remote=`echo $GIT_BRANCH | cut -d '/' -f 1`
branch=`echo $GIT_BRANCH | cut -d '/' -f 2`
# finding working directory of a process (where $$ is the PID, obtained through `pgrep` or other)
pwdx $$
# or
lsof -p $$ | grep cwd
# or
readlink -e /proc/$$/cwd #This one seems to give the exact value needed
# replace strings in a file - Mac OS X
sed -i '' -e 's/STRING_TO_REPLACE/NEW_STRING/g' filename
# show all network interfaces
ifconfig -a
# Check if variable is empty
if [ -z "$var" ]; then
echo "Variable not provided"
exit 1
# Check if directory does not exist.
if [ ! -d "$dir" ]; then
echo "Directory $dir does not exist!"
exit 1
# Check if file exists.
if [ -f "$FILE" ]; then
echo "$FILE exists."
# Create a tar file without absolute directories.
# '-C' specifies the directory to switch to before packing.
tar -zcf /tmp/deploy.tar.gz -C deploy .
# Get directory of current script.
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
# See all open ports.
sudo lsof -i -P -n | grep LISTEN
# Check what's running on a specific port.
sudo lsof -i:53 #replace 53 by any other port.
# Print 1st column of output
echo foo bar baz | awk '{print $1}'
#!/usr/bin/env bash
# Enable automatic login.
sudo sed -i -e 's/# AutomaticLoginEnable = true/AutomaticLoginEnable = true/g' /etc/gdm3/custom.conf
sudo sed -i -e 's/# AutomaticLogin = user1/AutomaticLogin = vagrant/g' /etc/gdm3/custom.conf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment