Skip to content
Jess edited this page Aug 10, 2019 · 1 revision

Bash Shell

THE FASTEST way to use your computer xD

rm -rf path/to/delete # forcibly remove, including contents
touch logs.txt # generate a file 
./your-script.sh > logs.txt # save output to logs.txt, not prompt
chmod u+x your-script.sh && ./your-script.sh # permiss and run a shell script
which <package> # find path of package or application, like 'which gdal'
yes | bash your-script.sh # auto yes
tar xzf file.tar.gz # unzip tar.gz
zip -r file.zip file # unzip an archive
Rscript file.R # execute R file from bash, no console

Common utilities:

# git 
git clone https://github.com/psu-hacking/home-wiki # clone from online repo
git add . && git commit # write a commit note, staged and ready to go
git push # send- for "origin remote" @ github this is all you need\

# network
wget https://raw.githubusercontent.com/psu-hacking/home-wiki/master/README.md # get some file from the internet
netstat # view active network/socket/udp/tcp/connection info
ping 8.8.8.8 # check internet connection- ping Google's DNS

# ssh and sftp
ssh user@yoursite.net 
sftp user@yoursite.net 

# AWS ssh specific:
### with key-gen key pair:
chmod 400 /path/to/keypair.pem # set permissions for key 
ssh -i /path/to/keypair.pem ec2-user@ec2-123-45-6-7.compute-1.amazonaws.com 

# GCP ssh specific:
### get gcloud CLI
echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] http://packages.cloud.google.com/apt cloud-sdk main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key --keyring /usr/share/keyrings/cloud.google.gpg add -
sudo apt-get update && sudo apt-get install google-cloud-sdk
### config GCP
gcloud auth # global auth via browser
gcloud config set project your-project # global project
gcloud compute ssh --zone your-zone your-instance # connect to vm instance, example vals: ("us-central1-a my-instance")
gcloud app deploy # submit to app engine (not vm)
gcloud app browse # open global project's app in browser

Package managers:

# apt and apt-get on Debian/Ubuntu
sudo apt-get update && sudo apt-get upgrade # 
apt autoremove # clean up depends!

#get homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
# common brew things:
brew install wget gdal qgis # multiple packages
brew list # see brews

Command Prompt: (Windows)

Virtualbox on Windows host example- resize VDI partition:

cd "c:\Program Files\Oracle\VirtualBox"
VBoxManage.exe modifyhd "C:\Users\YOURUSER\VirtualBox VMs\Path\To\Your.vdi" --resize 128000

Bash in RHEL- package manager example

sudo yum install --nogpgcheck shiny-server-1.5.7.907-rh6-x86_64.rpm

Eval disk speed (Debian/Ubuntu):

dd if=/dev/zero of=test bs=1048576 count=1024 && /sbin/sysctl -w vm.drop_caches=1 && dd if=test of=/dev/null bs=1048576 && rm test