Skip to content

Instantly share code, notes, and snippets.

@yusufhm
Last active December 20, 2021 00:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yusufhm/0a223c6821fe4db79b73 to your computer and use it in GitHub Desktop.
Save yusufhm/0a223c6821fe4db79b73 to your computer and use it in GitHub Desktop.
Bash Commands
#!/usr/bin/env bash
# split strings
GIT_BRANCH="origin/master"
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
fi
# Check if directory does not exist.
if [ ! -d "$dir" ]; then
echo "Directory $dir does not exist!"
exit 1
fi
# Check if file exists.
FILE=/etc/resolv.conf
if [ -f "$FILE" ]; then
echo "$FILE exists."
fi
# 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