From 88723913818a5b56b5023b1f93c7e307e0e9eac8 Mon Sep 17 00:00:00 2001 From: Sean Esteva Date: Sat, 5 Aug 2017 00:19:09 -0700 Subject: [PATCH 01/12] added socks5 and a few extra tricks --- README.md | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 81 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 193e55a..c81e654 100644 --- a/README.md +++ b/README.md @@ -854,6 +854,44 @@ This command also accepts an option `-p` that can be used to connect to specific ```bash ssh -p port user@host ``` +For easy access: +```bash +nano ~/.ssh/config +``` +The config file is organized by hosts. Each host definition can define connection options for the specific matching host. Wildcards are also available to allow for options that should have a broader scope. + + +```bash +Host firsthost + SSH_OPTION_1 custom_value + SSH_OPTION_2 custom_value + SSH_OPTION_3 custom_value + +Host secondhost + ANOTHER_OPTION custom_value + +Host *host + ANOTHER_OPTION custom_value + +Host * + CHANGE_DEFAULT custom_value +``` +However, we could also use the full option names with the -o flag, like this: + +```bash +ssh -o "User=custom_value" -o "Port=custom_value" -o "HostName=custom_value" anything +``` +#### q1. `SOCKS5` +```bash +ssh -D port -f -C -q -N user@host +``` +#### Explanation of arguments: +- -D: Tells SSH that we want a SOCKS tunnel on the specified port number (you can choose a number between 1025-65536) +- -f: Forks the process to the background +- -C: Compresses the data before sending it +- -q: Uses quiet mode +- -N: Tells SSH that no command will be sent once the tunnel is up + ### r. `top` Displays your currently active processes. @@ -1079,8 +1117,7 @@ file1 -ot file2 # file1 is older than file2 -ne # not equal ``` -## 2.6. Loops - +## 2.6. Loop There are three types of loops in bash. `for`, `while` and `until`. Different `for` Syntax: @@ -1142,6 +1179,41 @@ function finish { trap finish EXIT ``` +## Extract +Make your life easier. +```bash +function extract() # Handy Extract Program +{ + if [ -f $1 ] ; then + case $1 in + *.tar.bz2) tar xvjf $1 ;; + *.tar.gz) tar xvzf $1 ;; + *.bz2) bunzip2 $1 ;; + *.rar) unrar x $1 ;; + *.gz) gunzip $1 ;; + *.tar) tar xvf $1 ;; + *.tbz2) tar xvjf $1 ;; + *.tgz) tar xvzf $1 ;; + *.zip) unzip $1 ;; + *.Z) uncompress $1 ;; + *.7z) 7z x $1 ;; + *) echo "'$1' cannot be extracted via >extract<" ;; + esac + else + echo "'$1' is not a valid file!" + fi +} +``` +## Exit +```bash +function _exit() # Function to run upon exit of shell. +{ + echo -e "${BRed}Hasta la vista, cabron ${NC}" +} +trap _exit EXIT + +``` + ## Saving your environment variables When you do `export FOO = BAR`, your variable is only exported in this current shell and all its children, to persist in the future you can simply append in your `~/.bash_profile` file the command to export your variable @@ -1160,6 +1232,13 @@ If you can not access, try append the code below in your `~/.bash_profile` file PATH="$HOME/bin:$PATH" fi ``` +## Aliases +Put this in your ~/.bashrc file to include all your aliases in a neatly organized file: +```bash +if [ -f ~/.bash_aliases ]; then + source ~/.bash_aliases +fi +``` # 4. Debugging You can easily debug the bash script by passing different options to `bash` command. For example `-n` will not run commands and check for syntax errors only. `-v` echo commands before running them. `-x` echo commands after command-line processing. From 61edd74d82c13536deefb20a9836cc9dd256bfe6 Mon Sep 17 00:00:00 2001 From: Sean Esteva Date: Sat, 5 Aug 2017 00:30:54 -0700 Subject: [PATCH 02/12] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c81e654..f988d51 100644 --- a/README.md +++ b/README.md @@ -1117,7 +1117,7 @@ file1 -ot file2 # file1 is older than file2 -ne # not equal ``` -## 2.6. Loop +## 2.6. Loops There are three types of loops in bash. `for`, `while` and `until`. Different `for` Syntax: From de77a6f9e0e18716384f3852c432aaf5ba1f8de7 Mon Sep 17 00:00:00 2001 From: Ethan Date: Thu, 5 Oct 2017 01:44:46 -0500 Subject: [PATCH 03/12] add chinese translation reference (#64) --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 193e55a..c3ce202 100644 --- a/README.md +++ b/README.md @@ -1177,6 +1177,7 @@ bash -x scriptname - Spread the word ## Translation +- [Chinese | 简体中文](https://github.com/vuuihc/bash-guide) - [Turkish | Türkçe](https://github.com/omergulen/bash-guide) - [Japanese | 日本語](https://github.com/itooww/bash-guide) From b2e947fbc74e3f3a722bcbaf27e3d671aac2b59d Mon Sep 17 00:00:00 2001 From: Umer Salman Date: Sun, 19 Nov 2017 12:32:35 -0600 Subject: [PATCH 04/12] Add some more info on ps (#65) Also fixed a formatting typo. --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c3ce202..46d3b55 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ 1.5. [Process Monitoring Operations](#15-process-monitoring-operations) 2. [Basic Shell Programming](#2-basic-shell-programming) 2.1. [Variables](#21-variables) - 2.2 [Array](#22-array) + 2.2. [Array](#22-array) 2.3. [String Substitution](#23-string-substitution) 2.4. [Functions](#24-functions) 2.5. [Conditionals](#25-conditionals) @@ -821,6 +821,10 @@ Lists your processes. ```bash ps -u yourusername ``` +Use the flags ef. e for every process and f for full listing. +```bash +ps -ef +``` ### o. `quota` Shows what your disk quota is. From 9fa69633349ca0634c95a475e4d267310c62458f Mon Sep 17 00:00:00 2001 From: Evan Hahn Date: Sun, 19 Nov 2017 12:32:54 -0600 Subject: [PATCH 05/12] Remove gendered language (#63) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 46d3b55..0d5f121 100644 --- a/README.md +++ b/README.md @@ -808,7 +808,7 @@ man command ``` ### l. `passwd` -Allows the current logged user to change his password. +Allows the current logged user to change their password. ### m. `ping` Pings host and outputs results. From 017a050473a7a24f3d362b7e92cb8c5a769e43b1 Mon Sep 17 00:00:00 2001 From: Thomas Negash Date: Sun, 19 Nov 2017 21:34:39 +0300 Subject: [PATCH 06/12] Fixes #50 (#57) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0d5f121..78422b9 100644 --- a/README.md +++ b/README.md @@ -1028,7 +1028,7 @@ When you run the above example the `hello` function will output "world!". The ab The conditional statement in bash is similar to other programming languages. Conditions have many form like the most basic form is `if` expression `then` statement where statement is only executed if expression is true. ```bash -if [expression]; then +if [ expression ]; then will execute only if expression is true else will execute if expression is false From 659b9b2d51b80922c7d3e6ad956da298da43f5ad Mon Sep 17 00:00:00 2001 From: Gibran Malheiros Date: Wed, 3 Jan 2018 16:21:51 +0100 Subject: [PATCH 07/12] updated shebang to use env (#67) https://unix.stackexchange.com/questions/29608/why-is-it-better-to-use-usr-bin-env-name-instead-of-path-to-name-as-my --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 78422b9..7f5f26a 100644 --- a/README.md +++ b/README.md @@ -934,7 +934,7 @@ nohup command & The first line that you will write in bash script files is called `shebang`. This line in any script determines the script's ability to be executed like a standalone executable without typing sh, bash, python, php etc beforehand in the terminal. ```bash -#!/bin/bash +#!/usr/bin/env bash ``` ## 2.1. Variables From 71f73bef5bc38e476bb73de9f1352719405e4ace Mon Sep 17 00:00:00 2001 From: Ethan Date: Thu, 5 Oct 2017 01:44:46 -0500 Subject: [PATCH 08/12] add chinese translation reference (#64) --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index f988d51..4113148 100644 --- a/README.md +++ b/README.md @@ -1256,6 +1256,7 @@ bash -x scriptname - Spread the word ## Translation +- [Chinese | 简体中文](https://github.com/vuuihc/bash-guide) - [Turkish | Türkçe](https://github.com/omergulen/bash-guide) - [Japanese | 日本語](https://github.com/itooww/bash-guide) From 7be34c38ad74316c2f2ee0a032232b3fe52961b6 Mon Sep 17 00:00:00 2001 From: Umer Salman Date: Sun, 19 Nov 2017 12:32:35 -0600 Subject: [PATCH 09/12] Add some more info on ps (#65) Also fixed a formatting typo. --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4113148..ffc51b8 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ 1.5. [Process Monitoring Operations](#15-process-monitoring-operations) 2. [Basic Shell Programming](#2-basic-shell-programming) 2.1. [Variables](#21-variables) - 2.2 [Array](#22-array) + 2.2. [Array](#22-array) 2.3. [String Substitution](#23-string-substitution) 2.4. [Functions](#24-functions) 2.5. [Conditionals](#25-conditionals) @@ -821,6 +821,10 @@ Lists your processes. ```bash ps -u yourusername ``` +Use the flags ef. e for every process and f for full listing. +```bash +ps -ef +``` ### o. `quota` Shows what your disk quota is. From 2dcf1d254e06f2bc2aa6bf516f828fff3b8fbff1 Mon Sep 17 00:00:00 2001 From: Evan Hahn Date: Sun, 19 Nov 2017 12:32:54 -0600 Subject: [PATCH 10/12] Remove gendered language (#63) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ffc51b8..84488d4 100644 --- a/README.md +++ b/README.md @@ -808,7 +808,7 @@ man command ``` ### l. `passwd` -Allows the current logged user to change his password. +Allows the current logged user to change their password. ### m. `ping` Pings host and outputs results. From d1182ba6cec8fde3def06cc376e77a89953cb2b2 Mon Sep 17 00:00:00 2001 From: Thomas Negash Date: Sun, 19 Nov 2017 21:34:39 +0300 Subject: [PATCH 11/12] Fixes #50 (#57) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 84488d4..642f074 100644 --- a/README.md +++ b/README.md @@ -1066,7 +1066,7 @@ When you run the above example the `hello` function will output "world!". The ab The conditional statement in bash is similar to other programming languages. Conditions have many form like the most basic form is `if` expression `then` statement where statement is only executed if expression is true. ```bash -if [expression]; then +if [ expression ]; then will execute only if expression is true else will execute if expression is false From a5f22dda6b8ab7b114ef37881428c15171f5f492 Mon Sep 17 00:00:00 2001 From: Gibran Malheiros Date: Wed, 3 Jan 2018 16:21:51 +0100 Subject: [PATCH 12/12] updated shebang to use env (#67) https://unix.stackexchange.com/questions/29608/why-is-it-better-to-use-usr-bin-env-name-instead-of-path-to-name-as-my --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 642f074..8de8ee3 100644 --- a/README.md +++ b/README.md @@ -972,7 +972,7 @@ nohup command & The first line that you will write in bash script files is called `shebang`. This line in any script determines the script's ability to be executed like a standalone executable without typing sh, bash, python, php etc beforehand in the terminal. ```bash -#!/bin/bash +#!/usr/bin/env bash ``` ## 2.1. Variables