GithubHelp home page GithubHelp logo

alexanderm33 / cheatsheet-shell-a4 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dennyzhang/cheatsheet-shell-a4

0.0 0.0 0.0 1.58 MB

:school: Examine your shell skills

Home Page: https://cheatsheet.dennyzhang.com/cheatsheet-shell-A4

Shell 100.00%

cheatsheet-shell-a4's Introduction

1 Shell CheatSheet

linkedin
github
slack


PRs Welcome

File me Issues or star this repo.

1.1 Basic

NameComment
Redirect stdout/stderrls /tmp >/dev/null 2>&1
Deal with filenamebasename $f, dirname $f
Use timeout: avoid command hangtimeout 10 sh -c ‘ls -lt’
Restart shell without killing terminalexec -l $SHELL
Run sub-shellecho $BASH_SUBSHELL; ( echo "Running in subshell: $BASH_SUBSHELL" )
Set pipefailset -ueoxv pipefail, set +ueoxv pipefail
Shell match regexp=echo $str, then grep “$regexp”=
Shell match regexpexpr match "$date" "^[0-9]\{8\}" >/dev/null && echo yes
Run static code checkLink: shellcheck
Show date in utcdate -u
Check file type of a given typefile /etc/hosts
Check command type of a commandtype echo

1.2 Shell script

NameComment
Trap exit signalcode/trap-exit.sh
Shell retrycode/shell-retry.sh
Check if a string contains a substringcode/string-contains.sh
Check if a string in a listcode/string-in-list.sh, Link: stackoverflow
Log with timestampcode/log-with-timestamp.sh
Quit if current user is not rootcode/assert-user-root.sh
Set -x on flycode/restore-debug-output.sh
Shell run curl checkcode/curl-test.sh

1.3 Environment variables

NameComment
List all environment variablesexport
Define a new env variableexport NAME1=”value1”
Define a variable with default value of othersexport MYVAR=”${MYVAR:-$OTHERVAR}”

1.4 iterm

NameComment
Delete a wordCtrl+w

1.5 zsh

NameComment
Disable all zsh’s autocorrectIn ~/.zshrc, unsetopt correct_all
Disable a given autocorrectIn ~/.zshrc, alias ssh=’nocorrect ssh’. zsh_disable

1.6 GNU tools

1.6.1 Echo string

NameComment
Echo red textecho -e “hello,\e[0;31m there \e[0;31m”
Echo multiple linesecho -e “hello,\ndenny”
Echo bold textecho -e hello, “\033[1mThis is bold text.\033[0m”
Echo underlined textecho -e hello, “\033[4mThis is underlined text.\033[0m”

1.7 Shell Basic

1.7.1 cd

NameComment
Go to given foldercd /var/log/
Go to folder in subshell(cd /var/log/ && ls) After this, PWD won’t be changed
Go to homecd
Go to parent foldercd ..
Go to previous foldercd -

1.7.2 Numeric

NameComment
*expr 5 \* 4
+let z=x+y, z=$x+$y
==int1 -eq int2, =[ $? -eq 0 ] && echo “good”=
>=int1 -ge =int2
>int1 -gt =int2
<=int1 -le =int2
<int1 -lt =int2
!=int1 -ne =int2

1.7.3 xargs

# Run grep for files filtered by find
find /var/log -name "*.log" | xargs grep -i error

# Loop with pipes
cat /etc/passwd | awk -F':' '{print $1}' | xargs -I{} sudo -l -U {} | grep -v "not allowed to"

1.8 Scripts

  • Compare command output
[ 0 -eq $(find ./data -name "*.txt" -type f -print | wc -l) ]
  • get ip from eth0
/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'

1.9 More Resources

License: Code is licensed under MIT License.

linkedin github slack

cheatsheet-shell-a4's People

Contributors

dennyzhang 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.