Bash
Various terminal commands that I don't wanna remember

Super Powers

Let there be life!
create.sh
upgrades.sh
destroy.sh
usage.sh
process.sh
security.sh
compression.sh
searching.sh
git.sh
1
# create directory named george
2
mkdir george
3
4
# create file with name george
5
touch george
6
7
# edit file
8
nano george
9
10
# edit with vi
11
vi george
Copied!
1
# check for updates
2
sudo apt-get update
3
4
# upgrade
5
sudo apt-get upgrade
6
7
# install new package
8
sudo apt-get install new_package
9
10
# cleanup
11
sudo apt-get autoremove
12
13
# Fix missing keys
14
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4B8EC3BAABDC4346
Copied!
1
# find process running on port 5000
2
sudo lsof -i tcp:5000
3
4
# kill a process with pid 1990
5
kill -9 1990
6
7
# find and kill a process running on port 5000
8
sudo kill $( sudo lsof -i tcp:5000 -t )
9
10
# kill all processes named Google Chrome Helper
11
killall -9 "Google Chrome Helper"
Copied!
1
# check docker usage
2
sudo docker stats
3
4
# check process usage
5
top
6
7
# check memory usage
8
free -h
9
10
# check disk usage
11
df -lh
12
13
# list all directories in current folder with their size
14
du -h
Copied!
1
# full process tree
2
ps -axfo pid,uname,cmd
Copied!
1
# check application certificate
2
spctl -a -vv /Applications/Google\ Chrome.app
3
# /Applications/Google Chrome.app: accepted
4
# source=Notarized Developer ID
5
# origin=Developer ID Application: Google, Inc. (EQHXZ8M8AV)
Copied!
1
# gzip compression on a tar archiv: tar_file files_or_folder_to_be_compressed
2
tar cvzf my-files.tar.gz ./my-files
3
4
# unzip a tar file
5
tar xvzf my-files.tar.gz
Copied!
1
# Find a file by name on your machine
2
sudo find / -name 'secret.txt'
3
4
# delete backup files
5
sudo find . -name "*.bak" -delete
Copied!
1
# delete all local branches except main, master and develop
2
git branch | grep -v "main" | grep -v "master" | grep -v "develop" | xargs git branch -D
Copied!
Virtual Screen
virtual-screen.sh
xvfb-deps.sh
1
# Note: you will still need to install all the dependencies for xvfb to run
2
xvfb-run --server-args='-screen 0 1024x768x24' node src
Copied!
1
apt-get update && apt-get install -yq gconf-service libasound2 libatk1.0-0 libatk-bridge2.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget x11vnc x11-xkb-utils xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic x11-apps xvfb
2
apt-get update && apt-get install -y wget --no-install-recommends \
3
&& wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
4
&& sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
5
&& apt-get update \
6
&& apt-get install -y google-chrome-unstable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst ttf-freefont \
7
--no-install-recommends \
8
&& rm -rf /var/lib/apt/lists/* \
9
&& apt-get purge --auto-remove -y curl \
10
&& rm -rf /src/*.deb
Copied!
Loops
for.sh
while.sh
until.sh
1
# For loop using counter
2
for COUNTER in `seq 1 10`;
3
do
4
echo The counter is $COUNTER
5
done
6
7
# For loop using other values
8
for i in $( ls ); do
9
echo item: $i
10
done
Copied!
1
COUNTER=0
2
while [ $COUNTER -lt 10 ]; do
3
echo The counter is $COUNTER
4
let COUNTER=COUNTER+1
5
done
Copied!
1
COUNTER=20
2
until [ $COUNTER -lt 10 ]; do
3
echo COUNTER $COUNTER
4
let COUNTER-=1
5
done
Copied!
Last modified 4mo ago
Copy link