Some useful Bash Scripts
A curated list of bash scripts to automate a few stuff to make my life (or could be yours) easy.
1. Update local GIT repositories
A bash script that iterates through directories and runs git pull
in those that are Git repositories:
# Loop through each directory in the current directory
for dir in ./*; do
# Check if it's a directory (avoid hidden files)
if [[ -d "$dir" && ! "$dir" == .git ]]; then
# Change directory to the current one
pushd "$dir" >/dev/null 2>&1
# Check if it's a Git repository (presence of .git directory)
if [[ -d .git ]]; then
echo "Updating $dir..."
# Pull changes from remote repository
git pull
fi
# Move back to the previous directory
popd >/dev/null 2>&1
fi
done
2. Kill port
killport () {
PID=$(sudo lsof -t -i:$1)
sudo kill -9 ${PID}
}
Usage:
$ killport 8080
3. Clean up node_modules to free disk space
npx npkill
4. Install Android Studio
sudo apt update \
wget https://dl.google.com/dl/android/studio/ide-zips/2024.2.1.12/android-studio-2024.2.1.12-linux.tar.gz \
tar -zxvf android-studio-2024.2.1.12-linux.tar.gz \
sudo mv android-studio /opt/ \
sudo ln -sf /opt/android-studio/bin/studio.sh /bin/android-studio
Ceate Desktop Entry:
sudo nano /usr/share/applications/android-studio.desktop
with following content:
[Desktop Entry]
Version=1.0
Type=Application
Name=Android Studio
Comment=Android Studio
Exec=bash -i "/opt/android-studio/bin/studio.sh" %f
Icon=/opt/android-studio/bin/studio.png
Categories=Development;IDE;
Terminal=false
StartupNotify=true
StartupWMClass=jetbrains-android-studio
Name[en_GB]=android-studio.desktop
Last updated on: 2024-12-19