From b0dd45c5e2b57544087791ef5f7f6cab7ae7be75 Mon Sep 17 00:00:00 2001 From: Alexey Pyltsyn Date: Tue, 4 Apr 2017 06:06:11 +0300 Subject: [PATCH 01/50] Minor changes (#12) --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index cd8e321..efeae4e 100644 --- a/README.md +++ b/README.md @@ -15,8 +15,8 @@ 2.4. [Functions](#23-functions) 2.5. [Conditionals](#24-conditionals) 2.6. [Loops](#25-loops) - 3. [Tricks](#4-tricks) - 4. [Debugging](#5-debugging) + 3. [Tricks](#3-tricks) + 4. [Debugging](#4-debugging) # 1. Basic Operations @@ -1036,11 +1036,11 @@ done # 3. Tricks -## set an alias +## Set an alias Open `bash_profile` by running following command `nano ~/.bash_profile` > alias dockerlogin='ssh www-data@adnan.local -p2222' # add your alias in .bash_profile -## to quickly go to a specific directory +## To quickly go to a specific directory nano ~/.bashrc > export hotellogs="/workspace/hotel-api/storage/logs" From 5127d4e5c9f7c75856986ab481643d6a3ced932d Mon Sep 17 00:00:00 2001 From: Paulo Henrique Date: Mon, 3 Apr 2017 23:19:29 -0400 Subject: [PATCH 02/50] Update README.md (#10) Add file command. --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index efeae4e..a3b784a 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,7 @@ Clears content on window. lpr lpq lprm + file @@ -225,6 +226,17 @@ Remove something from the printer queue. lprm jobnumber ``` +### r. `file` +Determine file type. +```bash +file filename +``` +Example: +```bash +$ file index.html + index.html: HTML document, ASCII text +``` + ## 1.2. Text Operations From 50097044da79fa22afdabceaf2aa824a58066f06 Mon Sep 17 00:00:00 2001 From: Shahid Ahmad Date: Tue, 4 Apr 2017 17:05:16 +0500 Subject: [PATCH 03/50] fix function spelling mistake issue #15 (#16) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a3b784a..5a7d7b9 100644 --- a/README.md +++ b/README.md @@ -948,7 +948,7 @@ function say { say "hello world!" ``` -When you run the above example the `hello` function will output "world!". The above two functions `hello` and `say` are identical. The main difference is function `say`. This function, prints the first argument it receives. Arguments, within funtions, are treated in the same manner as arguments given to the script. +When you run the above example the `hello` function will output "world!". The above two functions `hello` and `say` are identical. The main difference is function `say`. This function, prints the first argument it receives. Arguments, within functions, are treated in the same manner as arguments given to the script. ## 2.4. Conditionals From 56e9c9c74b981332353bce1a26a2958686357956 Mon Sep 17 00:00:00 2001 From: Chandan Rai Date: Tue, 4 Apr 2017 23:03:58 +0530 Subject: [PATCH 04/50] corrected typos (#18) --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 5a7d7b9..9622c1e 100644 --- a/README.md +++ b/README.md @@ -723,7 +723,7 @@ ssh (SSH client) is a program for logging into and executing commands on a remot ```bash ssh user@host ``` -This command also accepts an option `-p` that can to used to connect to specific port. +This command also accepts an option `-p` that can be used to connect to specific port. ```bash ssh -p port user@host ``` @@ -807,7 +807,7 @@ killall processname Displays your currently active processes. ### s. `bg` -Lists stopped or background jobs ; resume a stopped job in the background. +Lists stopped or background jobs; resume a stopped job in the background. ### t. `fg` Brings the most recent job in the foreground. @@ -849,7 +849,7 @@ scp source_file user@host:directory/target_file scp user@host:directory/source_file target_file scp -r user@host:directory/source_folder farget_folder ``` -This command also accepts an option `-P` that can to used to connect to specific port. +This command also accepts an option `-P` that can be used to connect to specific port. ```bash scp -P port user@host:directory/source_file target_file ``` @@ -858,7 +858,7 @@ scp -P port user@host:directory/source_file target_file # 2. Basic Shell Programming -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 an standalone executable without typing sh, bash, python, php etc beforehand in the terminal. +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 From c67218ec186127e20efadc6a27e83c43a81c491b Mon Sep 17 00:00:00 2001 From: Ashish Kumar Badtiya Date: Tue, 4 Apr 2017 23:14:21 +0530 Subject: [PATCH 05/50] Removed -f option for rm command (#14) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9622c1e..8c7a42c 100644 --- a/README.md +++ b/README.md @@ -166,7 +166,7 @@ Where `filename1` is the source path to the file and `filename2` is the destinat ### i. `rm` Removes a file. Using this command on a directory gives you an error. `rm: directory: is a directory` -In order to remove a directory you have to pass `-rf` to remove all the content of the directory recursively. +In order to remove a directory you have to pass `-r` to remove all the content of the directory recursively. ```bash rm filename ``` From 42d692737a29d8a54bc854118ff31a4d8c629e75 Mon Sep 17 00:00:00 2001 From: Adnan Ahmed Date: Tue, 4 Apr 2017 22:01:23 +0400 Subject: [PATCH 06/50] Add detail for `-f` option in `rm` command #14 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8c7a42c..c821929 100644 --- a/README.md +++ b/README.md @@ -166,7 +166,7 @@ Where `filename1` is the source path to the file and `filename2` is the destinat ### i. `rm` Removes a file. Using this command on a directory gives you an error. `rm: directory: is a directory` -In order to remove a directory you have to pass `-r` to remove all the content of the directory recursively. +To remove a directory you have to pass `-r` which will remove the content of the directory recursively. Optionally you can use `-f` flag to force the deletion i.e. without any confirmations etc. ```bash rm filename ``` From aadad11e00484949381d99fe78c3214366f185bd Mon Sep 17 00:00:00 2001 From: Adnan Ahmed Date: Tue, 4 Apr 2017 22:51:26 +0400 Subject: [PATCH 07/50] alphabetical order in command list #11 --- README.md | 911 +++++++++++++++++++++++++++--------------------------- 1 file changed, 454 insertions(+), 457 deletions(-) diff --git a/README.md b/README.md index c821929..d4bcb8a 100644 --- a/README.md +++ b/README.md @@ -67,58 +67,30 @@ Clears content on window. ## 1.1. File Operations
- - - - - - - - - - + + + + + + + + + + - - - - - - - - + + + + + + + +
lstouchcatmoreheadtailmvcprmdiffcatchmodcpdifffilegunzipgzcatgzipheadlpq
chmodgzipgunzipgzcatlprlpqlprmfilelprlprmlsmoremvrmtailtouch
-### a. `ls` -Lists your files. `ls` has many options: `-l` lists files in 'long format', which contains the exact size of the file, who owns the file, who has the right to look at it, and when it was last modified. `-a` lists all files, including hidden files. For more information on this command check this [link](https://ss64.com/bash/ls.html). -```bash -ls option -``` -Example: -
-$ ls -al
-rwxr-xr-x   33 adnan  staff    1122 Mar 27 18:44 .
-drwxrwxrwx  60 adnan  staff    2040 Mar 21 15:06 ..
--rw-r--r--@  1 adnan  staff   14340 Mar 23 15:05 .DS_Store
--rw-r--r--   1 adnan  staff     157 Mar 25 18:08 .bumpversion.cfg
--rw-r--r--   1 adnan  staff    6515 Mar 25 18:08 .config.ini
--rw-r--r--   1 adnan  staff    5805 Mar 27 18:44 .config.override.ini
-drwxr-xr-x  17 adnan  staff     578 Mar 27 23:36 .git
--rwxr-xr-x   1 adnan  staff    2702 Mar 25 18:08 .gitignore
-
- -### b. `touch` -Creates or updates your file. -```bash -touch filename -``` -Example: -```bash -$ touch trick.md -``` - -### c. `cat` +### a. `cat` It can be used for the following purposes under UNIX or Linux. * Display text files on screen * Copy text files @@ -130,84 +102,61 @@ cat file1 file2 cat file1 file2 > newcombinedfile ``` -### d. `more` -Shows the first part of a file (move with space and type q to quit). -```bash -more filename -``` - -### e. `head` -Outputs the first 10 lines of file -```bash -head filename -``` - -### f. `tail` -Outputs the last 10 lines of file. Use `-f` to output appended data as the file grows. -```bash -tail filename -``` - - -### g. `mv` -Moves a file from one location to other. +### b. `chmod` +Lets you change the read, write, and execute permissions on your files. ```bash -mv filename1 filename2 +chmod -options filename ``` -Where `filename1` is the source path to the file and `filename2` is the destination path to the file. -### h. `cp` +### c. `cp` Copies a file from one location to other. ```bash cp filename1 filename2 ``` Where `filename1` is the source path to the file and `filename2` is the destination path to the file. -### i. `rm` -Removes a file. Using this command on a directory gives you an error. -`rm: directory: is a directory` -To remove a directory you have to pass `-r` which will remove the content of the directory recursively. Optionally you can use `-f` flag to force the deletion i.e. without any confirmations etc. -```bash -rm filename -``` - -### j. `diff` +### d. `diff` Compares files, and lists their differences. ```bash diff filename1 filename2 ``` -### k. `chmod` -Lets you change the read, write, and execute permissions on your files. +### e. `file` +Determine file type. ```bash -chmod -options filename +file filename ``` - -### l. `gzip` -Compresses files. +Example: ```bash -gzip filename +$ file index.html + index.html: HTML document, ASCII text ``` -### m. `gunzip` +### f. `gunzip` Un-compresses files compressed by gzip. ```bash gunzip filename ``` -### n. `gzcat` +### g. `gzcat` Lets you look at gzipped file without actually having to gunzip it. ```bash gzcat filename ``` -### o. `lpr` -Print the file. +### h. `gzip` +Compresses files. ```bash -lpr filename +gzip filename ``` -### p. `lpq` +### i. `head` +Outputs the first 10 lines of file +```bash +head filename +``` + +### j. `lpq` Check out the printer queue. ```bash lpq @@ -220,42 +169,92 @@ active adnanad 59 demo 399360 bytes 1st adnanad 60 (stdin) 0 bytes ``` -### q. `lprm` +### k. `lpr` +Print the file. +```bash +lpr filename +``` + +### l. `lprm` Remove something from the printer queue. ```bash lprm jobnumber ``` -### r. `file` -Determine file type. +### m. `ls` +Lists your files. `ls` has many options: `-l` lists files in 'long format', which contains the exact size of the file, who owns the file, who has the right to look at it, and when it was last modified. `-a` lists all files, including hidden files. For more information on this command check this [link](https://ss64.com/bash/ls.html). ```bash -file filename +ls option ``` Example: +
+$ ls -al
+rwxr-xr-x   33 adnan  staff    1122 Mar 27 18:44 .
+drwxrwxrwx  60 adnan  staff    2040 Mar 21 15:06 ..
+-rw-r--r--@  1 adnan  staff   14340 Mar 23 15:05 .DS_Store
+-rw-r--r--   1 adnan  staff     157 Mar 25 18:08 .bumpversion.cfg
+-rw-r--r--   1 adnan  staff    6515 Mar 25 18:08 .config.ini
+-rw-r--r--   1 adnan  staff    5805 Mar 27 18:44 .config.override.ini
+drwxr-xr-x  17 adnan  staff     578 Mar 27 23:36 .git
+-rwxr-xr-x   1 adnan  staff    2702 Mar 25 18:08 .gitignore
+
+ +### n. `more` +Shows the first part of a file (move with space and type q to quit). ```bash -$ file index.html - index.html: HTML document, ASCII text +more filename +``` + +### o. `mv` +Moves a file from one location to other. +```bash +mv filename1 filename2 +``` +Where `filename1` is the source path to the file and `filename2` is the destination path to the file. + +### p. `rm` +Removes a file. Using this command on a directory gives you an error. +`rm: directory: is a directory` +To remove a directory you have to pass `-r` which will remove the content of the directory recursively. Optionally you can use `-f` flag to force the deletion i.e. without any confirmations etc. +```bash +rm filename +``` + +### q. `tail` +Outputs the last 10 lines of file. Use `-f` to output appended data as the file grows. +```bash +tail filename +``` + +### r. `touch` +Creates or updates your file. +```bash +touch filename +``` +Example: +```bash +$ touch trick.md ``` ## 1.2. Text Operations - + - - - - - - - - + + + + + + + + + - - - - + + +
awkgrepwcsedsortuniqcutechofmtcutechoegrepfgrepfmtgrepnlsedsort
trnlegrepfgreptruniqwc
@@ -288,7 +287,156 @@ sync ``` For more detail on how to use `awk`, check following [link](https://www.cyberciti.biz/faq/bash-scripting-using-awk). -### b. `grep` + +### b. `cut` +Remove sections from each line of files + +*example.txt* +```bash +red riding hood went to the park to play +``` + +*show me columns 2 , 7 , and 9 with a space as a separator* +```bash +cut -d " " -f2,7,9 example.txt +``` +```bash +riding park play +``` + +### c. `echo` +Display a line of text + +*display "Hello World"* +```bash +echo Hello World +``` +```bash +Hello World +``` + +*display "Hello World" with newlines between words* +```bash +echo -ne "Hello\nWorld\n" +``` +```bash +Hello +World +``` + +### d. `egrep` +Print lines matching a pattern - Extended Expression (alias for: 'grep -E') + +*example.txt* +```bash +Lorem ipsum +dolor sit amet, +consetetur +sadipscing elitr, +sed diam nonumy +eirmod tempor +invidunt ut labore +et dolore magna +aliquyam erat, sed +diam voluptua. At +vero eos et +accusam et justo +duo dolores et ea +rebum. Stet clita +kasd gubergren, +no sea takimata +sanctus est Lorem +ipsum dolor sit +amet. +``` + +*display lines that have either "Lorem" or "dolor" in them.* +```bash +egrep '(Lorem|dolor)' example.txt +or +grep -E '(Lorem|dolor)' example.txt +``` +```bash +Lorem ipsum +dolor sit amet, +et dolore magna +duo dolores et ea +sanctus est Lorem +ipsum dolor sit +``` + +### e. `fgrep` +Print lines matching a pattern - FIXED pattern matching (alias for: 'grep -F') + +*example.txt* +```bash +Lorem ipsum +dolor sit amet, +consetetur +sadipscing elitr, +sed diam nonumy +eirmod tempor +foo (Lorem|dolor) +invidunt ut labore +et dolore magna +aliquyam erat, sed +diam voluptua. At +vero eos et +accusam et justo +duo dolores et ea +rebum. Stet clita +kasd gubergren, +no sea takimata +sanctus est Lorem +ipsum dolor sit +amet. +``` + +*Find the exact string '(Lorem|doloar)' in example.txt* +```bash +fgrep '(Lorem|dolor)' example.txt +or +grep -F '(Lorem|dolor)' example.txt +``` +```bash +foo (Lorem|dolor) +``` + +### f. `fmt` +Simple optimal text formatter + +*example: example.txt (1 line)* +```bash +Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. +``` + +*output the lines of example.txt to 20 character width* +```bash +cat example.txt | fmt -w 20 +``` +```bash +Lorem ipsum +dolor sit amet, +consetetur +sadipscing elitr, +sed diam nonumy +eirmod tempor +invidunt ut labore +et dolore magna +aliquyam erat, sed +diam voluptua. At +vero eos et +accusam et justo +duo dolores et ea +rebum. Stet clita +kasd gubergren, +no sea takimata +sanctus est Lorem +ipsum dolor sit +amet. +``` + +### g. `grep` Looks for text inside files. You can use grep to search for lines of text that match one or many regular expressions, and outputs only the matching lines. ```bash grep pattern filename @@ -306,19 +454,59 @@ $ grep -r admin /etc/ ``` And `-w` to search for words only. For more detail on `grep`, check following [link](https://www.cyberciti.biz/faq/grep-in-bash). -### c. `wc` -Tells you how many lines, words and characters there are in a file. +### h. `nl` +Number lines of files + +*example.txt* ```bash -wc filename +Lorem ipsum +dolor sit amet, +consetetur +sadipscing elitr, +sed diam nonumy +eirmod tempor +invidunt ut labore +et dolore magna +aliquyam erat, sed +diam voluptua. At +vero eos et +accusam et justo +duo dolores et ea +rebum. Stet clita +kasd gubergren, +no sea takimata +sanctus est Lorem +ipsum dolor sit +amet. ``` -Example: + +*show example.txt with line numbers* ```bash -$ wc demo.txt -7459 15915 398400 demo.txt +nl -s". " example.txt +``` +```bash + 1. Lorem ipsum + 2. dolor sit amet, + 3. consetetur + 4. sadipscing elitr, + 5. sed diam nonumy + 6. eirmod tempor + 7. invidunt ut labore + 8. et dolore magna + 9. aliquyam erat, sed + 10. diam voluptua. At + 11. vero eos et + 12. accusam et justo + 13. duo dolores et ea + 14. rebum. Stet clita + 15. kasd gubergren, + 16. no sea takimata + 17. sanctus est Lorem + 18. ipsum dolor sit + 19. amet. ``` -Where `7459` is lines, `15915` is words and `398400` is characters. -### d. `sed` +### i. `sed` Stream editor for filtering and transforming text *example.txt* @@ -342,7 +530,7 @@ sed 's/[0-9]/d/g' example.txt Hello This is a Test d d d d ``` -### e. `sort` +### j. `sort` Sort lines of text files *example.txt* @@ -356,7 +544,6 @@ e d ``` - *sort example.txt* ```bash sort example.txt @@ -379,120 +566,13 @@ sort example.txt | sort -R b f a -c -d -g -e -``` - -### f. `uniq` -Report or omit repeated lines - -*example.txt* -```bash -a -a -b -a -b -c -d -c -``` - -*show only unique lines of example.txt (first you need to sort it, otherwise it won't see the overlap)* -```bash -sort example.txt | uniq -``` -```bash -a -b -c -d -``` - -*show the unique items for each line, and tell me how many instances it found* -```bash -sort example.txt | uniq -c -``` -```bash - 3 a - 2 b - 2 c - 1 d -``` - -### g. `cut` -Remove sections from each line of files - -*example.txt* -```bash -red riding hood went to the park to play -``` - -*show me columns 2 , 7 , and 9 with a space as a separator* -```bash -cut -d " " -f2,7,9 example.txt -``` -```bash -riding park play -``` - -### h. `echo` -Display a line of text - -*display "Hello World"* -```bash -echo Hello World -``` -```bash -Hello World -``` - -*display "Hello World" with newlines between words* -```bash -echo -ne "Hello\nWorld\n" -``` -```bash -Hello -World -``` - -### i. `fmt` -Simple optimal text formatter - -*example: example.txt (1 line)* -```bash -Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. -``` - -*output the lines of example.txt to 20 character width* -```bash -cat example.txt | fmt -w 20 -``` -```bash -Lorem ipsum -dolor sit amet, -consetetur -sadipscing elitr, -sed diam nonumy -eirmod tempor -invidunt ut labore -et dolore magna -aliquyam erat, sed -diam voluptua. At -vero eos et -accusam et justo -duo dolores et ea -rebum. Stet clita -kasd gubergren, -no sea takimata -sanctus est Lorem -ipsum dolor sit -amet. +c +d +g +e ``` -### j. `tr` +### k. `tr` Translate or delete characters *example.txt* @@ -520,153 +600,66 @@ Bar Baz! ``` -### k. `nl` -Number lines of files +### l. `uniq` +Report or omit repeated lines *example.txt* ```bash -Lorem ipsum -dolor sit amet, -consetetur -sadipscing elitr, -sed diam nonumy -eirmod tempor -invidunt ut labore -et dolore magna -aliquyam erat, sed -diam voluptua. At -vero eos et -accusam et justo -duo dolores et ea -rebum. Stet clita -kasd gubergren, -no sea takimata -sanctus est Lorem -ipsum dolor sit -amet. +a +a +b +a +b +c +d +c ``` -*show example.txt with line numbers* -```bash -nl -s". " example.txt -``` +*show only unique lines of example.txt (first you need to sort it, otherwise it won't see the overlap)* ```bash - 1. Lorem ipsum - 2. dolor sit amet, - 3. consetetur - 4. sadipscing elitr, - 5. sed diam nonumy - 6. eirmod tempor - 7. invidunt ut labore - 8. et dolore magna - 9. aliquyam erat, sed - 10. diam voluptua. At - 11. vero eos et - 12. accusam et justo - 13. duo dolores et ea - 14. rebum. Stet clita - 15. kasd gubergren, - 16. no sea takimata - 17. sanctus est Lorem - 18. ipsum dolor sit - 19. amet. +sort example.txt | uniq ``` - -### l. `egrep` -Print lines matching a pattern - Extended Expression (alias for: 'grep -E') - -*example.txt* ```bash -Lorem ipsum -dolor sit amet, -consetetur -sadipscing elitr, -sed diam nonumy -eirmod tempor -invidunt ut labore -et dolore magna -aliquyam erat, sed -diam voluptua. At -vero eos et -accusam et justo -duo dolores et ea -rebum. Stet clita -kasd gubergren, -no sea takimata -sanctus est Lorem -ipsum dolor sit -amet. +a +b +c +d ``` -*display lines that have either "Lorem" or "dolor" in them.* -```bash -egrep '(Lorem|dolor)' example.txt -or -grep -E '(Lorem|dolor)' example.txt -``` +*show the unique items for each line, and tell me how many instances it found* ```bash -Lorem ipsum -dolor sit amet, -et dolore magna -duo dolores et ea -sanctus est Lorem -ipsum dolor sit +sort example.txt | uniq -c ``` - -### m. `fgrep` -Print lines matching a pattern - FIXED pattern matching (alias for: 'grep -F') - -*example.txt* ```bash -Lorem ipsum -dolor sit amet, -consetetur -sadipscing elitr, -sed diam nonumy -eirmod tempor -foo (Lorem|dolor) -invidunt ut labore -et dolore magna -aliquyam erat, sed -diam voluptua. At -vero eos et -accusam et justo -duo dolores et ea -rebum. Stet clita -kasd gubergren, -no sea takimata -sanctus est Lorem -ipsum dolor sit -amet. + 3 a + 2 b + 2 c + 1 d ``` -*Find the exact string '(Lorem|doloar)' in example.txt* +### m. `wc` +Tells you how many lines, words and characters there are in a file. ```bash -fgrep '(Lorem|dolor)' example.txt -or -grep -F '(Lorem|dolor)' example.txt +wc filename ``` +Example: ```bash -foo (Lorem|dolor) +$ wc demo.txt +7459 15915 398400 demo.txt ``` +Where `7459` is lines, `15915` is words and `398400` is characters. ## 1.3. Directory Operations - - + +
mkdircdcdmkdir pwd
-### a. `mkdir` -Makes a new directory. -```bash -mkdir dirname -``` - -### b. `cd` +### a. `cd` Moves you from one directory to other. Running this ```bash $ cd @@ -676,6 +669,12 @@ moves you to home directory. This command accepts an optional `dirname`, which m cd dirname ``` +### b. `mkdir` +Makes a new directory. +```bash +mkdir dirname +``` + ### c. `pwd` Tells you which directory you currently are in. ```bash @@ -686,158 +685,117 @@ pwd - - - - - - - - - - + + + + + + + + + + - - - - + + + + - - - - - + + + + + - - - - - + + + + +
sshwhoamipasswdquotadatecaluptimewfingerunamebgcaldatedfdigdufgfingerkillkillall
mandfdulastlastmanpasswdping pskillkillalltopbgfgquotascpsshtopuname
pingwhoisdigwgetscpuptimewwgetwhoamiwhois
-### a. `ssh` -ssh (SSH client) is a program for logging into and executing commands on a remote machine. -```bash -ssh user@host -``` -This command also accepts an option `-p` that can be used to connect to specific port. -```bash -ssh -p port user@host -``` - -### b. `whoami` -Return current logged in username. - -### c. `passwd` -Allows the current logged user to change his password. - -### d. `quota` -Shows what your disk quota is. -```bash -quota -v -``` - -### e. `date` -Shows the current date and time. +### a. `bg` +Lists stopped or background jobs; resume a stopped job in the background. -### f. `cal` +### b. `cal` Shows the month's calendar. -### g. `uptime` -Shows current uptime. - -### h. `w` -Displays who is online. - -### i. `finger` -Displays information about user. -```bash -finger username -``` +### c. `date` +Shows the current date and time. -### j. `uname` -Shows kernel information. -```bash -uname -a -``` +### d. `df` +Shows disk usage. -### k. `man` -Shows the manual for specified command. +### e. `dig` +Gets DNS information for domain. ```bash -man command +dig domain ``` -### l. `df` -Shows disk usage. - -### m. `du` +### f. `du` Shows the disk usage of the files and directories in filename (du -s give only a total). ```bash du filename ``` -### n. `last` -Lists your last logins of specified user. -```bash -last yourUsername -``` +### g. `fg` +Brings the most recent job in the foreground. -### o. `ps` -Lists your processes. +### h. `finger` +Displays information about user. ```bash -ps -u yourusername +finger username ``` -### p. `kill` +### i. `kill` Kills (ends) the processes with the ID you gave. ```bash kill PID ``` -### q. `killall` +### j. `killall` Kill all processes with the name. ```bash killall processname ``` -### r. `top` -Displays your currently active processes. +### k. `last` +Lists your last logins of specified user. +```bash +last yourUsername +``` -### s. `bg` -Lists stopped or background jobs; resume a stopped job in the background. +### l. `man` +Shows the manual for specified command. +```bash +man command +``` -### t. `fg` -Brings the most recent job in the foreground. +### m. `passwd` +Allows the current logged user to change his password. -### u. `ping` +### n. `ping` Pings host and outputs results. ```bash ping host ``` -### v. `whois` -Gets whois information for domain. -```bash -whois domain -``` - -### w. `dig` -Gets DNS information for domain. +### o. `ps` +Lists your processes. ```bash -dig domain +ps -u yourusername ``` -### x. `wget` -Downloads file. +### p. `quota` +Shows what your disk quota is. ```bash -wget file +quota -v ``` - -### y. `scp` +### q. `scp` Transfer files between a local host and a remote host or between two remote hosts. *copy from local host to remote host* @@ -854,6 +812,45 @@ This command also accepts an option `-P` that can be used to connect to specific scp -P port user@host:directory/source_file target_file ``` +### r. `ssh` +ssh (SSH client) is a program for logging into and executing commands on a remote machine. +```bash +ssh user@host +``` +This command also accepts an option `-p` that can be used to connect to specific port. +```bash +ssh -p port user@host +``` + +### s. `top` +Displays your currently active processes. + +### t. `uname` +Shows kernel information. +```bash +uname -a +``` + +### u. `uptime` +Shows current uptime. + +### v. `w` +Displays who is online. + +### w. `wget` +Downloads file. +```bash +wget file +``` + +### x. `whoami` +Return current logged in username. + +### y. `whois` +Gets whois information for domain. +```bash +whois domain +``` # 2. Basic Shell Programming From 0c46fdf4e1d7459dbe077d8eb25d07bbbf7813cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20J=C3=BCttner?= Date: Tue, 4 Apr 2017 21:12:00 +0200 Subject: [PATCH 08/50] corrected test for non-empty file (#19) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d4bcb8a..33d8e58 100644 --- a/README.md +++ b/README.md @@ -989,7 +989,7 @@ str1>str2 # str1 is greater than str2 -e file # file exists; same -a -f file # file exists and is a regular file (i.e., not a directory or other special type of file) -r file # you have read permission --r file # file exists and is not empty +-s file # file exists and is not empty -w file # your have write permission -x file # you have execute permission on file, or directory search permission if it is a directory -N file # file was modified since it was last read From 089476ea2f066a56e07636a6e72fa04471f7ac9f Mon Sep 17 00:00:00 2001 From: Diserere Date: Wed, 5 Apr 2017 07:15:53 +0300 Subject: [PATCH 09/50] Corrected example for array initialization (#22) Given example does not initialize an array - there is a probably typo in code sample. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 33d8e58..6b5c3d0 100644 --- a/README.md +++ b/README.md @@ -885,7 +885,7 @@ array[0] = val array[1] = val array[2] = val array=([2]=val [0]=val [1]=val) -array(val val val) +array=(val val val) ``` To display a value at specific index use following syntax: From b7a87a856a64e1f215931bca33d4ea4ef08fdb1b Mon Sep 17 00:00:00 2001 From: Kim Chen Date: Wed, 5 Apr 2017 15:44:49 +1000 Subject: [PATCH 10/50] add basic find support (#21) fixes#20 --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index 6b5c3d0..92120d7 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,7 @@ Clears content on window. rm tail touch + find @@ -236,6 +237,17 @@ Example: $ touch trick.md ``` +### s. `find` +Find files in directory +```bash +find directory options pattern +``` +Example: +```bash +$ find . -name README.md +$ find /home/user1 -name '*.png' +``` + ## 1.2. Text Operations From 911be8949ed223d8c75f9f5dd6f4238447c02411 Mon Sep 17 00:00:00 2001 From: Adnan Ahmed Date: Wed, 5 Apr 2017 09:48:07 +0400 Subject: [PATCH 11/50] minor update --- README.md | 75 +++++++++++++++++++++++++++---------------------------- 1 file changed, 37 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index 92120d7..37efd79 100644 --- a/README.md +++ b/README.md @@ -72,22 +72,22 @@ Clears content on window. - - - - - + + + + + - - - - - - - - - + + + + + + + + +
cp diff filegunzipgzcatgzipheadlpqfindgunzipgzcatgziphead
lprlprmlsmoremvrmtailtouchfindlpqlprlprmlsmoremvrmtailtouch
@@ -132,32 +132,42 @@ Example: $ file index.html index.html: HTML document, ASCII text ``` +### f. `find` +Find files in directory +```bash +find directory options pattern +``` +Example: +```bash +$ find . -name README.md +$ find /home/user1 -name '*.png' +``` -### f. `gunzip` +### g. `gunzip` Un-compresses files compressed by gzip. ```bash gunzip filename ``` -### g. `gzcat` +### h. `gzcat` Lets you look at gzipped file without actually having to gunzip it. ```bash gzcat filename ``` -### h. `gzip` +### i. `gzip` Compresses files. ```bash gzip filename ``` -### i. `head` +### j. `head` Outputs the first 10 lines of file ```bash head filename ``` -### j. `lpq` +### k. `lpq` Check out the printer queue. ```bash lpq @@ -170,19 +180,19 @@ active adnanad 59 demo 399360 bytes 1st adnanad 60 (stdin) 0 bytes ``` -### k. `lpr` +### l. `lpr` Print the file. ```bash lpr filename ``` -### l. `lprm` +### m. `lprm` Remove something from the printer queue. ```bash lprm jobnumber ``` -### m. `ls` +### n. `ls` Lists your files. `ls` has many options: `-l` lists files in 'long format', which contains the exact size of the file, who owns the file, who has the right to look at it, and when it was last modified. `-a` lists all files, including hidden files. For more information on this command check this [link](https://ss64.com/bash/ls.html). ```bash ls option @@ -200,20 +210,20 @@ drwxr-xr-x 17 adnan staff 578 Mar 27 23:36 .git -rwxr-xr-x 1 adnan staff 2702 Mar 25 18:08 .gitignore -### n. `more` +### o. `more` Shows the first part of a file (move with space and type q to quit). ```bash more filename ``` -### o. `mv` +### p. `mv` Moves a file from one location to other. ```bash mv filename1 filename2 ``` Where `filename1` is the source path to the file and `filename2` is the destination path to the file. -### p. `rm` +### q. `rm` Removes a file. Using this command on a directory gives you an error. `rm: directory: is a directory` To remove a directory you have to pass `-r` which will remove the content of the directory recursively. Optionally you can use `-f` flag to force the deletion i.e. without any confirmations etc. @@ -221,13 +231,13 @@ To remove a directory you have to pass `-r` which will remove the content of the rm filename ``` -### q. `tail` +### r. `tail` Outputs the last 10 lines of file. Use `-f` to output appended data as the file grows. ```bash tail filename ``` -### r. `touch` +### s. `touch` Creates or updates your file. ```bash touch filename @@ -237,17 +247,6 @@ Example: $ touch trick.md ``` -### s. `find` -Find files in directory -```bash -find directory options pattern -``` -Example: -```bash -$ find . -name README.md -$ find /home/user1 -name '*.png' -``` - ## 1.2. Text Operations From f5d4727522e130cbabaff6ca42adb30c616353b3 Mon Sep 17 00:00:00 2001 From: Borek Bernard Date: Wed, 5 Apr 2017 18:52:47 +0200 Subject: [PATCH 12/50] Changed `ls -al` to the more common `ls -la` (#23) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 37efd79..7e7a241 100644 --- a/README.md +++ b/README.md @@ -199,7 +199,7 @@ ls option ``` Example:
-$ ls -al
+$ ls -la
 rwxr-xr-x   33 adnan  staff    1122 Mar 27 18:44 .
 drwxrwxrwx  60 adnan  staff    2040 Mar 21 15:06 ..
 -rw-r--r--@  1 adnan  staff   14340 Mar 23 15:05 .DS_Store

From b8311a48a0a180fcb04560b7f7e6014459f7b707 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tobias=20B=C3=BCschel?= 
Date: Wed, 5 Apr 2017 18:54:46 +0200
Subject: [PATCH 13/50] Add du command options & better example (#25)

---
 README.md | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/README.md b/README.md
index 7e7a241..b6f7c3d 100644
--- a/README.md
+++ b/README.md
@@ -747,9 +747,21 @@ dig domain
 ```
 
 ### f. `du`
-Shows the disk usage of the files and directories in filename (du -s give only a total).  
+Shows the disk usage of files or directories. For more information on this command check this [link](http://www.linfo.org/du.html)
 ```bash
-du filename
+du [option] [filename|directory]
+```
+Options:
+- `-h` (human readable) Displays output it in kilobytes (K), megabytes (M) and gigabytes (G).
+- `-s` (supress or summarize) Outputs total disk space of a directory and supresses reports for subdirectories. 
+
+Example:
+```shell
+du -sh pictures
+```
+
+```shell
+1.4M pictures
 ```
 
 ### g. `fg`

From 191c202bd1eafc38fc32ba5728de5b63bc55deb4 Mon Sep 17 00:00:00 2001
From: Adnan Ahmed 
Date: Wed, 5 Apr 2017 23:38:43 +0400
Subject: [PATCH 14/50] minor fix

---
 README.md | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/README.md b/README.md
index b6f7c3d..5c26746 100644
--- a/README.md
+++ b/README.md
@@ -756,11 +756,8 @@ Options:
 - `-s` (supress or summarize) Outputs total disk space of a directory and supresses reports for subdirectories. 
 
 Example:
-```shell
+```bash
 du -sh pictures
-```
-
-```shell
 1.4M pictures
 ```
 

From a9ee7cbe5f5a0b4b7b86a5d628e9c79df7acca54 Mon Sep 17 00:00:00 2001
From: Adnan Ahmed 
Date: Wed, 5 Apr 2017 23:41:57 +0400
Subject: [PATCH 15/50] Remove zsh from export example

fixes#26
---
 README.md | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/README.md b/README.md
index 5c26746..f063ee0 100644
--- a/README.md
+++ b/README.md
@@ -29,14 +29,13 @@ export
 Example:
 ```bash
 $ export
-SHELL=/bin/zsh
 AWS_HOME=/Users/adnanadnan/.aws
 LANG=en_US.UTF-8
 LC_CTYPE=en_US.UTF-8
 LESS=-R
 
-$ echo $SHELL
-/usr/bin/zsh
+$ echo $AWS_HOME
+/Users/adnanadnan/.aws
 ```
 
 ### b. `whereis`

From 1e2cd1f5f09aaf3fb309d84b3102b36b8a27cc98 Mon Sep 17 00:00:00 2001
From: Zero King 
Date: Thu, 6 Apr 2017 06:23:57 +0000
Subject: [PATCH 16/50] Fix quickly go to directory example (#27)

---
 README.md | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/README.md b/README.md
index f063ee0..4d037f9 100644
--- a/README.md
+++ b/README.md
@@ -1072,9 +1072,10 @@ Open `bash_profile` by running following command `nano ~/.bash_profile`
 nano ~/.bashrc
 > export hotellogs="/workspace/hotel-api/storage/logs"
 
+```bash
 source ~/.bashrc
-cd hotellogs
-
+cd $hotellogs
+```
 
 # 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 6d3d99bfaf3e170804231cb99464b0f03995d9a7 Mon Sep 17 00:00:00 2001
From: "J. G. Sebring" 
Date: Thu, 6 Apr 2017 12:06:32 +0200
Subject: [PATCH 17/50] fix: minor spelling error (#28)

---
 README.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/README.md b/README.md
index 4d037f9..95c399c 100644
--- a/README.md
+++ b/README.md
@@ -402,7 +402,7 @@ ipsum dolor sit
 amet.
 ```
 
-*Find the exact string '(Lorem|doloar)' in example.txt*
+*Find the exact string '(Lorem|dolor)' in example.txt*
 ```bash
 fgrep '(Lorem|dolor)' example.txt
 or

From 2cfa591650e8d76126481990d473288d4b2e107f Mon Sep 17 00:00:00 2001
From: Diego 
Date: Thu, 6 Apr 2017 18:39:33 +0200
Subject: [PATCH 18/50] Add another use for `mv` command (#30)

---
 README.md | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/README.md b/README.md
index 95c399c..37c44d3 100644
--- a/README.md
+++ b/README.md
@@ -222,6 +222,11 @@ mv filename1 filename2
 ```
 Where `filename1` is the source path to the file and `filename2` is the destination path to the file.
 
+Also it can be used for rename a file.
+```bash
+mv old_name new_name
+```
+
 ### q. `rm`
 Removes a file. Using this command on a directory gives you an error.
 `rm: directory: is a directory`

From e0731233e0c2d5556de0926027e7984fa4e7f68f Mon Sep 17 00:00:00 2001
From: JaeYoung Mun 
Date: Fri, 7 Apr 2017 18:29:38 +0900
Subject: [PATCH 19/50] Add description for whatis command (#31)

* Add whatis command

* Edit mistype
---
 README.md | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/README.md b/README.md
index 37c44d3..4211813 100644
--- a/README.md
+++ b/README.md
@@ -38,7 +38,18 @@ $ echo $AWS_HOME
 /Users/adnanadnan/.aws
 ```
 
-### b. `whereis`
+### b. `whatis`
+whatis shows description for user commands, system calls, library functions, and others in manual pages
+```bash
+whatis something
+```
+Example:
+```bash
+$ whatis bash
+bash (1)             - GNU Bourne-Again SHell
+```
+
+### c. `whereis`
 whereis searches for executables, source files, and manual pages using a database built by system automatically.
 ```bash
 whereis name
@@ -49,7 +60,7 @@ $ whereis php
 /usr/bin/php
 ```
 
-### c. `which`
+### d. `which`
 which searches for executables in the directories specified by the environment variable PATH. This command will print the full path of the executable(s).
 ```bash
 which program_name 
@@ -60,7 +71,7 @@ $ which php
 /c/xampp/php/php
 ```
 
-### d. clear
+### e. clear
 Clears content on window.
 
 ## 1.1. File Operations

From 3a7c7fc13ee2a77e070873f6dde9d70e6344f426 Mon Sep 17 00:00:00 2001
From: Kaveet Laxmidas 
Date: Sat, 8 Apr 2017 12:23:22 -0500
Subject: [PATCH 20/50] Clarify description of OR operator (#35)

The current description of the OR operator ("one of the statements is true") implies that only one of the statements in the expression can be true, as in an XOR. Adding "at least" to clarify.
---
 README.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/README.md b/README.md
index 4211813..6844713 100644
--- a/README.md
+++ b/README.md
@@ -1010,7 +1010,7 @@ Expression Examples:
 
 ```bash
 statement1 && statement2  # both statements are true
-statement1 || statement2  # one of the statement is true
+statement1 || statement2  # at least one of the statements is true
 
 str1=str2       # str1 matches str2
 str1!=str2      # str1 does not match str2

From 1ab02a3d4749a6c28734ffa98e013109ff2cdcb7 Mon Sep 17 00:00:00 2001
From: "R.Ganesh" 
Date: Sun, 9 Apr 2017 13:48:02 +0530
Subject: [PATCH 21/50] Add copy example for cat (#38)

---
 README.md | 1 +
 1 file changed, 1 insertion(+)

diff --git a/README.md b/README.md
index 6844713..f50230b 100644
--- a/README.md
+++ b/README.md
@@ -111,6 +111,7 @@ It can be used for the following purposes under UNIX or Linux.
 cat filename
 cat file1 file2 
 cat file1 file2 > newcombinedfile
+cat < file1 > file2 #copy file1 to file2
 ```
 
 ### b. `chmod`

From 2317a5bdb2c0c516653193f9f56aee18b469240b Mon Sep 17 00:00:00 2001
From: Mohammed Umar 
Date: Tue, 11 Apr 2017 09:21:31 +0530
Subject: [PATCH 22/50] Reformatting (#39)

1. Reformatting of Bash tutorial.
2. Link for more help n contribution inserted.
---
 README.md | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/README.md b/README.md
index f50230b..9e609a1 100644
--- a/README.md
+++ b/README.md
@@ -912,7 +912,7 @@ Example:
 ```bash
 echo $str   # hello world
 ```
-
+## 2.2. Array
 Like other languages bash has also arrays. An array is variable containing multiple values. There's no maximum limit on the size of array. Array in bash are zero based. The first element is indexed with element 0. There are several ways for creating arrays in bash. Which are given below.
 
 Examples:
@@ -944,7 +944,7 @@ ${varname:+word}    # if varname exists and isn't null, return word; otherwise r
 ${varname:offset:length}    # performs substring expansion. It returns the substring of $varname starting at offset and up to length characters
 ```
 
-## 2.2 String Substitution
+## 2.3 String Substitution
 
 Check some of the syntax on how to manipulate strings
 
@@ -958,7 +958,7 @@ ${variable//pattern/string} # the longest match to pattern in variable is replac
 ${#varname}     # returns the length of the value of the variable as a character string
 ```
 
-## 2.3. Functions
+## 2.4. Functions
 As in almost any programming language, you can use functions to group pieces of code in a more logical way or practice the divine art of recursion. Declaring a function is just a matter of writing function my_func { my_code }. Calling a function is just like calling another program, you just write its name.
 
 ```bash
@@ -983,7 +983,7 @@ say "hello world!"
 
 When you run the above example the `hello` function will output "world!". The above two functions `hello` and `say` are identical. The main difference is function `say`. This function, prints the first argument it receives. Arguments, within functions, are treated in the same manner as arguments given to the script.
 
-## 2.4. Conditionals
+## 2.5. Conditionals
 
 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.
 
@@ -1043,7 +1043,7 @@ file1 -ot file2     # file1 is older than file2
 -ne     # not equal
 ```
 
-## 2.5. Loops
+## 2.6. Loops
 
 There are three types of loops in bash. `for`, `while` and `until`.
 
@@ -1105,8 +1105,8 @@ bash -x scriptname
 
 ## Contribution
 
-- Report issues
-- Open pull request with improvements
+- Report issues [How to](https://help.github.com/articles/creating-an-issue/)
+- Open pull request with improvements [How to](https://help.github.com/articles/about-pull-requests/)
 - Spread the word
 
 ## License

From b23931ef435d4264097d49a416a1db41d1666fb8 Mon Sep 17 00:00:00 2001
From: Adnan Ahmed 
Date: Tue, 11 Apr 2017 07:52:55 +0400
Subject: [PATCH 23/50] add missing TOC

---
 README.md | 1 +
 1 file changed, 1 insertion(+)

diff --git a/README.md b/README.md
index 9e609a1..ce6d565 100644
--- a/README.md
+++ b/README.md
@@ -11,6 +11,7 @@
     1.5. [Process Monitoring Operations (TODO)](#15-process-monitoring-operations)
   2. [Basic Shell Programming](#2-basic-shell-programming)  
     2.1. [Variables](#21-variables)  
+    2.2  [Array](#22-array)  
     2.3. [String Substitution](#22-string-substitution)  
     2.4. [Functions](#23-functions)  
     2.5. [Conditionals](#24-conditionals)  

From 54681a2b225f59d3c924120b1f5ac824cdb7cbcd Mon Sep 17 00:00:00 2001
From: Adnan Ahmed 
Date: Tue, 11 Apr 2017 07:53:29 +0400
Subject: [PATCH 24/50] Update README.md

---
 README.md | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/README.md b/README.md
index ce6d565..0ffa121 100644
--- a/README.md
+++ b/README.md
@@ -12,10 +12,10 @@
   2. [Basic Shell Programming](#2-basic-shell-programming)  
     2.1. [Variables](#21-variables)  
     2.2  [Array](#22-array)  
-    2.3. [String Substitution](#22-string-substitution)  
-    2.4. [Functions](#23-functions)  
-    2.5. [Conditionals](#24-conditionals)  
-    2.6. [Loops](#25-loops)  
+    2.3. [String Substitution](#23-string-substitution)  
+    2.4. [Functions](#24-functions)  
+    2.5. [Conditionals](#25-conditionals)  
+    2.6. [Loops](#26-loops)  
   3. [Tricks](#3-tricks)  
   4. [Debugging](#4-debugging)  
   

From 1131add1067394bd85d651784cbfb1d6d48dda2d Mon Sep 17 00:00:00 2001
From: Ryan Barth 
Date: Sun, 16 Apr 2017 01:02:21 -0700
Subject: [PATCH 25/50] add exit trap trick (#45)

---
 README.md | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/README.md b/README.md
index 0ffa121..6eb29b3 100644
--- a/README.md
+++ b/README.md
@@ -1095,6 +1095,18 @@ source ~/.bashrc
 cd $hotellogs
 ```
 
+## Exit traps
+
+Make your bash scripts more robust by reliably performing cleanup.
+
+```bash
+function finish {
+  # your cleanup here. e.g. kill any forked processes
+  jobs -p | xargs kill
+}
+trap finish EXIT
+```
+
 # 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 d85384a84748f8487349268048323576f9d14d9a Mon Sep 17 00:00:00 2001
From: Gibran Malheiros 
Date: Tue, 18 Apr 2017 02:57:54 -0300
Subject: [PATCH 26/50] improved description from the touch command (#51)

---
 README.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/README.md b/README.md
index 6eb29b3..4271e1f 100644
--- a/README.md
+++ b/README.md
@@ -255,7 +255,7 @@ tail filename
 ```
 
 ### s. `touch`
-Creates or updates your file.  
+Updates access and modification time stamps of your file. If it doesn't exists, it'll be created.
 ```bash
 touch filename
 ```

From 15a44de8ea06f080cc916f591da1245bf629219a Mon Sep 17 00:00:00 2001
From: Mohammed Umar 
Date: Tue, 25 Apr 2017 00:25:07 +0530
Subject: [PATCH 27/50] Update README.md (#32)

chmod function updated for beter clarity.
---
 README.md | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/README.md b/README.md
index 4271e1f..22f6f0a 100644
--- a/README.md
+++ b/README.md
@@ -120,6 +120,33 @@ Lets you change the read, write, and execute permissions on your files.
 ```bash
 chmod -options filename
 ```
+Syntax : (for numericals role assignment)
+```bash
+chmod nnn /path/to/file
+```
+Where n is number from 0 to 7
+
+
    Here, +
  • First number is for Owner
  • +
  • Second number is for group
  • +
  • Third number is for Other
  • +
+ +Following number are used for permissions
+0 - no permissions
+1 - execute
+2 - write
+3 - write and execute
+4 - read
+5 - read and execute
+6 - read and write
+7 - read, write and execute.
+ +For example to provide full access to only Owner + +```bash +chmod 700 path/to/file +``` ### c. `cp` Copies a file from one location to other. From 4329a7352f5f2d68e27742f4f69902a7de37f21d Mon Sep 17 00:00:00 2001 From: Adnan Ahmed Date: Mon, 24 Apr 2017 22:57:03 +0400 Subject: [PATCH 28/50] add more detail link on chmod command --- README.md | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/README.md b/README.md index 22f6f0a..005c28d 100644 --- a/README.md +++ b/README.md @@ -116,37 +116,10 @@ cat < file1 > file2 #copy file1 to file2 ``` ### b. `chmod` -Lets you change the read, write, and execute permissions on your files. +Lets you change the read, write, and execute permissions on your files. For more information on this command check this [link](https://ss64.com/bash/chmod.html). ```bash chmod -options filename ``` -Syntax : (for numericals role assignment) -```bash -chmod nnn /path/to/file -``` -Where n is number from 0 to 7 - -
    Here, -
  • First number is for Owner
  • -
  • Second number is for group
  • -
  • Third number is for Other
  • -
- -Following number are used for permissions
-0 - no permissions
-1 - execute
-2 - write
-3 - write and execute
-4 - read
-5 - read and execute
-6 - read and write
-7 - read, write and execute.
- -For example to provide full access to only Owner - -```bash -chmod 700 path/to/file -``` ### c. `cp` Copies a file from one location to other. From cae0769e3c668a71ab98741bb4aa3fb87ff97ad7 Mon Sep 17 00:00:00 2001 From: arterhacker Date: Mon, 24 Apr 2017 22:25:03 +0300 Subject: [PATCH 29/50] chown added (#34) * chown added * add chown command * add chown command --- README.md | 77 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 42 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 005c28d..81cea7b 100644 --- a/README.md +++ b/README.md @@ -80,25 +80,26 @@ Clears content on window.
- - - - - - - - + + + + + + + + + - - - - - - - - - + + + + + + + + +
cat chmodcpdifffilefindgunzipgzcatgzipheadchowncpdifffilefindgunzipgzcatgziphead
lpqlprlprmlsmoremvrmtailtouchlpqlprlprmlsmoremvrmtailtouch
@@ -116,25 +117,31 @@ cat < file1 > file2 #copy file1 to file2 ``` ### b. `chmod` -Lets you change the read, write, and execute permissions on your files. For more information on this command check this [link](https://ss64.com/bash/chmod.html). +The chmod command stands for "change mode" and allows you to change the read, write, and execute permissions on your files and folders. For more information on this command check this [link](https://ss64.com/bash/chmod.html). ```bash chmod -options filename ``` -### c. `cp` +### c. `chown` +The chown command stands for "change owner", and allows you to change the owner of a given file or folder, which can be a user and a group. Basic usage is simple forward first comes the user (owner), and then the group, delimited by a colon. +```bash +chown -options user:group filename +``` + +### d. `cp` Copies a file from one location to other. ```bash cp filename1 filename2 ``` Where `filename1` is the source path to the file and `filename2` is the destination path to the file. -### d. `diff` +### e. `diff` Compares files, and lists their differences. ```bash diff filename1 filename2 ``` -### e. `file` +### f. `file` Determine file type. ```bash file filename @@ -144,7 +151,7 @@ Example: $ file index.html index.html: HTML document, ASCII text ``` -### f. `find` +### g. `find` Find files in directory ```bash find directory options pattern @@ -155,31 +162,31 @@ $ find . -name README.md $ find /home/user1 -name '*.png' ``` -### g. `gunzip` +### h. `gunzip` Un-compresses files compressed by gzip. ```bash gunzip filename ``` -### h. `gzcat` +### i. `gzcat` Lets you look at gzipped file without actually having to gunzip it. ```bash gzcat filename ``` -### i. `gzip` +### j. `gzip` Compresses files. ```bash gzip filename ``` -### j. `head` +### k. `head` Outputs the first 10 lines of file ```bash head filename ``` -### k. `lpq` +### l. `lpq` Check out the printer queue. ```bash lpq @@ -192,19 +199,19 @@ active adnanad 59 demo 399360 bytes 1st adnanad 60 (stdin) 0 bytes ``` -### l. `lpr` +### m. `lpr` Print the file. ```bash lpr filename ``` -### m. `lprm` +### n. `lprm` Remove something from the printer queue. ```bash lprm jobnumber ``` -### n. `ls` +### o. `ls` Lists your files. `ls` has many options: `-l` lists files in 'long format', which contains the exact size of the file, who owns the file, who has the right to look at it, and when it was last modified. `-a` lists all files, including hidden files. For more information on this command check this [link](https://ss64.com/bash/ls.html). ```bash ls option @@ -222,13 +229,13 @@ drwxr-xr-x 17 adnan staff 578 Mar 27 23:36 .git -rwxr-xr-x 1 adnan staff 2702 Mar 25 18:08 .gitignore -### o. `more` +### p. `more` Shows the first part of a file (move with space and type q to quit). ```bash more filename ``` -### p. `mv` +### q. `mv` Moves a file from one location to other. ```bash mv filename1 filename2 @@ -240,7 +247,7 @@ Also it can be used for rename a file. mv old_name new_name ``` -### q. `rm` +### r. `rm` Removes a file. Using this command on a directory gives you an error. `rm: directory: is a directory` To remove a directory you have to pass `-r` which will remove the content of the directory recursively. Optionally you can use `-f` flag to force the deletion i.e. without any confirmations etc. @@ -248,13 +255,13 @@ To remove a directory you have to pass `-r` which will remove the content of the rm filename ``` -### r. `tail` +### s. `tail` Outputs the last 10 lines of file. Use `-f` to output appended data as the file grows. ```bash tail filename ``` -### s. `touch` +### t. `touch` Updates access and modification time stamps of your file. If it doesn't exists, it'll be created. ```bash touch filename From 634bda0187649c2d05fe2088b5dcd0d6009f5898 Mon Sep 17 00:00:00 2001 From: Constantin Guidon Date: Mon, 24 Apr 2017 21:39:32 +0200 Subject: [PATCH 30/50] =?UTF-8?q?add=20process=20monitoring=20section=20,?= =?UTF-8?q?=20add=20nohup=20command=20and=20move=20kill=20and=20=E2=80=A6?= =?UTF-8?q?=20(#36)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add process monitoring section , add nohup command and move kill and killall inside * nohup and & command * Add index for navigation in network section and remove todo * Update README.md --- README.md | 116 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 70 insertions(+), 46 deletions(-) diff --git a/README.md b/README.md index 81cea7b..2254de7 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ 1.2. [Text Operations](#12-text-operations) 1.3. [Directory Operations](#13-directory-operations) 1.4. [SSH, System Info & Network Operations](#14-ssh-system-info--network-operations) - 1.5. [Process Monitoring Operations (TODO)](#15-process-monitoring-operations) + 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) @@ -727,28 +727,26 @@ pwd dig du fg - finger - kill - killall + finger + last + man - last - man - passwd - ping - ps - quota - scp - ssh - top - uname + passwd + ping + ps + quota + scp + ssh + top + uname + uptime + w - uptime - w - wget - whoami - whois + wget + whoami + whois @@ -794,52 +792,40 @@ Displays information about user. finger username ``` -### i. `kill` -Kills (ends) the processes with the ID you gave. -```bash -kill PID -``` - -### j. `killall` -Kill all processes with the name. -```bash -killall processname -``` - -### k. `last` +### i. `last` Lists your last logins of specified user. ```bash last yourUsername ``` -### l. `man` +### j. `man` Shows the manual for specified command. ```bash man command ``` -### m. `passwd` +### k. `passwd` Allows the current logged user to change his password. -### n. `ping` +### l. `ping` Pings host and outputs results. ```bash ping host ``` -### o. `ps` +### m. `ps` Lists your processes. ```bash ps -u yourusername ``` -### p. `quota` +### n. `quota` Shows what your disk quota is. ```bash quota -v ``` -### q. `scp` +### o. `scp` Transfer files between a local host and a remote host or between two remote hosts. *copy from local host to remote host* @@ -856,7 +842,7 @@ This command also accepts an option `-P` that can be used to connect to specific scp -P port user@host:directory/source_file target_file ``` -### r. `ssh` +### p. `ssh` ssh (SSH client) is a program for logging into and executing commands on a remote machine. ```bash ssh user@host @@ -866,36 +852,74 @@ This command also accepts an option `-p` that can be used to connect to specific ssh -p port user@host ``` -### s. `top` +### q. `top` Displays your currently active processes. -### t. `uname` +### r. `uname` Shows kernel information. ```bash uname -a ``` -### u. `uptime` +### s. `uptime` Shows current uptime. -### v. `w` +### t. `w` Displays who is online. -### w. `wget` +### u. `wget` Downloads file. ```bash wget file ``` -### x. `whoami` +### v. `whoami` Return current logged in username. -### y. `whois` +### w. `whois` Gets whois information for domain. ```bash whois domain ``` +## 1.5. Process Monitoring Operations + + + + + + + +
killkillall&
+ +### a. `kill` +Kills (ends) the processes with the ID you gave. +```bash +kill PID +``` + +### b. `killall` +Kill all processes with the name. +```bash +killall processname +``` + +### c. `&` +The `&` symbol instructs the command to run as a background process in a subshell. +```bash +command & +``` + +### d. `nohup` +nohup stands for "No Hang Up". This allows to run command/process or shell script that can continue running in the background after you log out from a shell. +```bash +nohup command +``` +Combine it with `&` to create background processes +```bash +nohup command & +``` + # 2. Basic Shell Programming From e17c58464772ae920659a3942f36681677c541b5 Mon Sep 17 00:00:00 2001 From: Adnan Ahmed Date: Mon, 24 Apr 2017 23:44:09 +0400 Subject: [PATCH 31/50] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2254de7..e778c16 100644 --- a/README.md +++ b/README.md @@ -889,6 +889,7 @@ whois domain kill killall & + nohup @@ -904,7 +905,7 @@ Kill all processes with the name. killall processname ``` -### c. `&` +### c. `&` The `&` symbol instructs the command to run as a background process in a subshell. ```bash command & From b648976e228058e49177beefb88a24da07478a75 Mon Sep 17 00:00:00 2001 From: Adnan Ahmed Date: Mon, 24 Apr 2017 23:45:41 +0400 Subject: [PATCH 32/50] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e778c16..70f0525 100644 --- a/README.md +++ b/README.md @@ -905,7 +905,7 @@ Kill all processes with the name. killall processname ``` -### c. `&` +### c. & The `&` symbol instructs the command to run as a background process in a subshell. ```bash command & From 32eabdc3396fcc6165b8c0978f239887b7ca76b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Freires?= Date: Mon, 24 Apr 2017 16:52:41 -0300 Subject: [PATCH 33/50] ~/bin directory to access scripts easily and keeping environment variables. (#49) * keeping environment variables. Useful way to keep the environment variables. * Add a ~/bin directory to access scripts easily Useful way to access yours scripts easily. --- README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/README.md b/README.md index 70f0525..248ea7c 100644 --- a/README.md +++ b/README.md @@ -1139,6 +1139,25 @@ function finish { trap finish 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 +```bash +echo export FOO=BAR >> ~/.bash_profile +``` + +## Accessing your scripts + +You can easily access your scripts by creating a bin folder in your home with `mkdir ~/bin`, now all the scripts you put in this folder you can access in any directory. + +If you can not access, try append the code below in your `~/.bash_profile` file and after do `source ~/.bash_profile`. +```bash + # set PATH so it includes user's private bin if it exists + if [ -d "$HOME/bin" ] ; then + PATH="$HOME/bin:$PATH" + 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 d374a6db8b450cf36e3190504e2a838cc29a6518 Mon Sep 17 00:00:00 2001 From: Aubree Lytwyn Date: Tue, 2 May 2017 00:32:13 -0600 Subject: [PATCH 34/50] added the "jobs" command, close #17 (#52) --- README.md | 65 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 34 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 248ea7c..1eb706d 100644 --- a/README.md +++ b/README.md @@ -727,26 +727,27 @@ pwd dig du fg - finger - last - man + finger + jobs + last + man - passwd - ping - ps - quota - scp - ssh - top - uname - uptime - w + passwd + ping + ps + quota + scp + ssh + top + uname + uptime + w - wget - whoami - whois + wget + whoami + whois @@ -791,41 +792,43 @@ Displays information about user. ```bash finger username ``` +### i. `jobs` +Lists the jobs running in the background, giving the job number. -### i. `last` +### j. `last` Lists your last logins of specified user. ```bash last yourUsername ``` -### j. `man` +### k. `man` Shows the manual for specified command. ```bash man command ``` -### k. `passwd` +### l. `passwd` Allows the current logged user to change his password. -### l. `ping` +### m. `ping` Pings host and outputs results. ```bash ping host ``` -### m. `ps` +### n. `ps` Lists your processes. ```bash ps -u yourusername ``` -### n. `quota` +### o. `quota` Shows what your disk quota is. ```bash quota -v ``` -### o. `scp` +### p. `scp` Transfer files between a local host and a remote host or between two remote hosts. *copy from local host to remote host* @@ -842,7 +845,7 @@ This command also accepts an option `-P` that can be used to connect to specific scp -P port user@host:directory/source_file target_file ``` -### p. `ssh` +### q. `ssh` ssh (SSH client) is a program for logging into and executing commands on a remote machine. ```bash ssh user@host @@ -852,31 +855,31 @@ This command also accepts an option `-p` that can be used to connect to specific ssh -p port user@host ``` -### q. `top` +### r. `top` Displays your currently active processes. -### r. `uname` +### s. `uname` Shows kernel information. ```bash uname -a ``` -### s. `uptime` +### t. `uptime` Shows current uptime. -### t. `w` +### u. `w` Displays who is online. -### u. `wget` +### v. `wget` Downloads file. ```bash wget file ``` -### v. `whoami` +### w. `whoami` Return current logged in username. -### w. `whois` +### x. `whois` Gets whois information for domain. ```bash whois domain From 986117ef3d2c9a2927d8010e7b24eabe8e0c75bc Mon Sep 17 00:00:00 2001 From: Adnan Ahmed Date: Tue, 2 May 2017 10:34:26 +0400 Subject: [PATCH 35/50] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1eb706d..64d1963 100644 --- a/README.md +++ b/README.md @@ -730,9 +730,9 @@ pwd finger jobs last - man + man passwd ping ps @@ -742,9 +742,9 @@ pwd top uname uptime - w + w wget whoami whois From 809824add81a400e7ca395d75bf7b105bd235d6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer?= Date: Wed, 3 May 2017 12:07:52 +0300 Subject: [PATCH 36/50] Update README.md (#54) miss typing farget_folder -> target_folder --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 64d1963..9ab9658 100644 --- a/README.md +++ b/README.md @@ -838,7 +838,7 @@ scp source_file user@host:directory/target_file *copy from remote host to local host* ```bash scp user@host:directory/source_file target_file -scp -r user@host:directory/source_folder farget_folder +scp -r user@host:directory/source_folder target_folder ``` This command also accepts an option `-P` that can be used to connect to specific port. ```bash From 9a0aefb48aac2001be002181afb9edc115912fe2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer?= Date: Wed, 3 May 2017 12:08:13 +0300 Subject: [PATCH 37/50] Update README.md (#53) mis-typing your-> you --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9ab9658..74eaccd 100644 --- a/README.md +++ b/README.md @@ -1062,7 +1062,7 @@ str1>str2 # str1 is greater than str2 -f file # file exists and is a regular file (i.e., not a directory or other special type of file) -r file # you have read permission -s file # file exists and is not empty --w file # your have write permission +-w file # you have write permission -x file # you have execute permission on file, or directory search permission if it is a directory -N file # file was modified since it was last read -O file # you own file From 6d38f42719063275f362b2a13efc1b4ede49d27b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer?= Date: Sun, 7 May 2017 21:04:37 +0300 Subject: [PATCH 38/50] Turkish link added. (#56) --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 74eaccd..2bd734c 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ bash logo

+#### Turkish Version is below. | Türkçe linki dosyanın alt kısmında. + ## Table of Contents 1. [Basic Operations](#1-basic-operations) 1.1. [File Operations](#11-file-operations) @@ -1176,6 +1178,9 @@ bash -x scriptname - Open pull request with improvements [How to](https://help.github.com/articles/about-pull-requests/) - Spread the word +## Translation +- [Turkish | Türkçe](https://github.com/omergulen/bash-guide) + ## License [![License: CC BY 4.0](https://img.shields.io/badge/License-CC%20BY%204.0-lightgrey.svg)](https://creativecommons.org/licenses/by/4.0/) From 8d38caf0faf3a5ab82580c889d929e252510a202 Mon Sep 17 00:00:00 2001 From: Adnan Ahmed Date: Sun, 7 May 2017 22:05:03 +0400 Subject: [PATCH 39/50] Update README.md --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 2bd734c..4cae412 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,6 @@ bash logo

-#### Turkish Version is below. | Türkçe linki dosyanın alt kısmında. - ## Table of Contents 1. [Basic Operations](#1-basic-operations) 1.1. [File Operations](#11-file-operations) From b90e8b56c77c19704af62a637fbec883b5eebd14 Mon Sep 17 00:00:00 2001 From: Aleksandar Jovanov Date: Sun, 14 May 2017 13:17:29 +0200 Subject: [PATCH 40/50] Fix function declaration syntax (#59) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4cae412..575571f 100644 --- a/README.md +++ b/README.md @@ -998,7 +998,7 @@ ${#varname} # returns the length of the value of the variable as a character As in almost any programming language, you can use functions to group pieces of code in a more logical way or practice the divine art of recursion. Declaring a function is just a matter of writing function my_func { my_code }. Calling a function is just like calling another program, you just write its name. ```bash -functname() { +function name() { shell commands } ``` From c0001e932cfb03437ea91320c5ff191cabc61275 Mon Sep 17 00:00:00 2001 From: itooww Date: Fri, 30 Jun 2017 12:03:43 +0900 Subject: [PATCH 41/50] add japanese link (#61) --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 575571f..193e55a 100644 --- a/README.md +++ b/README.md @@ -1178,6 +1178,7 @@ bash -x scriptname ## Translation - [Turkish | Türkçe](https://github.com/omergulen/bash-guide) +- [Japanese | 日本語](https://github.com/itooww/bash-guide) ## License From de77a6f9e0e18716384f3852c432aaf5ba1f8de7 Mon Sep 17 00:00:00 2001 From: Ethan Date: Thu, 5 Oct 2017 01:44:46 -0500 Subject: [PATCH 42/50] 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 43/50] 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 44/50] 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 45/50] 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 46/50] 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 a24eaecc3f23d2127b6d0ce55a282b719a068c82 Mon Sep 17 00:00:00 2001 From: Rowayda Khayri Date: Sun, 5 May 2019 08:46:26 +0200 Subject: [PATCH 47/50] Fixes (#74) * fix typos * fix assigning values to array indexes --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7f5f26a..85e19b5 100644 --- a/README.md +++ b/README.md @@ -953,13 +953,13 @@ Example: echo $str # hello world ``` ## 2.2. Array -Like other languages bash has also arrays. An array is variable containing multiple values. There's no maximum limit on the size of array. Array in bash are zero based. The first element is indexed with element 0. There are several ways for creating arrays in bash. Which are given below. +Like other languages bash has also arrays. An array is a variable containing multiple values. There's no maximum limit on the size of array. Arrays in bash are zero based. The first element is indexed with element 0. There are several ways for creating arrays in bash which are given below. Examples: ```bash -array[0] = val -array[1] = val -array[2] = val +array[0]=val +array[1]=val +array[2]=val array=([2]=val [0]=val [1]=val) array=(val val val) ``` From 1e3268163c7bf101f05498595cb43fd1bed1c115 Mon Sep 17 00:00:00 2001 From: Adnan Ahmed Date: Thu, 23 May 2019 23:30:12 +0400 Subject: [PATCH 48/50] Create FUNDING.yml --- .github/FUNDING.yml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .github/FUNDING.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..0be85e1 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,4 @@ +# These are supported funding model platforms + +github: [idnan] +custom: https://paypal.me/id9a9 From 90d268b9d7ad4fb835cf56b09b8fd8274e54fdce Mon Sep 17 00:00:00 2001 From: Cary Williams Date: Wed, 16 Oct 2019 06:37:13 -0500 Subject: [PATCH 49/50] adding info for mkdir and command execution (#77) --- README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/README.md b/README.md index 85e19b5..6b75f0a 100644 --- a/README.md +++ b/README.md @@ -709,6 +709,15 @@ Makes a new directory. ```bash mkdir dirname ``` +You can use this to create multiple directories at once within your current directory. +```bash +mkdir 1stDirectory 2ndDirectory 3rdDirectory +``` +You can also use this to create parent directories at the same time. For instance, if you wanted a directory named 'project1' in another subdirectory at '/samples/bash/projects/', you could run: +```bash +mkdir /samples/bash/projects/project1 +``` +If any of these directories did no already exist, they would be created as well. ### c. `pwd` Tells you which directory you currently are in. @@ -1134,6 +1143,14 @@ source ~/.bashrc cd $hotellogs ``` +## Re-execute the previous command +This goes back to the days before you could rely on keyboards to have an "up" arrow key, but can still be useful. +To run the last command in your history +> !! +A common error is to forget to use `sudo` to prefix a command requiring privileged execution. Instead of typing the whole command again, you can: +> sudo !! +This would change a `mkdir somedir` into `sudo mkdir somedir` + ## Exit traps Make your bash scripts more robust by reliably performing cleanup. From c19dd162de73952db040b8514089b4c506cda2b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zlatan=20Vasovi=C4=87?= Date: Tue, 28 Jan 2020 09:44:45 +0100 Subject: [PATCH 50/50] Replace > with codeblocks (#78) The text is very unreadable in several sections thanks to the use of `>` (quote syntax in Markdown), so I replaced it with codeblocks. --- README.md | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 6b75f0a..0f9ad4d 100644 --- a/README.md +++ b/README.md @@ -1131,12 +1131,22 @@ done # 3. Tricks ## Set an alias -Open `bash_profile` by running following command `nano ~/.bash_profile` -> alias dockerlogin='ssh www-data@adnan.local -p2222' # add your alias in .bash_profile + +Run `nano ~/.bash_profile` and add the following line: + +```bash +alias dockerlogin='ssh www-data@adnan.local -p2222' # add your alias in .bash_profile +``` ## To quickly go to a specific directory -nano ~/.bashrc -> export hotellogs="/workspace/hotel-api/storage/logs" + +Run `nano ~/.bashrc` and add the following line: + +```bash +export hotellogs="/workspace/hotel-api/storage/logs" +``` + +Now you can use the saved path: ```bash source ~/.bashrc @@ -1144,12 +1154,17 @@ cd $hotellogs ``` ## Re-execute the previous command + This goes back to the days before you could rely on keyboards to have an "up" arrow key, but can still be useful. To run the last command in your history -> !! +```bash +!! +``` A common error is to forget to use `sudo` to prefix a command requiring privileged execution. Instead of typing the whole command again, you can: -> sudo !! -This would change a `mkdir somedir` into `sudo mkdir somedir` +```bash +sudo !! +``` +This would change a `mkdir somedir` into `sudo mkdir somedir`. ## Exit traps @@ -1176,10 +1191,10 @@ You can easily access your scripts by creating a bin folder in your home with `m If you can not access, try append the code below in your `~/.bash_profile` file and after do `source ~/.bash_profile`. ```bash - # set PATH so it includes user's private bin if it exists - if [ -d "$HOME/bin" ] ; then - PATH="$HOME/bin:$PATH" - fi +# set PATH so it includes user's private bin if it exists +if [ -d "$HOME/bin" ] ; then + PATH="$HOME/bin:$PATH" +fi ``` # 4. Debugging