GithubHelp home page GithubHelp logo

paradite / bash-cheatsheet Goto Github PK

View Code? Open in Web Editor NEW
8.0 1.0 0.0 31 KB

:scroll: bash cheatsheet

Shell 11.48% CSS 16.28% JavaScript 72.24%
sed cloc cheatsheet bash terminal git cheat-sheet http-server osx-setup

bash-cheatsheet's Introduction

bash cheatsheet

Specific to OS X only

TOC

kill gpg-agent

$ killall gpg-agent
# or
$ gpgconf --kill gpg-agent

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"

nginx

# check current config and print config path
$ nginx -t

# update the config
$ open /usr/local/etc/nginx/

# run
$ nginx

# stop
$ nginx -s stop

# restart
$ nginx -s reload

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`

# count tsx or ts files, excluding *.test.ts and .test.tsx, sort by LOC
$ wc -l `find ./src -type f '(' -name "*.tsx" -or -name "*.ts" ')' -not '(' -name "*.test.ts" -or -name ".test.tsx" ')'` | sort -n

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

count example

Git

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 gfp="git fetch --prune"
alias gcz="git cz"
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'

Revert to remote origin master

$ git checkout origin/master filename

Sort files by git modified date

https://serverfault.com/questions/401437/how-to-retrieve-the-last-modification-date-of-all-files-in-a-git-repository#comment1118135_401450

$ git ls-tree -r --name-only HEAD | while read filename; do   echo "$(git log -1 --format="%ai" -- $filename) $filename"; done | sort

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 &

$ alias android="~/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/

$ alias ios="open /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app/"

List open ports

$ sudo lsof -iTCP -sTCP:LISTEN -n -P
$ sudo lsof -i -P -n | grep LISTEN

List tar/zip file contents

$ tar -tvf archive.tar

Remove node_modules

# check
$ find . -name "node_modules" -type d -prune | xargs du -chs

# remove
$ find . -name "node_modules" -type d -prune -exec rm -rf '{}' +

Remove .DS_Store

$ find . -name ".DS_Store" -delete

Spotlight indexing

# turn off
$ sudo mdutil -a -i off

# turn on
$ sudo mdutil -a -i on

virtualenv

$ virtualenv venv
$ source venv/bin/activate
$ deactivate

Other cheatsheets

License

MIT

bash-cheatsheet's People

Contributors

paradite avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.