The Wayback Machine - https://web.archive.org/web/20200909043110/https://github.com/paradite/bash-cheatsheet/
Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 

README.md

bash cheatsheet

Specific to OS X only

make shell scripts executable

$ chmod +x script.sh

static http server

# python2
$ python -m SimpleHTTPServer 8000

# python3
$ python3 -m http.server

# alias
alias http="python -m SimpleHTTPServer 8000"

modify files using sed

# substitute and print to stdout
$ sed -e 's/one/first/g' test-file.txt

# substitute in place with backup
$ sed -i '.backup' -e 's/one/first/g' test-file.txt

# substitute in place without backup
$ sed -i '' -e 's/another/next/g' test-file.txt

sed example

count lines of code for each individual file

# count lines of code for jsx files in current folder
$ wc -l `find . -type f -name "*.jsx" | sort -n`

# count lines of code for jsx and css files in current folder
$ wc -l `find . -type f -name "*.jsx" -or -name "*.css" | sort -n`

# count lines of code for tsx files in src folder
$ wc -l `find ./src -type f -name "*.tsx" | sort -n`

# alias
alias wct=$'wc -l `find ./src -type f -name "*.tsx" | sort -n`'

count example

remove old merged git branches that are no longer in remote

# prune remote-tracking branches no longer on remote
git fetch --prune

# print local branches that are not found on remote
git branch -r | awk '{print $1}' | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk '{print $1}'

# remove local branches that are not found on remote
git branch -r | awk '{print $1}' | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk '{print $1}' | xargs git branch -d

#alias
alias gp="git fetch --prune"
alias grm=$'git branch -r | awk \'{print $1}\' | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk \'{print $1}\' | xargs git branch -d'

git revert to remote origin master

git checkout origin/master filename

Android emulator

https://stackoverflow.com/a/48729278/1472186

# list devices with identifiers
$ ~/Library/Android/sdk/emulator/emulator -list-avds

# run in background
$ ~/Library/Android/sdk/emulator/emulator -avd Pixel_2_API_28 &

iOS Simulator

# list devices with identifiers
$ instruments -s devices

# start Simulator
$ open /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app/

List open ports

$ sudo lsof -iTCP -sTCP:LISTEN -n -P

List tar/zip file contents

$ tar -tvf archive.tar

Other cheatsheets

License

MIT

About

📜 bash cheatsheet

Topics

Resources

Releases

No releases published

Packages

No packages published
You can’t perform that action at this time.