⭐️ Hit the star button, make me happy!
👀 Visit my other projects https://github.com/IGPenguin
- What is it?
- Basic bash syntax
- Useful terminal commands
- Oneliners
- Code snippets
- Git
- Terminal shortcuts
command1; command2; command3;
- execute command regardless of success of the previous command
command1 && command2
- execute command2 if command1 executed successfully (exit code 0)
command1 || command2
- execute command2 if command1 execution failed (exit code != 0)
command1 &
- execute command as a background task
wait
- wait until triggered background tasks are done
if [ "$var" -eq 1 ]
Always use spaces between brackets and the condition
Always quote a tested variable
-eq - equal to if [ "$a" -eq "$b" ]
-ne - not equal to if [ "$a" -ne "$b" ]
-gt - greater than if [ "$a" -gt "$b" ]
-ge - greater than or equal to if [ "$a" -ge "$b" ]
-lt - less than if [ "$a" -lt "$b" ]
-le - less than or equal to if [ "$a" -le "$b" ]
<, <=, >, >= - within double parentheses (("$a" < "$b"))
-n - string is not null if [ -n "$string" ]
-z - string is null, that is, has zero length if [ -z "$string" ]
= or == - equal to, if [ "$a" = "$b" ]
!= - not equal to, if [ "$a" != "$b" ]
The == comparison operator behaves differently within a double-brackets test than within single brackets
[[ $a == z* ]]
- true if $a starts with an "z" (pattern matching)
[[ $a == "z*" ]]
or [ "$a" == "z*" ]
- true if $a is equal to z* (literal matching)
[ $a == z* ]
- file globbing and word splitting take place
< - less than, in ASCII alphabetical order, if [[ "$a" < "$b" ]], if [ "$a" < "$b" ]
> - greater than, in ASCII alphabetical order, if [[ "$a" > "$b" ]], if [ "$a" > "$b" ]
man <command>
- show command manual, exit with q
curl -o <filename> -k <url>
- download file from url
grep <text>
- find lines containing <text>
grep ^<text>
- find <text> at the start of a line
grep <text>$
- find <text> at the end of a line
grep <text>.
- find line with <text> and exactly one character immediately after it
grep <text>.?
- find line with <text> and one optional character immediately after it
grep <text>Z+
- find line with <text> and one or more Z characters immediately after it
grep <text>*
- find line with <text> and any number of characters immediately after it
sort -u
- strip duplicate lines
echo "some.string.with.dots" | tr . _
- replace dots with underscores
cat <some-file> | awk '{print $2}'
- get second word from each line
file image_file.jpg
- file information including image resolution etc
curl -L https://raw.githubusercontent.com/dummyuser/great-repo/master/install.sh | bash
[ $(id -u) -eq 0 ] && return $TRUE || return $FALSE
[ "$VAR" =~ ^[0-9]+$ ]
foo=${string#"$prefix"}
foo=${foo%"$suffix"}
echo <tbd> | column
<cmd> | at <time>
- run command at scheduled time
echo "<some-text-with-newline>" | tr -d '\r'
Output color codes
tput setaf 1; echo WARNING MESSAGE; tput sgr0;
Code conflict resolution command line manual
git reset --soft
- cancel commits, keep changes
git branch -m new-name
- rename local branch
git branch -d <branch_name> - delete local branch
git commit --amend
- add to previous commit
git remote prune origin
- remove merged branches