├── images ├── logo.jpeg ├── unix.jpeg ├── logos │ ├── light.png │ ├── toc.png │ ├── web.png │ ├── python.png │ ├── checkmark.png │ ├── checkmark_white.png │ └── linux-terminal.jpeg └── banners │ ├── python-oop.png │ ├── introduction.png │ ├── python-basics.png │ ├── python-pandas.png │ ├── python-advanced.png │ ├── python-modular.png │ ├── python-modules.png │ ├── python-practice.png │ └── python-before-start.png ├── Linux ├── images │ ├── alias.png │ ├── egrep.png │ ├── fgrep.png │ ├── ls-l.jpg │ ├── nano.png │ ├── tee.png │ ├── fdfind.png │ ├── grep-r.png │ ├── locate.png │ ├── nano-l.png │ ├── grep-r-h.png │ ├── tar-gzip.png │ ├── grep-escape.png │ ├── command_in_out.png │ ├── file-permissions.png │ └── file-permissions-2.gif ├── 01 Introduction │ ├── images │ │ ├── wsl │ │ │ ├── wsl_enable.png │ │ │ ├── wsl_install.png │ │ │ ├── wsl_ubuntu_get.png │ │ │ ├── windows_terminal.png │ │ │ ├── wsl_ubuntu_launch.png │ │ │ ├── wsl_ubuntu_download.png │ │ │ ├── wsl_ubuntu_userpass.png │ │ │ ├── windows_terminal_tabs.png │ │ │ └── windows_terminal_customization.png │ │ ├── operating-systems │ │ │ ├── os.jpeg │ │ │ ├── mac-os.jpeg │ │ │ ├── windows.jpeg │ │ │ ├── mobile-os.jpeg │ │ │ ├── os-types.jpeg │ │ │ ├── os_process.jpg │ │ │ ├── ibm_first_pc.jpeg │ │ │ ├── batch-operating-system.png │ │ │ ├── types-of-operating-system.png │ │ │ └── os-definition-and-functions.png │ │ ├── linux-terminal │ │ │ ├── pwd-command.png │ │ │ ├── linux-terminal.png │ │ │ ├── mac-terminal.png │ │ │ └── open_terminal.png │ │ └── linux-fundamentals │ │ │ ├── linux-terminal.png │ │ │ ├── ubuntu-install-software.png │ │ │ ├── gnu-linux-distribution-timeline.png │ │ │ └── ubuntu-install-software-terminal.png │ ├── 05 Linux Command Structure.ipynb │ ├── 03 WSL.ipynb │ ├── 02 Linux Fundamentals.ipynb │ ├── 01 Operating Systems.ipynb │ └── 04 Linux Terminal Basics.ipynb ├── 02 Linux File System │ ├── 06. Copying, Moving, Renaming.md │ ├── 02. File Extensions.md │ ├── 05. Deleting File and Directories.md │ ├── 04. Creating Files and Directories.md │ ├── 07. Nano Editor.md │ ├── 01. Navigating the File System.md │ ├── 03. Wildcards.md │ ├── 09. Viewing Files.md │ ├── 10. Search File Content.md │ ├── 08. Search for Files.md │ └── 11. Archiving and Compression.md ├── 04 Bash Shell Scripting │ ├── 06. Comparison.md │ ├── 04. Redirection.md │ ├── 07. Conditional Statement.md │ ├── 02. Script Execution.md │ ├── 08. Loops.md │ ├── 03. Variables.md │ ├── 01. Introduction.md │ └── 05. Functions.md └── 03 Linux Advanced │ ├── 04. Command Input & Output.md │ ├── 05. Redirection.md │ ├── 07. Aliases.md │ ├── 01. Command Structure.md │ ├── 06. Piping.md │ ├── 02. Linux Manual.md │ └── 03. Permissions.md ├── README.md ├── LICENSE └── .gitignore /images/logo.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/images/logo.jpeg -------------------------------------------------------------------------------- /images/unix.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/images/unix.jpeg -------------------------------------------------------------------------------- /Linux/images/alias.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/Linux/images/alias.png -------------------------------------------------------------------------------- /Linux/images/egrep.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/Linux/images/egrep.png -------------------------------------------------------------------------------- /Linux/images/fgrep.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/Linux/images/fgrep.png -------------------------------------------------------------------------------- /Linux/images/ls-l.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/Linux/images/ls-l.jpg -------------------------------------------------------------------------------- /Linux/images/nano.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/Linux/images/nano.png -------------------------------------------------------------------------------- /Linux/images/tee.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/Linux/images/tee.png -------------------------------------------------------------------------------- /images/logos/light.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/images/logos/light.png -------------------------------------------------------------------------------- /images/logos/toc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/images/logos/toc.png -------------------------------------------------------------------------------- /images/logos/web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/images/logos/web.png -------------------------------------------------------------------------------- /Linux/images/fdfind.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/Linux/images/fdfind.png -------------------------------------------------------------------------------- /Linux/images/grep-r.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/Linux/images/grep-r.png -------------------------------------------------------------------------------- /Linux/images/locate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/Linux/images/locate.png -------------------------------------------------------------------------------- /Linux/images/nano-l.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/Linux/images/nano-l.png -------------------------------------------------------------------------------- /images/logos/python.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/images/logos/python.png -------------------------------------------------------------------------------- /Linux/images/grep-r-h.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/Linux/images/grep-r-h.png -------------------------------------------------------------------------------- /Linux/images/tar-gzip.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/Linux/images/tar-gzip.png -------------------------------------------------------------------------------- /images/logos/checkmark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/images/logos/checkmark.png -------------------------------------------------------------------------------- /Linux/images/grep-escape.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/Linux/images/grep-escape.png -------------------------------------------------------------------------------- /images/banners/python-oop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/images/banners/python-oop.png -------------------------------------------------------------------------------- /Linux/images/command_in_out.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/Linux/images/command_in_out.png -------------------------------------------------------------------------------- /images/banners/introduction.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/images/banners/introduction.png -------------------------------------------------------------------------------- /images/banners/python-basics.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/images/banners/python-basics.png -------------------------------------------------------------------------------- /images/banners/python-pandas.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/images/banners/python-pandas.png -------------------------------------------------------------------------------- /images/logos/checkmark_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/images/logos/checkmark_white.png -------------------------------------------------------------------------------- /images/logos/linux-terminal.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/images/logos/linux-terminal.jpeg -------------------------------------------------------------------------------- /Linux/images/file-permissions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/Linux/images/file-permissions.png -------------------------------------------------------------------------------- /images/banners/python-advanced.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/images/banners/python-advanced.png -------------------------------------------------------------------------------- /images/banners/python-modular.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/images/banners/python-modular.png -------------------------------------------------------------------------------- /images/banners/python-modules.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/images/banners/python-modules.png -------------------------------------------------------------------------------- /images/banners/python-practice.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/images/banners/python-practice.png -------------------------------------------------------------------------------- /Linux/images/file-permissions-2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/Linux/images/file-permissions-2.gif -------------------------------------------------------------------------------- /images/banners/python-before-start.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/images/banners/python-before-start.png -------------------------------------------------------------------------------- /Linux/01 Introduction/images/wsl/wsl_enable.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/Linux/01 Introduction/images/wsl/wsl_enable.png -------------------------------------------------------------------------------- /Linux/01 Introduction/images/wsl/wsl_install.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/Linux/01 Introduction/images/wsl/wsl_install.png -------------------------------------------------------------------------------- /Linux/01 Introduction/images/wsl/wsl_ubuntu_get.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/Linux/01 Introduction/images/wsl/wsl_ubuntu_get.png -------------------------------------------------------------------------------- /Linux/01 Introduction/images/operating-systems/os.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/Linux/01 Introduction/images/operating-systems/os.jpeg -------------------------------------------------------------------------------- /Linux/01 Introduction/images/wsl/windows_terminal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/Linux/01 Introduction/images/wsl/windows_terminal.png -------------------------------------------------------------------------------- /Linux/01 Introduction/images/wsl/wsl_ubuntu_launch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/Linux/01 Introduction/images/wsl/wsl_ubuntu_launch.png -------------------------------------------------------------------------------- /Linux/01 Introduction/images/wsl/wsl_ubuntu_download.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/Linux/01 Introduction/images/wsl/wsl_ubuntu_download.png -------------------------------------------------------------------------------- /Linux/01 Introduction/images/wsl/wsl_ubuntu_userpass.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/Linux/01 Introduction/images/wsl/wsl_ubuntu_userpass.png -------------------------------------------------------------------------------- /Linux/01 Introduction/images/linux-terminal/pwd-command.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/Linux/01 Introduction/images/linux-terminal/pwd-command.png -------------------------------------------------------------------------------- /Linux/01 Introduction/images/operating-systems/mac-os.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/Linux/01 Introduction/images/operating-systems/mac-os.jpeg -------------------------------------------------------------------------------- /Linux/01 Introduction/images/operating-systems/windows.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/Linux/01 Introduction/images/operating-systems/windows.jpeg -------------------------------------------------------------------------------- /Linux/01 Introduction/images/wsl/windows_terminal_tabs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/Linux/01 Introduction/images/wsl/windows_terminal_tabs.png -------------------------------------------------------------------------------- /Linux/01 Introduction/images/linux-terminal/linux-terminal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/Linux/01 Introduction/images/linux-terminal/linux-terminal.png -------------------------------------------------------------------------------- /Linux/01 Introduction/images/linux-terminal/mac-terminal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/Linux/01 Introduction/images/linux-terminal/mac-terminal.png -------------------------------------------------------------------------------- /Linux/01 Introduction/images/linux-terminal/open_terminal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/Linux/01 Introduction/images/linux-terminal/open_terminal.png -------------------------------------------------------------------------------- /Linux/01 Introduction/images/operating-systems/mobile-os.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/Linux/01 Introduction/images/operating-systems/mobile-os.jpeg -------------------------------------------------------------------------------- /Linux/01 Introduction/images/operating-systems/os-types.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/Linux/01 Introduction/images/operating-systems/os-types.jpeg -------------------------------------------------------------------------------- /Linux/01 Introduction/images/operating-systems/os_process.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/Linux/01 Introduction/images/operating-systems/os_process.jpg -------------------------------------------------------------------------------- /Linux/01 Introduction/images/operating-systems/ibm_first_pc.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/Linux/01 Introduction/images/operating-systems/ibm_first_pc.jpeg -------------------------------------------------------------------------------- /Linux/01 Introduction/images/linux-fundamentals/linux-terminal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/Linux/01 Introduction/images/linux-fundamentals/linux-terminal.png -------------------------------------------------------------------------------- /Linux/01 Introduction/images/wsl/windows_terminal_customization.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/Linux/01 Introduction/images/wsl/windows_terminal_customization.png -------------------------------------------------------------------------------- /Linux/01 Introduction/images/operating-systems/batch-operating-system.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/Linux/01 Introduction/images/operating-systems/batch-operating-system.png -------------------------------------------------------------------------------- /Linux/01 Introduction/images/linux-fundamentals/ubuntu-install-software.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/Linux/01 Introduction/images/linux-fundamentals/ubuntu-install-software.png -------------------------------------------------------------------------------- /Linux/01 Introduction/images/operating-systems/types-of-operating-system.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/Linux/01 Introduction/images/operating-systems/types-of-operating-system.png -------------------------------------------------------------------------------- /Linux/01 Introduction/images/operating-systems/os-definition-and-functions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/Linux/01 Introduction/images/operating-systems/os-definition-and-functions.png -------------------------------------------------------------------------------- /Linux/01 Introduction/images/linux-fundamentals/gnu-linux-distribution-timeline.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/Linux/01 Introduction/images/linux-fundamentals/gnu-linux-distribution-timeline.png -------------------------------------------------------------------------------- /Linux/01 Introduction/images/linux-fundamentals/ubuntu-install-software-terminal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pytopia/Linux/HEAD/Linux/01 Introduction/images/linux-fundamentals/ubuntu-install-software-terminal.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Linux 2 | 3 | 4 | logo 5 | 6 | [Pytopia](https://www.pytopia.ai) Linux Course Material (for Python and Data Science purposes). Including: 7 | 8 | 9 | - Linux Fundametals 10 | - Linux Terminal 11 | - Linux File Systems 12 | - Bash Shell Scripting 13 | 14 | To register for the courses, visit the [Pytopia Website](https://www.pytopia.ai/). 15 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 PyTopia 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Linux/02 Linux File System/06. Copying, Moving, Renaming.md: -------------------------------------------------------------------------------- 1 | # Copying, Moving, Renaming 2 | 3 | ## Copy 4 | The `cp` command which handles all the copying of files and folders in Linux with `cp source_file dest` for files and `cp source_dir dest_dir` for directories. 5 | 6 | ```bash 7 | $user@computer-name:~$ cp file1.txt /home/user/file_1_copy.txt 8 | $user@computer-name:~$ cp -r dir_1 dir_1_copy 9 | ``` 10 | 11 | ## Rename 12 | ```bash 13 | $user@computer-name:~$ mv file1.txt file_renamed.txt 14 | ``` 15 | 16 | ## Move 17 | ```bash 18 | $user@computer-name:~$ mv file1.txt dest 19 | ``` 20 | 21 | For directories, add `-r` option: 22 | ```bash 23 | $user@computer-name:~$ mv -r dir dir_renamed 24 | $user@computer-name:~$ mv -r dir dest/dir 25 | ``` 26 | 27 | You can use wildcards: 28 | Move everything in `dir` to desktop: 29 | ```bash 30 | $user@computer-name:~$ mv -r dir/* /home/user/Desktop 31 | ``` 32 | 33 | ## Summary 34 | - `cp ` 35 | - `mv ` 36 | - `mv ` 37 | - **Create** using `touch` and `mkdir` commands. 38 | - **Delete** using the `rm` and `rmdir` commands. 39 | - **Copy** using the `cp` command. 40 | - **Move** and Rename using the `mv` command. -------------------------------------------------------------------------------- /Linux/04 Bash Shell Scripting/06. Comparison.md: -------------------------------------------------------------------------------- 1 | # Comparison 2 | 3 | In this section, we are going to learn some basics of numeric and string bash shell comparisons. Using comparisons, we can compare strings ( words, sentences ) or integer numbers whether raw or as variables. The following table lists rudimentary comparison operators for both numbers and strings: 4 | 5 | |Description|Numeric Comparison|String Comparison| 6 | |:--|:--|:--| 7 | |less than|`-lt`|`<`| 8 | |greater than|`-gt`|`>`| 9 | |equal|`-eq`|`=`| 10 | |not equal|`-ne`|`!=`| 11 | |less or equal|`-le`|N/A| 12 | |greater or equal|`-ge`|N/A| 13 | 14 | Next, we use square brackets and numeric comparison operators to perform the actual evaluation. Using echo $? command, we check for a return value of the previously executed evaluation. There or two possible outcomes for every evaluation, true or false. If the return value is equal to 0, then the comparison evaluation is true. However, if the return value is equal to 1, the evaluation resulted as false. 15 | 16 | ```bash 17 | string_a="UNIX" 18 | string_b="GNU" 19 | 20 | echo "Are $string_a and $string_b strings equal?" 21 | [ $string_a = $string_b ] 22 | echo $? 23 | 24 | num_a=100 25 | num_b=100 26 | 27 | echo "Is $num_a equal to $num_b ?" 28 | [ $num_a -eq $num_b ] 29 | echo $? 30 | ``` 31 | 32 | Apart from the educational value, the above script does not serve any other purpose. Comparisons operations will make more sense once we learn about conditional statements like `if/else`. Conditional statements will be covered in the next chapter, and this is where we put comparison operations to better use. 33 | -------------------------------------------------------------------------------- /Linux/02 Linux File System/02. File Extensions.md: -------------------------------------------------------------------------------- 1 | # File Extensions 2 | In linux, file extensions don't matter. Linux doesn't determine file type. Using the file extension but instead it reads a piece of code inserted at the top of every file and that piece of code is known as a header and it serves as a kind of label for Linux to read and when Linux reads that label it knows the file type. 3 | 4 | In linux, `file` command will tell us basically what type of file we are dealing with. 5 | 6 | ```bash 7 | $user@computer-name:~$ file image.png 8 | image.PNG: PNG image data, 1913 x 1086, 8-bit/color RGBA, non-interlaced 9 | 10 | $user@computer-name:~$ file document.txt 11 | document.txt: UTF-8 Unicode text 12 | 13 | $user@computer-name:~$ file document.txt 14 | document.txt: UTF-8 Unicode text 15 | 16 | $user@computer-name:~$ file myfolder 17 | myfolder: directory 18 | ``` 19 | 20 | So changing just the name of the file won't make a difference because that file header won't have changed. 21 | 22 | Although the operating system will know what file format the actual file is by reading the header, The extra programs that are installed on top of the operating system such as this PDA viewer are trying to open the files that might require a certain formats or the file extensions in order to work. 23 | 24 | The important distinction to make there the programs that are installed on top of the operating system such as PDF viewers and the fact that they might need the file to have a specific file extension in order to open them but the operating system itself does not care. 25 | 26 | ## Summary 27 | - Use the `file` command to know what type of file you are dealing with. 28 | - You can name files whatever you want in linux (even `.blahblah`). 29 | - Try not to confuse third party softwares. -------------------------------------------------------------------------------- /Linux/04 Bash Shell Scripting/04. Redirection.md: -------------------------------------------------------------------------------- 1 | # Input, Output and Error Redirections 2 | 3 | Normally commands executed on GNU/Linux command line either produce output, require input or throw an error message. This is a fundamental concept for shell scripting as well as for working with GNU/Linux's command line in general. 4 | 5 | Every time, you execute a command, three possible outcomes might happen. The first scenario is that the command will produce an expected output, second, the command will generate an error, and lastly, your command might not produce any output at all. 6 | 7 | Back to our `backup.sh` script. When executing our backup script, you may have noticed an extra message display by tar command: 8 | 9 | ```bash 10 | tar: Removing leading `/' from member names 11 | ``` 12 | 13 | Despite the message's informative nature, it is sent to **stderr** descriptor. In a nutshell, the message is telling us that the absolute path has been removed thus extraction of the compressed file not overwrite any existing files. 14 | 15 | Now that we have a basic understanding of the output redirection we can eliminate this unwanted **stderr** message by redirecting it with `2>` notation to `/dev/null`. Imagine `/dev/null` as a data sink, which discards any data redirected to it. For more information run `man null`. Below is our new `backup.sh` version including tar's **stderr** redirection: 16 | 17 | ```bash 18 | #!/bin/bash 19 | 20 | # This bash script is used to backup a user's home directory to /tmp/. 21 | 22 | user=$(whoami) 23 | input=/home/$user 24 | output=/tmp/${user}_home_$(date +%Y-%m-%d_%H%M%S).tar.gz 25 | 26 | tar -czf $output $input 2> /dev/null 27 | echo "Backup of $input completed! Details about the output backup file:" 28 | ls -l $output 29 | ``` 30 | 31 | After executing a new version of our backup.sh script, no tar stderr message will be displayed. 32 | 33 | -------------------------------------------------------------------------------- /Linux/03 Linux Advanced/04. Command Input & Output.md: -------------------------------------------------------------------------------- 1 | # Command Input & Output 2 | 3 | The ways **data** flows **into** and **out** of a **command**. 4 | 5 | Be ready to connect commands. 6 | 7 | ![command-in-out](../images/command_in_out.png) 8 | 9 | Standard output is something called a standard data stream just like a stream of water data stream start somewhere and they end somewhere. **So where does standard output lead?** 10 | 11 | Well **by default** standard output will lead to your terminal. So that's why when we type commands the output of the command appears on the screen. 12 | 13 | The amazing thing about output data streams is that you can **redirect** where they go using a process imaginative imaginatively called redirection. 14 | 15 | Similarly, standard input is a data stream and is by default connected to the keyboard. So it can be redirected as well. 16 | 17 | That makes them so powerful you can simply pass the standard output stream from one command to the standard input stream of another then pass the standard output stream of that second command to the standard input stream of the third command and so on and so on until you build up a very powerful pipeline connecting outputs to inputs in this way is known as **piping** together commands and it's an incredibly important concept in Linux as it's what makes working with the command line so powerful and effective. 18 | 19 | 20 | ## Summary 21 | - There are two ways to get data into commands and two ways to get data out. 22 | 1. Command line arguments 23 | 3. Standard Input 24 | 2. Standard Output 25 | 4. Standard Error 26 | - Standard Input, Standard Output, and Standard Error are Standard Data Streams. 27 | - Data streams can be redirected from their default locations to wherever you wish. 28 | - You can redirect the standard output of one command to the standard input of another in a process know as **piping**. 29 | -------------------------------------------------------------------------------- /Linux/03 Linux Advanced/05. Redirection.md: -------------------------------------------------------------------------------- 1 | # Redirection 2 | - You will be able to **redirect the standard data streams**. 3 | 4 | But by the end, you'll be able to redirect standard input standard output and standard error to your heart's content and you'll feel much more like a computer genius already. 5 | 6 | ## Examples 7 | - `cat`: `cat` needs standard input in order to run but because standard input is by default connected to the keyboard cat just sits there and waits for us to enter something on the keyboard. 8 | - `cat 1> output.txt`: Every data stream not only has a name like standard outputs and imports on that, but it also has a number associated with it. 9 | - Standard Input is number zero. 10 | - Standard output is number one. 11 | - Standard error is number two. 12 | 13 | Here, we are redirecting or changing the destination of standard output because standard output is number one. 14 | 15 | - `cat -k bla 2> error.txt`: Redirect standard error data stream to error.txt 16 | - `cat 0< input.txt 1> output.txt 2> error.txt` 17 | 18 | **Notes:** 19 | - You don't actually even need to put the number 1 in `cat 1> output.txt` (default for output: 1). 20 | - You don't actually even need to put the number 0 in `cat 0< input.txt`> (default for input: 0). 21 | - Use two arrows to write to a file again using redirection without truncating it (`cat 1>> output.txt`) 22 | 23 | ## Summary 24 | - Standard input, standard output, and standard error are data streams. 25 | - Using redirection you can control where those streams **flow**. 26 | - Standard Input: 0 27 | - Standard Output: 1 28 | - Standard Error: 2 29 | - `>` will overwrite a file before writing it. 30 | - `>>` will append to what's already there. 31 | 32 | **Read More**: 33 | - [Redirections](https://www.gnu.org/software/bash/manual/html_node/Redirections.html) 34 | - [BashGuide/InputAndOutput](http://mywiki.wooledge.org/BashGuide/InputAndOutput?#Redirection) -------------------------------------------------------------------------------- /Linux/02 Linux File System/05. Deleting File and Directories.md: -------------------------------------------------------------------------------- 1 | # Deleting File and Directories 2 | 3 | The way to actually delete or remove that file is using something called the `rm` command. 4 | 5 | ## Delete Files 6 | ```bash 7 | $user@computer-name:~$ rm file1.txt 8 | $user@computer-name:~$ rm file2.txt file2.txt /home/user/file3.txt 9 | $user@computer-name:~$ rm file*.txt # deletes with wildcard 10 | $user@computer-name:~$ rm *[2,3]* # deletes everything 11 | $user@computer-name:~$ rm *.png # deletes all .png files 12 | $user@computer-name:~$ rm * # deletes everything 13 | ``` 14 | 15 | ## Delete Directories 16 | To delete directories, you have to add `-r` option: 17 | ```bash 18 | $user@computer-name:~$ rm dir1 19 | rm: cannot remove 'dir/': Is a directory 20 | $user@computer-name:~$ rm -r dir1 21 | ``` 22 | 23 | ```bash 24 | $user@computer-name:~$ touch delme/deleteme{1,2,3}/file{1,2,3} 25 | $user@computer-name:~$ rm -r delme 26 | ``` 27 | 28 | **Note:** To ask shell to prompt before every removal, add `-i` option. 29 | ```bash 30 | $user@computer-name:~$ touch delme/deleteme{1,2,3}/file{1,2,3} 31 | $user@computer-name:~$ rm -ri delme 32 | rm: descend into directory 'delme'? 33 | rm: descend into directory 'delme/deleteme1'? 34 | rm: remove directory 'delme/deleteme1/file1'? 35 | ... 36 | ``` 37 | 38 | Fortunately there's another command that specialized for only removing directories that are empty now because this command only removes empty directories. This means that you can tell it to delete everything. It will only delete the folders that are actually empty. Which means you'll never delete a file accidentally. 39 | 40 | ```bash 41 | $user@computer-name:~$ rmdir delme 42 | rmdir: failed to remove 'delme': Directory not empty 43 | ``` 44 | 45 | To remove everything inside `delme` that is empty directory: 46 | ```bash 47 | $user@computer-name:~$ rmdir delme/* 48 | rmdir: failed to remove 'delme': Directory not empty 49 | ``` 50 | 51 | ## Summary 52 | - The `rm` command needs `-r` option to delete folders (Be careful!). 53 | - The `i` option will allow the `rm` command to be **interactive** when deleting. 54 | - The `rmdir` command will only delete folders that are empty. 55 | -------------------------------------------------------------------------------- /Linux/04 Bash Shell Scripting/07. Conditional Statement.md: -------------------------------------------------------------------------------- 1 | # Conditional Statement 2 | 3 | Now, it is time to give our backup script some logic by including few conditional statements. Conditionals allow the programmer to implement decision making within a shell script based on certain conditions or events. 4 | 5 | The conditionals we are referring to are of course, `if`, `then` and `else`. For example, we can improve our backup script by implementing a sanity check to compare the number of files and directories within a source directory we intend to backup and the resulting backup file. The pseudocode for this kind of implementation will read as follows: 6 | 7 | Let's start by creating a simple bash script depicting a basic `if/then/else` construct. 8 | 9 | ```bash 10 | #!/bin/bash 11 | 12 | num_a=100 13 | num_b=200 14 | 15 | if [ $num_a -lt $num_b ]; then 16 | echo "$num_a is less than $num_b!" 17 | fi 18 | ``` 19 | 20 | For now the `else` conditional was deliberately left out, we will include it once we understand the logic behind the above script. Save the script as, eg. `if_else.sh` and execute it: 21 | 22 | Lines 3-4 are used to initialize an integer variables. On Line 6 we begin an if conditional block. We further compare both variables and if the comparison evaluation yields true, then on Line 7 the echo command will inform us, that the value within the variable `$num_a` is less when compared with the variable `$num_b`. Lines 8 closes our `if` conditional block with a `fi` keyword. 23 | 24 | The important observation to make from the script execution is that, in the situation when the variable `$num_a` greater than `$num_b` our script fails to react. This is where the last piece of the puzzle, `else` conditional comes in handy. Update your script by adding else block and execute it: 25 | 26 | ```bash 27 | #!/bin/bash 28 | 29 | num_a=400 30 | num_b=200 31 | 32 | if [ $num_a -lt $num_b ]; then 33 | echo "$num_a is less than $num_b!" 34 | else 35 | echo "$num_a is greater than $num_b!" 36 | fi 37 | ``` 38 | The Line 8 now holds the `else` part of our conditional block. If the comparison evaluation on Line 6 reports `false` the code below `else` statement, in our case Line 9 is executed. 39 | 40 | -------------------------------------------------------------------------------- /Linux/03 Linux Advanced/07. Aliases.md: -------------------------------------------------------------------------------- 1 | # Aliases 2 | 3 | Linux users often need to use one command over and over again. Typing or copying the same command again and again reduces your productivity and distracts you from what you are actually doing. 4 | 5 | You can save yourself some time by creating **aliases** for your most used commands. **Aliases** are like custom shortcuts used to represent a command (or set of commands) executed with or without custom options. Chances are you are already using aliases on your Linux system. 6 | 7 | ## List Currently Defined Aliases in Linux 8 | You can see a list of defined aliases on your profile by simply executing `alias` command. 9 | 10 | ![alias](../images/alias.png =500x) 11 | 12 | ## How to Create Aliases in Linux 13 | 14 | Creating aliases is relatively easy and quick process. You can create two types of aliases – temporary ones and permanent. We will review both types. 15 | 16 | ### Creating Temporary Aliases 17 | What you need to do is type the word alias then use the name you wish to use to execute a command followed by "=" sign and quote the command you wish to alias. 18 | 19 | `alias shortName="your custom command here"` 20 | 21 | For example: 22 | `alias ls="ls -l"` 23 | 24 | ### Creating Permanent Aliases 25 | 26 | To keep aliases between sessions, you can save them in your user’s shell configuration profile file. This can be: 27 | 28 | ``` 29 | Bash – ~/.bashrc 30 | ZSH – ~/.zshrc 31 | Fish – ~/.config/fish/config.fish 32 | ``` 33 | 34 | The syntax you should use is practically the same as creating a temporary alias. The only difference comes from the fact that you will be saving it in a file this time. So for example, in bash, you can open `.bashrc` file with your favorite editor like this: 35 | 36 | `code ~/.bashrc` 37 | 38 | Find a place in the file, where you want to keep the aliases. For example, you can add them in the end of the file. For organizations purposes you can leave a comment before your aliases something like this: 39 | 40 | ``` 41 | # my custom aliases 42 | alias home="ssh -i ~/.ssh/mykep.pem tecmint@192.168.0.100" 43 | alias ll="ls -alF" 44 | ``` 45 | 46 | **Note:** If you are using [zsh](https://linuxhint.com/install_zsh_shell_ubuntu_1804/), then you should open `~/.zshrc` file. 47 | 48 | 49 | ## Summary 50 | 51 | - An alias is a custom nickname for a command or pipeline. 52 | - aliases are accessible when you restart your terminal. 53 | -------------------------------------------------------------------------------- /Linux/04 Bash Shell Scripting/02. Script Execution.md: -------------------------------------------------------------------------------- 1 | # Script Execution 2 | 3 | Next, let's talk about an alternative way on how to run bash scripts. In a highly simplistic view, a bash script is nothing else just a text file containing instructions to be executed in order from top to bottom. How the instructions are interpreted depends on defined shebang or the way the script is executed. 4 | 5 | Another way to execute bash scripts is to call bash interpreter explicitly eg. `$ bash date.sh`, hence executing the script without the need to make the shell script executable and without declaring shebang directly within a shell script. By calling bash executable binary explicitly, the content of our file `date.sh` is loaded and interpreted as Bash Shell Script. 6 | 7 | ## Hello World Bash Shell Script 8 | 9 | Now, it is time to write our first, most basic bash shell script. The whole purpose of this script is nothing else but print "Hello World" using `echo` command to the terminal output. Using any text editor create a new file named `hello-world.sh` containing the below code: 10 | 11 | ```bash 12 | #!/bin/bash 13 | 14 | echo "Hello World" 15 | ``` 16 | 17 | Once ready, make your script executable with thechmod command and execute it using relative path `./hello-world.sh`: 18 | 19 | ```bash 20 | $ chmod +x hello-world.sh 21 | $ linuxconfig.org:~$ ./hello-world.sh 22 | Hello World 23 | ``` 24 | 25 | ## Simple Backup Bash Shell Script 26 | Let's discuss a command line execution and how GNU/Linux commands fit into the shell script creation process in more detail. 27 | 28 | Any command which can be successfully executed directly via bash shell terminal can be in the same form used as part of bash shell script. In fact, there is no difference between command execution directly via terminal or within a shell script apart from the fact that the shell script offers non-interactive execution of multiple commands as a single process. 29 | 30 | The next example offers more practical application as it can be used to backup our user home directory. To create the backup script, we will be using `tar` command with various options `-czf` in order to create a compressed tar ball of entire user home directory `/home/linuxconfig/`. Insert the following code into a new file called `backup.sh`, make the script executable and run it: 31 | 32 | ```bash 33 | #!/bin/bash 34 | 35 | tar -czf /tmp/myhome_directory.tar.gz /home/linuxconfig 36 | ``` -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | 131 | # Custom gitignore 132 | .DS_Store -------------------------------------------------------------------------------- /Linux/02 Linux File System/04. Creating Files and Directories.md: -------------------------------------------------------------------------------- 1 | # Creating Files and Directories 2 | 3 | You're going to learn how to use the `touch` and the `mkdir` are commands to create files and directories. 4 | 5 | ## `touch` 6 | `touch` command can create new empty files. 7 | 8 | ```bash 9 | $user@computer-name:~$ touch file1.txt 10 | $user@computer-name:~$ touch /home/user/file1.txt 11 | ``` 12 | 13 | You can directly create file and put contents in it with `echo`: 14 | ```bash 15 | $user@computer-name:~$ echo "Hello World!" > hello.txt 16 | ``` 17 | 18 | ## `mkdir` 19 | The `mkdir` command in Linux/Unix allows users to create or make new directories. `mkdir` stands for **make directory** 20 | 21 | ```bash 22 | $user@computer-name:~$ mkdir newfolder 23 | $user@computer-name:~$ touch /home/user/newfolder 24 | ``` 25 | 26 | Let's say I wanted to create `dir1/dir2/dir3`. OK but I can't go ahead and make that in one go because it is going to give us an error and it's going to say that the folder doesn't exist. 27 | 28 | This is because the shell tried to go to `dir1` then `dir2`, and then create `dir3`. 29 | 30 | You can make this work by adding `-p` option: 31 | ```bash 32 | $user@computer-name:~$ mkdir -p dir1/dir2/dir3 33 | ``` 34 | 35 | **Note:** Try to avoid having spaces in directory/file names. It is a nightmare in linux. Instead use `_`. If you insist on having spaces, use quotations: 36 | ```bash 37 | $user@computer-name:~$ mkdir "new folder" 38 | ``` 39 | 40 | ## Brace Expansion 41 | Brace expansion is a mechanism by which arbitrary strings may be generated. 42 | 43 | So let's say that you're working on a big five year project and every month you need to write a 100 memo files to keep track of the project and the folder should be named something like _Jan 2017_, _FEB 2017_, _March 2017, and so on and so on for five years. 44 | 45 | How can you create those files and folders up front? 46 | 47 | Well doing it graphically would be horrific. There's actually just no way around it. 48 | 49 | We're going to use a powerful feature of the shell known as **Brace Expansion**. 50 | 51 | We create all these directories in `project` directory: 52 | ```bash 53 | $user@computer-name:~$ mkdir project 54 | $user@computer-name:~$ cd prject 55 | $user@computer-name:~$ mkdir {jan,feb,mar,apr,may,jun,july,aug,sep,oct,nov,dec}_{2017,2018,2019,2020,2021,2022} 56 | ``` 57 | 58 | You can then create `file1.txt` to `file100.txt` in each directory. 59 | ```bash 60 | $user@computer-name:~$ touch {jan,feb,mar,apr,may,jun,july,aug,sep,oct,nov,dec}_{2017,2018,2019,2020,2021,2022}/file{1..100}.txt 61 | ``` 62 | 63 | Brace expansion isn't only possible for the `touch` and `mkdir` commands. It's actually usable across the whole shelf. 64 | ```bash 65 | $user@computer-name:~$ ls {jan,feb,mar,apr,may,jun,july,aug,sep,oct,nov,dec}_{2017,2018} 66 | ``` 67 | -------------------------------------------------------------------------------- /Linux/04 Bash Shell Scripting/08. Loops.md: -------------------------------------------------------------------------------- 1 | # Loops 2 | 3 | So far our backup script functions as expected and its usability has been substantially increased in comparison with the initial code introduced at the beginning of this scripting tutorial. We can now easily backup any user directory by pointing the script to user's home directory using positional parameters during the script's execution. 4 | 5 | The trouble only arises when we need to backup multiple user directories on a daily basis. Hence this task will very quickly become tedious and time-consuming. At this stage, it would be great to have the means to backup any number of selected user home directories with a single backup.sh script execution. 6 | 7 | Fortunately, bash has us covered, as this task can be accomplished by use of loops. Loops are looping constructs used to iterate through any given number of tasks until all items in a specified list were completed or predefined conditions were met. There are three basic loop types available to our disposal. 8 | 9 | ## For Loop 10 | 11 | For loop is used to iterate through any given code for any number of supplied items in the list. Let's start with a simple for loop example: 12 | 13 | ```bash 14 | for i in 1 2 3; do echo $i; done 15 | ``` 16 | 17 | The above for loop has used the echo command to print all items 1, 2 and 3 in the list. Using a semicolon allows us to execute for loop on a single command line. If we were to transfer the above for loop into a bash script, the code would look like follows: 18 | 19 | ```bash 20 | #!/bin/bash 21 | 22 | for i in 1 2 3; do 23 | echo $i 24 | done 25 | ``` 26 | 27 | The for loop consists of four Shell Reserved Words: `for`, `in`, `do`, `done`. The above code can therefore also be read as: FOReach item INlist 1, 2 and 3 assign each item temporarily into a variable `i` after which DO `echo $i` in order to print the item as `STDOUT` and keep printing until all items INthe list are DONE. 28 | 29 | Printing numbers is undoubtedly fun but let's try something more meaningful instead. Using command substitution as explained earlier in this tutorial we can create any kind of list to be a part of for loop construct. The following slightly more sophisticated for loop example will count characters of each line for any given file: 30 | 31 | ```bash 32 | for i in $(cat items.txt); do 33 | echo -n $i | wc -c; 34 | done 35 | ``` 36 | 37 | ## While Loop 38 | 39 | he next loop construct on our list is while loop. This particular loop acts on a given condition. Meaning, it will keep executing code enclosed withing DOand DONEwhile the specified condition is true. Once the specified condition becomes false, the execution will stop. Consider the following example: 40 | 41 | ```bash 42 | #!/bin/bash 43 | counter=0 44 | while [ $counter -lt 3 ]; do 45 | let counter+=1 46 | echo $counter 47 | done 48 | ``` 49 | -------------------------------------------------------------------------------- /Linux/02 Linux File System/07. Nano Editor.md: -------------------------------------------------------------------------------- 1 | # Nano Editor 2 | 3 | When getting used to the command-line, Linux novices are often put off by other, more advanced text editors such as vim and emacs. While they are excellent programs, they do have a bit of a learning curve. Enter Nano, an easy-to-use text editor that proves itself versatile and simple. Nano is installed by default in Ubuntu and many other Linux distros and works well in conjunction with sudo, which is why we love it so much. 4 | 5 | ## Running Nano 6 | ```bash 7 | nano diary.txt 8 | ``` 9 | 10 | You'll notice that our terminal has changed its look and we're actually now editing a file called diry that takes tape as you can see at the top. 11 | 12 | Down the bottom you can see that there's actually a little toolbar that tells you some of the things that you can do in nano and the options are in the white squares and then in the form of keyboard shortcuts. Hit **Ctrl+G** to bring up the Help documentation and scroll down to see a list of valid shortcuts. When you’re done looking at the list, hit **Ctrl+X** to exit help. 13 | 14 | nano 15 | 16 | In nano The little arrowhead that you see here the little hat or the carrot symbol means the control key on your keyboard. 17 | 18 | - **Write Out**: Save the file (press enter afterwards). 19 | - **Read File**: Insert another file content. 20 | - **Where Is**: Search in the file. 21 | 22 | If we had down to the bottom of the files if we shift down here and use `control + W` again you can see down the bottom that there are actually other options that pop up as well. 23 | 24 | ## Copying, Cutting, and Pasting 25 | Now some of these options begin with the the carrot symbol the heart which means the control key but some start with this `M-` which stands for modify and this is usually the alt key on your keyboard. For example **M-C**: **Alt+C** is to change case-sensitive for searching. 26 | 27 | - **Replace**: Replace words or phrases with something else. 28 | - **Cut**: You can cut a part of text that is highlighted. 29 | - **Paste Text** 30 | 31 | If you want to remove an entire line of text, simply hit Ctrl+K without highlighting anything. This sometimes comes in handy when editing configuration files. 32 | 33 | ## Quit 34 | 35 | When you want to quit nano, you just hit **Ctrl+X**. Nano will politely ask you if you want to save your buffer, and you can cancel this action as well. 36 | 37 | **Notes:** 38 | 39 | - `Ctrl+z` sends the program to the background. Use `fg %num` to bring job number `num` back to the foreground. 40 | - To show line numbers, use `nano diary.txt -l`. 41 | 42 | nano-l 43 | 44 | 45 | 46 | ## Summary 47 | - nano is a command line based text editor. 48 | - `^`: Ctrl 49 | - `M-`: Alt, Esc, or cmd (depending on your layout) 50 | - nano's configuration file is `/etc/nanorc` 51 | -------------------------------------------------------------------------------- /Linux/03 Linux Advanced/01. Command Structure.md: -------------------------------------------------------------------------------- 1 | # Command Structure 2 | 3 | By the end: Commands will begin to look like a langauge not random gibberish. 4 | 5 | Right now each command has its own unique behavior. You can actually look up using something called the manual pages which I'll show you how to do later. 6 | 7 | But the general command structure goes like this. 8 | 1. you type out the command name. So it would be like `date` or `echo`. 9 | 2. Then you give the comments of options to customize its behavior. 10 | 3. Then you give the command some inputs to actually operate on. 11 | 12 | --> `command_name -options inputs` 13 | 14 | ## Command Name 15 | 16 | Now the first thing you type is the command name. Now that lets the shell know what program you actually want to run. And once the Shell knows what program you want to run it knows the name of the program you want to run the show will then search for that program on something called your Shell's path which is just a list of folders that contain these programs. 17 | 18 | Now you can actually see your Shell's path by typing `echo $PATH`. So what the shell will do is it'll start at the very left of the path and it will look inside that folder for a command called `echo`. If it's not found, it will do the same on the next folder and so on and so forth. 19 | 20 | **Note**: If two programs with the same name are in different folders of `$PATH`, the one in the far left folder will always run. 21 | 22 | 23 | Now you can actually see which folder the command is stored in by using the `which` command: 24 | - `which cal` --> `/usr/bin/cal` 25 | - `which date` --> `/usr/bin/date` 26 | 27 | Now you can customize the way that commands work by giving them different **options** and different **inputs**. 28 | 29 | ## Inputs 30 | It's important to note that not all commands actually require inputs. Some inputs are optional. For example the date command doesn't strictly require an input. 31 | 32 | **Note**: Because commands **operate** on the input the input is sometimes called an **operand**. 33 | 34 | So for example if we take the cow command I could just type cow OK and press enter and I would get this month's calendar. But to customize the behavior I can give it one or more inputs: `cal 2021`, `cal 12 2017` 35 | 36 | ## Options 37 | 38 | That's common for commands to be preceded by dashes and hyphens and things: `cal -y`, `date -u` (UTC time) 39 | 40 | So sometimes options actually have long form names proceded by `--`: `date --universal` 41 | 42 | **Note:** The long form commands can make commands easier to read but they're not available for all options. It really depends upon the command that you're using. 43 | 44 | Now the only other thing to know is that sometimes options can have their own inputs. For example there is an option that will allow us to see a certain amount of months after a time: 45 | - `cal -A 1 12 2017` --> 1 month after (`-A`) December (12) 2017 46 | - `cal -B 1 12 2017` --> 1 month before (`-B`) December (12) 2017 47 | - `cal -A 1 -B 1 12 2017` --> 1 month after (`-A`) and before (`-B`) December (12) 2017 48 | 49 | ## Summary 50 | - Command: `command_name -options inputs` 51 | - Command name must be on the shell's **search path** (`$PATH`). 52 | - Commands operate on inputs. 53 | - Options modify command's behaviour 54 | -------------------------------------------------------------------------------- /Linux/02 Linux File System/01. Navigating the File System.md: -------------------------------------------------------------------------------- 1 | # Navigating the File System 2 | 3 | ## Where are we? 4 | The first thing we'd like to know when navigating the system is where we currently are. 5 | 6 | And the shell already tells us this with **shell prompt** and the shell prompt is everything up to the dollar sign. 7 | 8 | ```bash 9 | $user@computer-name:~$ 10 | ``` 11 | First of all it tells you the user who is logged in which is `user` on this computer. Then you have the name of the computer which is `computer-name`. 12 | 13 | And then you `~` that's called Tilda which is a short way of representing the current user's home directory. 14 | 15 | We can actually confirm at any time what directory or what location our shell is currently operating in but using the `pwd` command and the `pwd` command stands for **print working directory**. 16 | 17 | ```bash 18 | $user@computer-name:~$ pwd 19 | /home/user 20 | ``` 21 | 22 | The path starts all the way from the root directory the very base directory which is the `/` and works its way down until we get to the home directory for the user `user` which is the current user logged in. 23 | 24 | ## How to Navigate 25 | Now that we know where we are and we know that our shell is operating inside of our home folder how can we take a look around and see what's in the home folder? 26 | 27 | ### `ls` 28 | We need to use the `ls` command now the `ls` is short for the list and the `ls` command will list of files in a directory. 29 | 30 | |Command|Description| 31 | |:--|:--| 32 | |`ls`|List of files/directories in a directory| 33 | |`ls -F`|List files/directories with classification (directories appear with `/` at the end)| 34 | |`ls -l`|List of files/directories in **long format**| 35 | |`ls -lh`|List of files/directories in **human readable** long format (4096 will appear as 4K)| 36 | |`ls -a`|List of **all** (including hidden) files/directories| 37 | 38 | **Note:** Hidden files/directories start with a dot: `.` 39 | 40 | List of files/directories in long format: 41 | ![ls-l](../images/ls-l.jpg) 42 | 43 | ### `cd` 44 | How can we actually move from our home directory? 45 | 46 | The missing piece is the `cd` command and the `cd` command stands for **change directory**. 47 | ```bash 48 | user@computer ~ % cd /home/user/Downloads 49 | user@computer ~/Downloads % # directory is changed to ~/Downloads 50 | ``` 51 | 52 | **Note:** 53 | - You can use **full path** (start at the base `/` directory such as `/home/user/`) or **relative path** (start at the current directory such as `./user`). 54 | - `.` means the current directory. 55 | - `..` means the parent folder or the folder above where we currently are. 56 | - `cd .` stays in the same directory. 57 | - `cd ..` changes directory to the parent directory. 58 | - Press tab for auto completion. For example type `cd ~/Do` and press tab to receive two suggestions. 59 | ```bash 60 | user@computer ~ % cd /home/user/Do 61 | Downloads Documents 62 | ``` 63 | 64 | ## Summary 65 | - You can use `pwd` command to see the path to where on the file system the shell is currently operating. 66 | - You use `ls` to see what's around you. 67 | - You can use the `cd` command to move to a new location on the file system. 68 | - **Absolute Path** start at the base (`/`) directory. 69 | - **Relative Path** start from the current directory. 70 | - Every directory has the `.` (current directory) and `..` (parent directory) hidden folders. 71 | - **Tab Auto Completion** is a really usefull technique to speed up typing and avoid errors. 72 | - Tab auto completion can be used **anywhere**, not just when navigating. 73 | -------------------------------------------------------------------------------- /Linux/04 Bash Shell Scripting/03. Variables.md: -------------------------------------------------------------------------------- 1 | # Variables 2 | 3 | Variables are the essence of programming. Variables allow a programmer to store data, alter and reuse them throughout the script. Create a new script `welcome.sh` with the following content: 4 | 5 | ```bash 6 | #!/bin/bash 7 | 8 | greeting="Welcome" 9 | user=$(whoami) 10 | day=$(date +%A) 11 | 12 | echo "$greeting back $user! Today is $day, which is the best day of the entire week!" 13 | echo "Your Bash shell version is: $BASH_VERSION. Enjoy!" 14 | ``` 15 | 16 | By now you should possess all required skills needed to create a new script, making it executable and running it on the command line. After running the above welcome.sh script, you will see an output similar to the one below: 17 | 18 | ```bash 19 | $ ./welcome.sh 20 | Welcome back linuxconfig! Today is Wednesday, which is the best day of the entire week! 21 | Your Bash shell version is: 4.4.12(1)-release. Enjoy! 22 | ``` 23 | 24 | Let's look at the script more closely. First, we have declared a variable `greeting` and assigned a string value `Welcome` to it. The next variable `user` contains a value of user name running a shell session. This is done through a technique called command substitution. Meaning that the output of the `whoami` command will be directly assigned to the user variable. The same goes for our next variable `day` which holds a name of today's day produced by `date +%A` command. 25 | 26 | The second part of the script utilises the `echo` command to print a message while substituting variable names now prefixed by `$` sign with their relevant values. In case you wonder about the last variable used `$BASH_VERSION` know that this is a so called internal variable defined as part of your shell. 27 | 28 | **Note:** Never name your private variables using UPPERCASE characters. This is because uppercase variable names are reserved for internal shell variables, and you run a risk of overwriting them. This may lead to the dysfunctional or misbehaving script execution. 29 | 30 | Variables can also be used directly on the terminal's command line. The following example declares variables `a` and `b` with integer data. Using `echo` command, we can print their values or even perform an arithmetic operation as illustrated by the following example: 31 | 32 | ```bash 33 | a=4 34 | b=8 35 | echo $a 36 | echo $b 37 | echo $[$a + $b] 38 | ``` 39 | 40 | Now that we have bash variable introduction behind us we can update our backup script to produce more meaningful output file name by incorporating a date and time when the backup on our home directory was actually performed. 41 | 42 | Furthermore, the script will no longer be bind to a specific user. From now on our `backup.sh` bash script can be run by any user while still backing up a correct user home directory: 43 | 44 | ```bash 45 | #!/bin/bash 46 | 47 | # This bash script is used to backup a user's home directory to /tmp/. 48 | 49 | user=$(whoami) 50 | input=/home/$user 51 | output=/tmp/${user}_home_$(date +%Y-%m-%d_%H%M%S).tar.gz 52 | 53 | tar -czf $output $input 54 | echo "Backup of $input completed! Details about the output backup file:" 55 | ls -l $output 56 | ``` 57 | 58 | You may have already noticed that the above script introduces two new bash scripting concepts. Firstly, our new `backup.sh` script contains comment line. Every line starting with # sign except shebang will not be interpreted by bash and will only serve as a programmer's internal note. 59 | 60 | Secondly, the script uses a new shell scripting trick `${parameter}` called parameter expansion. In our case, curly braces `{}` are required because our variable `$user` is followed by characters which are not part of its variable name. 61 | 62 | -------------------------------------------------------------------------------- /Linux/04 Bash Shell Scripting/01. Introduction.md: -------------------------------------------------------------------------------- 1 | # Introduction 2 | 3 | ## Definition 4 | 5 | - Bash 6 | 7 | Bash is a command language interpreter. It is widely available on various operating systems and is a default command interpreter on most GNU/Linux systems. The name is an acronym for the ‘Bourne-Again SHell’. 8 | 9 | - Shell 10 | 11 | Shell is a macro processor which allows for an interactive or non-interactive command execution. 12 | 13 | - Scripting 14 | 15 | Scripting allows for an automatic commands execution that would otherwise be executed interactively one-by-one. 16 | 17 | ## Bash Shell Script Basics 18 | 19 | ### What is Shell 20 | 21 | Most likely, your are at the moment sitting in front of your computer, have a terminal window opened and wondering: "What should I do with this thing?" 22 | 23 | Well, the terminal window in front of you contains shell, and shell allows you by use of commands to interact with your computer, hence retrieve or store data, process information and various other simple or even extremely complex tasks. 24 | 25 | Try it now! Use your keyboard and type some commands such as date, cal, pwd or ls followed by the `ENTER` key. 26 | 27 | What you have just done, was that by use of commands and shell you interacted with your computer to retrieve a current date and time (`date`), looked up a calendar (`cal`), checked the location of your current working directory (`pwd`) and retrieved a list of all files and directories located within (`ls`). 28 | 29 | ### What is Scripting 30 | 31 | Now, imagine that the execution of all the above commands is your daily task. Every day you are required to execute all of the above commands without fail as well as store the observed information. Soon enough this will become an extremely tedious task destined for failure. Thus the obvious notion is to think of some way to execute all given commands together. This is where scripting becomes your salvation. 32 | 33 | To see what is meant by scripting, use shell in combination with your favorite text editor eg. `vi` to create a new file called `task.sh` containing all the above commands, each on a separate line. Once ready, make your new file executable using chmod command with an option `+x`. Lastly, execute your new script by prefixing its name with `./`. 34 | 35 | As you can see, by use of scripting, any shell interaction can be automated and scripted. Furthermore, it is now possible to automatically execute our new shell script `task.sh` daily at any given time by use of cron time-based job scheduler and store the script's output to a file every time it is executed. However, this is a tale for an another day, for now let's just concentrate on a task ahead. 36 | 37 | ### What is Bash 38 | 39 | So far we have covered shell and scripting. What about Bash? Where does the bash fit in? As already mentioned, the bash is a default interpreter on many GNU/Linux systems, thus we have been using it even without realising. This is why our previous shell script works even without us defining bash as an interpreter. To see what is your default interpreter execute command `echo $SHELL`: 40 | 41 | ```bash 42 | $ echo $SHELL 43 | /bin/bash 44 | ``` 45 | 46 | There are various other shell interpreters available, such as Korn shell, C shell and more. From this reason, it is a good practice to define the shell interpreter to be used explicitly to interpret the script's content. 47 | 48 | To define your script's interpreter as Bash, first locate a full path to its executable binary using `which` command, prefix it with a [shebang](https://en.wikipedia.org/wiki/Shebang_%28Unix%29) `#!` and insert it as the first line of your script. There are various other techniques how to define shell interpreter, but this is a solid start. 49 | 50 | From now, all our scripts will include shell interpreter definition #!/bin/bash. 51 | -------------------------------------------------------------------------------- /Linux/03 Linux Advanced/06. Piping.md: -------------------------------------------------------------------------------- 1 | # Piping 2 | 3 | What if you wanted to connect the standard output of one command so that it flowed into the standard input of another command? Well that's where **piping** comes. 4 | 5 | Each Linux command is designed to do one task extremely well. So if you can continually pipe these highly specialized commands together and pass data between them, you can build advanced pipelines to do pretty much any task that you can think of. 6 | 7 | **piping is all about connecting standard output of one command to standard input of another command.** 8 | 9 | ## Example 10 | For example if you want to get the weekday from date command, this is one way to do it: 11 | 1. `date > date.txt` 12 | 2. `cut < date.txt --delimiter " " --fields 1` 13 | 14 | It's very cool command but this this works but it's kind of clunky. OK first we're writing the standard output of the date command to a file which takes up space on our computer. Right then we have to read that file into the command. 15 | - A lot more typing. 16 | - Makes unnecessary files. 17 | - Inefficient and awkward. 18 | 19 | So instead we can pipe the standard output of the data command directly into the standard input of the cut command. 20 | - `date | cut --delimiter " " --fields 1` 21 | 22 | Or you can send the standard output to a file: 23 | - `date | cut --delimiter " " --fields 1 > today.txt` 24 | - `date | cut > today.txt --delimiter " " --fields 1` 25 | - `date | cut --delimiter " " > today.txt --fields 1` 26 | 27 | Send the data from the command into yet another command (multiple piping): 28 | - `date | cut --delimiter " " --fields 1 | command -options args` 29 | 30 | Remember the data can't really go two places at once. For example, piping is broken here and only date standard output is stored in `date.txt`: 31 | - `date > date.txt | cut --delimiter " " --fields 1` 32 | 33 | ## `tee` Command 34 | `tee` - read from standard input and write to standard output and files. 35 | 36 | How can we go about actually saving this information into a file but at the same time also pass it down into the pipeline? 37 | 38 | ![tee command](../images/tee.png =300x) 39 | 40 | - `date | tee fulldate.txt | cut --delimiter " " --fields 1` 41 | 42 | You can also send the standard output to a file: 43 | - `date | tee fulldate.txt | cut --delimiter " " --fields 1 > today.txt` 44 | - `date | tee fulldate.txt | cut --delimiter " " --fields 1 | tee today.txt` 45 | 46 | By `tee` command, you can actually pass data through your pipeline but also take snapshots of the data as it flows through and save those snapshots into a file. 47 | 48 | The `tee` command is really useful because by doing normal redirection you break your pipeline but by using the command you can save data but still keep your pipeline flowing. 49 | 50 | ## `xarg` Command 51 | What do you think will happen if I take the date command and pipe that into Echo? 52 | - `date | echo` 53 | 54 | this is a common mistake actually that people make when using pipelines for the first time they try to pipe things into Echo. 55 | **`echo` doesn't accept standard input.** 56 | 57 | the key is to convert the data from standard input into command line arguments so the command can continue to work like normal. 58 | 59 | - `date | xargs echo` 60 | - `date | xargs echo "hello world"` 61 | - `date | cut --delimiter " " --fields | xargs echo` 62 | 63 | `rm` is another command that delets files and directories: 64 | - `rm file` 65 | - `rm -r directory` 66 | 67 | Now create a file that contains two file names and name it `filestodelete.txt`. 68 | ``` 69 | file_1.txt 70 | file_2.txt 71 | ``` 72 | 73 | This does not work to delete files: 74 | - `cat filestodelete.txt | rm` 75 | 76 | But this workds: 77 | - `cat filestodelete.txt | xargs rm` 78 | 79 | It's as if we run this command: 80 | - `rm file_1.txt file_2.txt` 81 | 82 | ## Summary 83 | - Piping connects **STDOUT** of one command to **STDIN** of another. 84 | - Redirection of **STDOUT** breaks pipelines. 85 | - To save a data snapshot without breaking pipelines, use the `tee` command. 86 | - If a command does not accept **STDIN**, but you want to pipt to it, use `xargs`. 87 | - Command you use with `xargs` can still have their own arguments. 88 | -------------------------------------------------------------------------------- /Linux/02 Linux File System/03. Wildcards.md: -------------------------------------------------------------------------------- 1 | # Wildcards 2 | Wild cards are very useful tools that will make your commands a lot more precise a lot more expressive and a lot more powerful. 3 | 4 | We're going to learn about the most common types of wildcards. 5 | 6 | ## `*` (Asterisk) 7 | This can represent any number of characters (including zero, in other words, zero or more characters). 8 | 9 | For example, `ls` command will list the contents of every directory that we give it a valid path to. 10 | 11 | But what if we wanted to have a look at what's inside our documents folder our downloads folder and our Pictures folder at the same time? 12 | 13 | ```bash 14 | $user@computer-name:~$ ls Documents/ Downloads/ 15 | Documents/: 16 | file1.txt file2.txt file3.txt 17 | 18 | Downloads/: 19 | file1.txt 20 | ``` 21 | 22 | But you can see how manual of a process this was. 23 | 24 | Now wildcards are basically special symbols that the shell interprets to have a special meaning. The idea behind wildcards is to build up powerful patterns known as regular expressions so that instead of typing out every command line argument manually you can instead say something like hey linux make this command act on anything that matches this pattern. 25 | 26 | And then one of the most used wildcards is the asterisk or the star wildcard. **Star wildcard matches anything.** 27 | ```bash 28 | $user@computer-name:~$ ls D* 29 | Documents/: 30 | file1.txt file2.txt file3.txt 31 | 32 | Downloads/: 33 | file1.txt 34 | ``` 35 | and `ls *` will match everything and will show the contents of all directories. 36 | 37 | **Note:** Wildcards are case sensitive. So `ls D*` and `ls d*` will have different results. 38 | 39 | If you want to list all text file: 40 | ```bash 41 | $user@computer-name:~$ ls *.txt 42 | file1.txt file2.txt file3.txt file4.txt file5.txt 43 | ``` 44 | 45 | ## `?` (Question Mark) 46 | This can represent any single character. If you specified something at the command line like `hd?` GNU/Linux would look for `hda`, `hdb`, `hdc` and every other letter/number between `a-z`, `0-9`. 47 | 48 | ```bash 49 | $user@computer-name:~$ ls ???e.txt 50 | file1.txt file2.txt file3.txt file4.txt file5.txt 51 | ``` 52 | 53 | ## `[]` (Square Brackets) 54 | Specifies a range. If you did `m[a,o,u]m` it can become: `mam`, `mum`, `mom` if you did: `m[a-d]m` it can become anything that starts and ends with `m` and has any character `a` to `d` inbetween. For example, these would work: `mam`, `mbm`, `mcm`, `mdm`. This kind of wildcard specifies an **or** relationship (you only need one to match). 55 | 56 | ```bash 57 | $user@computer-name:~$ ls file[1-3].txt 58 | file1.txt file2.txt file3.txt 59 | $user@computer-name:~$ ls file[245].txt 60 | file2.txt file4.txt file5.txt 61 | $user@computer-name:~$ ls file[0-9][0-9].txt 62 | file11.txt 63 | ``` 64 | 65 | **Note:** You can have combinations of capital letters, numbers, etc. such as `file[a-zA-Z0-9].txt` 66 | 67 | ## `{}` (Curly Brackets) 68 | Terms are separated by commas and each term must be the name of something or a wildcard. This wildcard will copy anything that matches either wildcard(s), or exact name(s) (an `or` relationship, one or the other). 69 | 70 | For example, `ls {*.txt,*.png}` matches all files with either `.txt` or `.png` extension. 71 | ```bash 72 | $user@computer-name:~$ ls {*.txt,*.png} 73 | file1.txt file2.txt file3.txt file4.txt file5.txt image1.png image2.png image3.png 74 | ``` 75 | 76 | ## `\` (backslash) 77 | Is used as an **escape** character, i.e. to protect a subsequent special character. Thus, `\\` searches for a backslash. Note you may need to use quotation marks and backslash(es). 78 | 79 | ## `[^]` 80 | This construct is similar to the [ ] construct, except rather than matching any characters inside the brackets, it'll match any character, as long as it is not listed between the [ and ]. This is a logical NOT. For example `rm myfile[^9]` will remove all `myfiles*` (ie. `myfiles1`, `myfiles2` etc) but won't remove a file with the number 9 anywhere within it's name. 81 | 82 | ```bash 83 | $user@computer-name:~$ ls file[^2].txt 84 | file1.txt file3.txt file4.txt file5.txt 85 | $user@computer-name:~$ ls file[^2-4].txt 86 | file1.txt file5.txt 87 | ``` 88 | 89 | ## Summary 90 | - Wildcards are used to build patterns called "regular expression" 91 | - Anything that matches the pattern will be passed as a command line argument to a command. 92 | - Covered wildcards: 93 | - `*` 94 | - `?` 95 | - `[]` 96 | - `{}` 97 | - `[^]` -------------------------------------------------------------------------------- /Linux/02 Linux File System/09. Viewing Files.md: -------------------------------------------------------------------------------- 1 | # Viewing Files 2 | 3 | Linux provides a number of commands for viewing files. In this tutorial, we’ll look at the most commonly used `cat`, `more` and `less` commands. 4 | 5 | ## `cat` 6 | The cat command is the simplest way to view the contents of a file. It displays the contents of the file(s) specified on to the output terminal. 7 | 8 | ```bash 9 | cat file.txt 10 | ``` 11 | Sometimes, we might want to number the lines in the output. 12 | 13 | We can do this by using the -n option: 14 | ``` 15 | cat -n file.txt 16 | ``` 17 | 18 | You can concatenate many files and display them: 19 | ```bash 20 | cat file_1.txt file_2.txt 21 | ``` 22 | 23 | ## `tac` and `rev` 24 | `tac` is the reverse version of `cat` horizontally (linewise) meaning that the last line will be displayed first and the first line last. 25 | ```bash 26 | tac file.txt 27 | ``` 28 | 29 | `rev` is the reverse version of `cat` vertically (characterwise) meaning that the last character will be displayed first and the first character last. 30 | ```bash 31 | tac file.txt 32 | ``` 33 | 34 | 35 | 36 | ## `more` 37 | The `cat` command is all well and good for small files. But, if the file is large, the contents will zoom past and we’ll only see the last screen worth of content. 38 | 39 | The `more` command displays the contents of the file one screen at a time for large files. If the contents of the file fit a single screen, the output will be the same as the `cat` command. 40 | 41 | ``` 42 | more large-file.txt 43 | ``` 44 | The cursor will stay at the end of this text. Then, we can scroll through the contents of the file using the **Enter** key, one line at a time. 45 | 46 | We can also scroll through the file page by page by using the **Space bar**. And to scroll back to the previous page, we can use the b key. We’ll use the `q` key to go back to the command prompt. 47 | 48 | The more command can also be used to view multiple files. We just have to list each of them one after another: 49 | 50 | ```bash 51 | more file.txt large-file.txt 52 | ``` 53 | 54 | Along with files, we can also pipe the more command with the output of other commands: 55 | ```bash 56 | find . | more 57 | ls -l | more 58 | ``` 59 | 60 | Let’s suppose we want to view only a certain number of lines at a time. We can do this by specifying the number of lines as an option: 61 | 62 | ```bash 63 | more -5 large-file.txt 64 | ``` 65 | This will display the first 5 lines of the file instead of a screen worth of content. 66 | 67 | We can also specify the line number in the file from where we want to start viewing the content: 68 | ```bash 69 | more +5 file.txt 70 | ``` 71 | 72 | ## `less` 73 | Now, let’s move to the less command. The less command is similar to the more command but provides extensive features. Since it does not read the entire file before starting, it starts up faster compared to text editors — especially when we’re viewing large files. 74 | 75 | ```bash 76 | less file.txt 77 | ``` 78 | 79 | Read more: [more-vs-less](More and Less Differences) 80 | 81 | ## `head` and `tail` 82 | As their names imply, the `head` command will output the first part of the file, while the `tail` command will print the last part of the file. Both commands write the result to standard output. 83 | 84 | ```bash 85 | head file.txt 86 | tail file.txt 87 | ``` 88 | With the `-n` option, we can let the head command output the first `n` lines instead of the default `10`. 89 | ```bash 90 | # first 3 lines 91 | head -n 3 file.txt 92 | 93 | # last 3 lines 94 | head -n -3 file.txt 95 | 96 | # last 3 lines 97 | tail -n -3 file.txt 98 | tail -n 3 file.txt 99 | ``` 100 | 101 | Use the head and the tail Together to show lines 5, 6, and 7. 102 | ```bash 103 | head -n 7 file.txt | tail -n 3 104 | ``` 105 | 106 | ## Sorting Data 107 | Sort file alphabetically 108 | ```bash 109 | sort file.txt 110 | 111 | # reverse sort 112 | sort -r file.txt 113 | sort file.txt | tac 114 | ``` 115 | 116 | Sort file numerically: 117 | ```bash 118 | sort -n file.txt 119 | sort -nr file.txt 120 | ``` 121 | 122 | Sort and get unique results only: 123 | ```bash 124 | sort -u file.txt 125 | sort -nu file.txt 126 | ``` 127 | 128 | ### Sort by the Column 129 | You can sort tabular data using the `-k` option: 130 | ```bash 131 | # sort the second column alphabeticall 132 | ls -l | sort -k 2 133 | 134 | # sort the second column numerically 135 | ls -l | sort -k 2n 136 | 137 | # sort the second column numerically but in reverse order 138 | ls -l | sort -k 2nr 139 | 140 | # sort the fifth column in human readable format 141 | ls -l | sort -k 5h 142 | 143 | # sort by month 144 | ls -lh / | sort -k 6M 145 | ``` 146 | 147 | **Note:** 148 | - 2nr means sort using column `3` and use the `-n` and `-r` options. 149 | - To sort human-readable data use the `-h` option not `-n`. 150 | - To sort month data use the `-M` option. 151 | -------------------------------------------------------------------------------- /Linux/03 Linux Advanced/02. Linux Manual.md: -------------------------------------------------------------------------------- 1 | # Linux Manual 2 | 3 | Like we saw each of the Linux commands is implemented slightly differently and they behave slightly differently. 4 | 5 | So other than memorizing a jillion different implementations of things how can we actually know how to use each of the Linux commands properly. Well the answer is to use the manual pages known as **man pages** for sure. 6 | 7 | ## Manual Structure 8 | 9 | Manual is broken up into eight sections and each of these sections deals with a specific type of thing. 10 | 11 | |Section|Contains|Description|Example| 12 | |:--|:--|:--|:--| 13 | |1|User Commands|commands that can just be run from the shell by any regular user. You don't need any particular administration privileges or any root privileges to be able to run these|`date`, `cal`| 14 | |2|System Calls|this contains programming functions that can be used within an application that you write to make calls to the Linux kernel which is a very low level part of the operating system|| 15 | |3|C Library Functions|hese are libraries for the C programming language and these are functions and libraries that provide interfaces to specific things on your computer such as graphical user interfaces or other libraries that you might want to use if you're writing some C code that you want to have access to your computer with|| 16 | |4|Devices and Special Files|This is about how the different device is on your computer are managed. So things such as CD drives or things such as random number generators or things such as U.S. ports and stuff like that.|| 17 | |5|File Formats and Conventions|It's about all the different formats and the conventions of specific files and on your computer. So you know formats for word documents or formats where PDA documents a format for specific configuration files.|| 18 | |6|Games|Any games that are installed on your computer they have their own section and different commands.|| 19 | |7|Miscellaneous|More miscellaneous stuff more Uncategorized stuff. So it's usually stuff like protocols or file systems and information about those.|| 20 | |8|System Administration|All the commands that can actually that actually require root privileges and administration privileges to be run on your computers this is things like changing passwords. This is things like you know really editing important stuff on your computer setting up automation and things like that.|| 21 | 22 | 23 | **Note:** Section 1 Section 5 and section 8 are what you will likely use most often. 24 | 25 | ## Search Manual 26 | 27 | You would have to use the `man` command that a `man` command is short for the word manual. And it's the command that deals with everything to do with the manual basically: `man -k search_term` 28 | - `man -k which` 29 | - `man -k ls` 30 | - ... 31 | 32 | To see the manual for a command: `man command`: 33 | - `man which` 34 | - `man ls` 35 | - ... 36 | 37 | Example of a man page: `man which` 38 | 39 | ``` 40 | WHICH(1) General Commands Manual WHICH(1) NAME which - locate a command SYNOPSIS which [-a] filename ... DESCRIPTION which returns the pathnames of the files (or links) which would be exe‐ cuted in the current environment, had its arguments been given as com‐ mands in a strictly POSIX-conformant shell. It does this by searching the PATH for executable files matching the names of the arguments. It does not canonicalize path names. OPTIONS -a print all matching pathnames of each argument 41 | EXIT STATUS 42 | 0 if all specified commands are found and executable 1 if one or more specified commands is nonexistent or not executable 2 if an invalid option is specified 43 | ``` 44 | 45 | **Note**: in manual pages: 46 | - Anything inside `<>` is **mandatory**. 47 | - Anything inside `[]` is **optional** 48 | - For example: 49 | - in `which [-a] `, `-a` is optional but `something` is mandatory. 50 | - in `ls [OPTION]... [FILE]...` everything is optional and only ls is mandatory. 51 | 52 | - `|` inside `[]` means `or` which means you have to pick one of them not both. For example in `[-a | -f]` using `-af` is invalid 53 | 54 | ## -------------------------------------------------------------------------------- /Linux/04 Bash Shell Scripting/05. Functions.md: -------------------------------------------------------------------------------- 1 | # Functions 2 | 3 | It is possible to avoid using functions and write any script without including a single function in it. However, you are likely to end up with a chunky, inefficient and hard to troubleshoot code. 4 | 5 | You can think of the function as a way to the group number of different commands into a single command. This can be extremely useful if the output or calculation you require consists of multiple commands, and it will be expected multiple times throughout the script execution. Functions are defined by using the function keyword and followed by function body enclosed by curly brackets. 6 | 7 | The syntax for declaring a bash function is straightforward. Functions may be declared in two different formats: 8 | 9 | 1. The first format starts with the function name, followed by parentheses. This is the preferred and more used format. 10 | ```bash 11 | function_name () { 12 | commands 13 | } 14 | ``` 15 | 16 | Single line version: 17 | ```bash 18 | function_name () { commands; } 19 | ``` 20 | 21 | 2. The second format starts with the reserved word `function`, followed by the function name. 22 | 23 | ```bash 24 | function function_name { 25 | commands 26 | } 27 | ``` 28 | 29 | Single line version: 30 | ```bash 31 | function function_name { commands; } 32 | ``` 33 | 34 | - The commands between the curly braces (`{}`) are called the body of the function. The curly braces must be separated from the body by spaces or newlines. 35 | - Defining a function doesn’t execute it. To invoke a bash function, simply use the function name. Commands between the curly braces are executed whenever the function is called in the shell script. 36 | - The function definition must be placed before any calls to the function. 37 | - When using single line “compacted” functions, a semicolon `;` must follow the last command in the function. 38 | - Always try to keep your function names descriptive. 39 | 40 | ## Function with Input 41 | To call a function with arguments: 42 | 43 | ```bash 44 | function_name "$arg1" "$arg2" 45 | ``` 46 | 47 | The function refers to passed arguments by their position (not by name), that is $1, $2, and so forth. $0 is the name of the script itself. 48 | 49 | ```bash 50 | foo 1 # this will fail because foo has not been declared yet. 51 | 52 | foo() { 53 | echo "Parameter #1 is $1" 54 | } 55 | 56 | foo 2 # this will work. 57 | ``` 58 | 59 | ## Return Output 60 | Bash functions, unlike functions in most programming languages do not allow you to return a value to the caller. When a bash function ends its return value is its status: zero for success, non-zero for failure. To return values, you can set a global variable with the result, or use command substitution, or you can pass in the name of a variable to use as the result variable. The examples below describe these different mechanisms. 61 | 62 | 1. The simplest way to return a value from a bash function is to just set a global variable to the result. Since all variables in bash are global by default this is easy: 63 | 64 | ```bash 65 | function myfunc() 66 | { 67 | myresult='some value' 68 | } 69 | 70 | myfunc 71 | echo $myresult 72 | ``` 73 | The code above sets the global variable myresult to the function result. Reasonably simple, but as we all know, using global variables, particularly in large programs, can lead to difficult to find bugs. 74 | 75 | 2. A better approach is to use local variables in your functions. The problem then becomes how do you get the result to the caller. One mechanism is to use command substitution: 76 | 77 | ```bash 78 | function myfunc() 79 | { 80 | local myresult='some value' 81 | echo "$myresult" 82 | } 83 | 84 | result=$(myfunc) # or result=`myfunc` 85 | echo $result 86 | ``` 87 | Here the result is output to the stdout and the caller uses command substitution to capture the value in a variable. The variable can then be used as needed. 88 | 89 | ```bash 90 | function myfunc() 91 | { 92 | local __resultvar=$1 93 | local myresult='some value' 94 | eval $__resultvar="'$myresult'" 95 | } 96 | 97 | myfunc result 98 | echo $result 99 | ``` 100 | 101 | ## Example 102 | The following example defines a simple shell function to be used to print user details and will make two function calls, thus printing user details twice upon a script execution. 103 | 104 | The function name is `user_details`, and function body enclosed inside curly brackets consists of the group of two `echo` commands. Every time a function call is made by using the function name, both `echo` commands within our function definition are executed. It is important to point out that the function definition must precede function call, otherwise the script will return `function not found` error: 105 | 106 | ```bash 107 | #!/bin/bash 108 | 109 | funciton user_detail { 110 | echo "User Name: $(whoami)" 111 | echo "Home Directory: $HOME" 112 | } 113 | ``` 114 | 115 | As illustrated by the above video example the `user_details` function grouped multiple commands in a single new command `user_details`. 116 | 117 | The `echo` commands within the `user_details` function definition were deliberately shifted one TAB right which makes our code more readable, easier to troubleshot. 118 | 119 | 120 | -------------------------------------------------------------------------------- /Linux/01 Introduction/05 Linux Command Structure.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "b1fad908-d76b-49f9-accf-2e4033b2edd5", 6 | "metadata": {}, 7 | "source": [ 8 | "" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "id": "52265cc4-8e0c-47fb-944a-8579462cf517", 14 | "metadata": {}, 15 | "source": [ 16 | "# Linux Command Structure \n" 17 | ] 18 | }, 19 | { 20 | "cell_type": "markdown", 21 | "id": "0aa7bdf7-85e6-4376-ad53-647d130f8032", 22 | "metadata": {}, 23 | "source": [ 24 | "## Table of Contents \n", 25 | "* [Opening a terminal](#opening_a_terminal)\n", 26 | "* [A sense of location](#a_sense_of_location)\n", 27 | "* [Relative and absolute paths](#relative_and_absolute_paths)\n", 28 | "\n", 29 | "---" 30 | ] 31 | }, 32 | { 33 | "cell_type": "markdown", 34 | "id": "4143afbe-2bb9-4347-8397-ea9ba0f2cdae", 35 | "metadata": {}, 36 | "source": [ 37 | "By the end of this section, ommands will begin to look like a langauge not random gibberish." 38 | ] 39 | }, 40 | { 41 | "cell_type": "markdown", 42 | "id": "f71a24ad-2083-4ac9-89cf-c77169e9b1db", 43 | "metadata": {}, 44 | "source": [ 45 | "Right now each command has its own unique behavior. You can actually look up using something called the manual pages which I'll show you how to do later." 46 | ] 47 | }, 48 | { 49 | "cell_type": "markdown", 50 | "id": "c2aa9391-43e6-4886-b6be-2cfa86e948c6", 51 | "metadata": {}, 52 | "source": [ 53 | "But the general command structure goes like this.\n", 54 | "1. You type out the command name. So it would be like `date` or `echo`.\n", 55 | "2. Then you give the comments of options to customize its behavior.\n", 56 | "3. Then you give the command some inputs to actually operate on." 57 | ] 58 | }, 59 | { 60 | "cell_type": "markdown", 61 | "id": "b73b0186-5ae8-4b61-baf7-5eeeb053f414", 62 | "metadata": {}, 63 | "source": [ 64 | "```bash\n", 65 | "command_name -options inputs\n", 66 | "```" 67 | ] 68 | }, 69 | { 70 | "cell_type": "markdown", 71 | "id": "307d1598-5162-4801-a5bd-bd1d01104cc5", 72 | "metadata": {}, 73 | "source": [ 74 | "## Command Name" 75 | ] 76 | }, 77 | { 78 | "cell_type": "markdown", 79 | "id": "a68b9a85-39f9-438c-ab42-731386eb1e89", 80 | "metadata": {}, 81 | "source": [ 82 | "Now the first thing you type is the command name. Now that lets the shell know what program you actually want to run. And once the Shell knows what program you want to run it knows the name of the program you want to run the show will then search for that program on something called your Shell's path which is just a list of folders that contain these programs." 83 | ] 84 | }, 85 | { 86 | "cell_type": "markdown", 87 | "id": "a3c5e5f7-e49e-4af0-af2c-a561ad7bdd48", 88 | "metadata": {}, 89 | "source": [ 90 | "Now you can actually see your Shell's path by typing `echo $PATH`. So what the shell will do is it'll start at the very left of the path and it will look inside that folder for a command called `echo`. If it's not found, it will do the same on the next folder and so on and so forth." 91 | ] 92 | }, 93 | { 94 | "cell_type": "markdown", 95 | "id": "f34d4914-0b81-4bf8-9be8-8c79f619618b", 96 | "metadata": {}, 97 | "source": [ 98 | "**Note**: If two programs with the same name are in different folders of `$PATH`, the one in the far left folder will always run." 99 | ] 100 | }, 101 | { 102 | "cell_type": "markdown", 103 | "id": "170030de-0959-4c7a-9de2-79208645ccf4", 104 | "metadata": {}, 105 | "source": [ 106 | "Now you can actually see which folder the command is stored in by using the `which` command:\n", 107 | "- `which cal` --> `/usr/bin/cal`\n", 108 | "- `which date` --> `/usr/bin/date`" 109 | ] 110 | }, 111 | { 112 | "cell_type": "markdown", 113 | "id": "2d6d5c5a-015e-473e-a4d3-ce3107a5ecd0", 114 | "metadata": {}, 115 | "source": [ 116 | "Now you can customize the way that commands work by giving them different **options** and different **inputs**." 117 | ] 118 | }, 119 | { 120 | "cell_type": "markdown", 121 | "id": "edd9e67c-624a-4771-8ac5-177dcd00d597", 122 | "metadata": {}, 123 | "source": [ 124 | "## Inputs" 125 | ] 126 | }, 127 | { 128 | "cell_type": "markdown", 129 | "id": "af5daa1d-cef2-4a3c-9c6b-eb25aa8cffe8", 130 | "metadata": {}, 131 | "source": [ 132 | "It's important to note that not all commands actually require inputs. Some inputs are optional. For example the date command doesn't strictly require an input.\n", 133 | "\n", 134 | "**Note**: Because commands **operate** on the input the input is sometimes called an **operand**.\n", 135 | "\n", 136 | "So for example if we take the cow command I could just type cow OK and press enter and I would get this month's calendar. But to customize the behavior I can give it one or more inputs: `cal 2021`, `cal 12 2017`" 137 | ] 138 | }, 139 | { 140 | "cell_type": "markdown", 141 | "id": "17219fec-c8b6-47c4-87aa-ae0566318dd9", 142 | "metadata": {}, 143 | "source": [ 144 | "## Options" 145 | ] 146 | }, 147 | { 148 | "cell_type": "markdown", 149 | "id": "1c7f0954-36c8-476f-aff5-bc0022746a45", 150 | "metadata": {}, 151 | "source": [ 152 | "That's common for commands to be preceded by dashes and hyphens and things: `cal -y`, `date -u` (UTC time)\n", 153 | "\n", 154 | "So sometimes options actually have long form names proceded by `--`: `date --universal`\n", 155 | "\n", 156 | "**Note:** The long form commands can make commands easier to read but they're not available for all options. It really depends upon the command that you're using.\n", 157 | "\n", 158 | "Now the only other thing to know is that sometimes options can have their own inputs. For example there is an option that will allow us to see a certain amount of months after a time:\n", 159 | "- `cal -A 1 12 2017` --> 1 month after (`-A`) December (12) 2017\n", 160 | "- `cal -B 1 12 2017` --> 1 month before (`-B`) December (12) 2017\n", 161 | "- `cal -A 1 -B 1 12 2017` --> 1 month after (`-A`) and before (`-B`) December (12) 2017" 162 | ] 163 | }, 164 | { 165 | "cell_type": "markdown", 166 | "id": "f3346acc-013f-4753-be96-6e017ac82e54", 167 | "metadata": {}, 168 | "source": [ 169 | "## Summary\n", 170 | "- Command: `command_name -options inputs`\n", 171 | "- Command name must be on the shell's **search path** (`$PATH`).\n", 172 | "- Commands operate on inputs.\n", 173 | "- Options modify command's behaviour" 174 | ] 175 | } 176 | ], 177 | "metadata": { 178 | "kernelspec": { 179 | "display_name": "Python 3", 180 | "language": "python", 181 | "name": "python3" 182 | }, 183 | "language_info": { 184 | "codemirror_mode": { 185 | "name": "ipython", 186 | "version": 3 187 | }, 188 | "file_extension": ".py", 189 | "mimetype": "text/x-python", 190 | "name": "python", 191 | "nbconvert_exporter": "python", 192 | "pygments_lexer": "ipython3", 193 | "version": "3.8.11" 194 | } 195 | }, 196 | "nbformat": 4, 197 | "nbformat_minor": 5 198 | } 199 | -------------------------------------------------------------------------------- /Linux/02 Linux File System/10. Search File Content.md: -------------------------------------------------------------------------------- 1 | # Search File Content 2 | One of the renowned search tool on Unix-like systems which can be used to search for anything whether it be a file, or a line or multiple lines in file is `grep` utility. It is very vast in functionality which can be attributed to the large number of options it supports like: searching using string pattern, or reg-ex pattern or perl based reg-ex etc. 3 | 4 | `grep` is a command-line utility for searching plain-text data sets for lines that match a regular expression. Its name comes from the `ed` command `g/re/p` (globally search for a regular expression and print matching lines), which has the same effect. 5 | 6 | Due its varying functionalities, it has many variants including `grep`, `egrep` (Extended GREP), `fgrep` (Fixed GREP), `pgrep` (Process GREP), `rgrep` (Recursive GREP) etc. But these variants have minor differences to original grep which has made them popular and to be used by various Linux programmers for specific tasks. 7 | 8 | ## `grep` 9 | `grep` or Global Regular Expression Print is the main search program on Unix-like systems which can search for any type of string on any file or list of files or even output of any command. 10 | 11 | ### Command Examples 12 | Below is some standard grep command explained with examples to get you started with grep on Linux, macOS, and Unix: 13 | 14 | 1. Search any line that contains the _word_ in filename on Linux: `grep 'word' filename` 15 | 2. Perform a case-insensitive search for the word _bar_ in Linux and Unix: `grep -i 'bar' file1` 16 | 3. Look for all files in the current directory and in all of its subdirectories in Linux for the word _httpd_: `grep -R 'httpd' .` 17 | 4. Search and display the total number of matching lines that the string _nixcraft_ appears in a file named `frontpage.md`: `grep -c 'nixcraft' frontpage.md` 18 | 19 | ### Syntax 20 | The syntax is as follows: 21 | ```bash 22 | grep 'word' filename 23 | fgrep 'word-to-search' file.txt 24 | grep 'word' file1 file2 file3 25 | grep 'string1 string2' filename 26 | cat otherfile | grep 'something' 27 | command | grep 'something' 28 | command option1 | grep 'data' 29 | grep --color 'data' fileName 30 | grep [-options] pattern filename 31 | fgrep [-options] words file 32 | ``` 33 | 34 | ### How to use grep recursively 35 | You can search recursively i.e. read all files under each directory for a string hello 36 | 37 | ```bash 38 | grep -r "hello" . 39 | grep -R "hello" . 40 | ``` 41 | 42 | grep -r 43 | 44 | The inclusion of the file names in the output data can be suppressed by using the `-h` option as follows: 45 | grep -r -h 46 | 47 | ### Search Words Only 48 | When you search for _he_, `grep` will match _he_, _hello_, _she_ and more. You can force the grep command to select only those lines containing matches that form whole words i.e. match only _he_ word: 49 | 50 | ```bash 51 | grep -w "boo" file 52 | ``` 53 | 54 | ### Invert Match 55 | You can use `-v` option to print inverts the match; that is, it matches only those lines that do not contain the given word. For example print all line that do not contain the word `hello`: 56 | 57 | ```bash 58 | grep -v hello file.txt 59 | ``` 60 | 61 | ### Count Line When Word is Matched 62 | The grep can report the number of lines that the pattern has been matched for each file using `-c` (count) option: 63 | ```bash 64 | grep -c 'word' /path/to/file 65 | ``` 66 | 67 | Pass the `-n` option to precede each line of output with the number of the line in the text file from which it was obtained: 68 | ```bash 69 | grep -n 'hello' file.txt 70 | ``` 71 | 72 | For example, display cpu model name: 73 | ```bash 74 | cat /proc/cpuinfo | grep -i 'Model' 75 | ``` 76 | 77 | However, above command can be also used as follows without shell pipe: 78 | ```bash 79 | grep -i 'Model' /proc/cpuinfo 80 | ``` 81 | 82 | ### Colors Option 83 | Finally, we can force grep to display output in colors, enter: 84 | 85 | ```bash 86 | grep --color 'hello' file.txt 87 | ``` 88 | 89 | ### Piping 90 | `grep` command often used with shell pipes. In this example, show the name of the hard disk devices: 91 | 92 | ## `egrep` 93 | Main thing that remains to be investigated is what are the differences between the three main variants i.e. `grep`, `egrep` and `fgrep` of `grep` that makes Linux users choose one or the other version as per requirement. 94 | 95 | `grep` uses Basic Regular Expressions apart from normal strings as a search pattern. In Basic Regular Expressions (BRE), meta-characters like: `'{'`, `'}'`, `'('`, `')'`, `'|'`, `'+'`, `'?'` loose their meaning and are treated as normal characters of string and need to be escaped if they are to be treated as special characters. 96 | 97 | grep-escape 98 | 99 | `egrep` or `grep -E` is another version of grep or the Extended grep. This version of grep is efficient and fast when it comes to searching for a regular expression pattern as it treats meta-characters as is and doesnt substitute them as strings like in grep, and hence you are freed from the burden of escaping them as in grep. It uses ERE or the Extended Regular Expression set. 100 | 101 | In case of egrep, even if you do not escape the meta-characters, it would treat them as special characters and substitute them for their special meaning instead of treating them as part of string. 102 | 103 | egrep 104 | 105 | Like here, egrep searched for `file` string when the meta-characters were not escaped as it would mean by the meaning of these characters. But, when these characters were escaped, then egrep treated them as part of string and searched for complete string `(f|g)ile` in the file. 106 | 107 | ## `fgrep` 108 | `fgrep` or the Fixed grep or `grep -F` is yet another version of grep which is fast in searching when it comes to search for the entire string instead of regular expression as it doesnt recognize the regular expressions, neither any meta-characters. For searching any direct string, this is the version of grep which should be selected. 109 | 110 | Fgrep searches for complete string and doesnt even recognize special characters as part of regular expression even if escaped or not escaped. 111 | 112 | fgrep 113 | 114 | Like, when meta-characters were not escaped, fgrep searched for the complete string `(f|g)ile` in the file, and when the meta-characters were escaped, then the fgrep command searched for `\(f\|g\)ile` all characters as is in the file. 115 | 116 | ## Summary 117 | - Above highlighted are the differences between `grep`, `egrep` and `fgrep`. Apart from difference in the set of regular expressions used, and speed of execution, rest command line parameters remain same for all the three versions of grep and even instead of `egrep` or `fgrep`, `grep -E` or `grep -F` are recommended to be used. 118 | - `grep` is used to search data for certain text. 119 | - `grep` returns lines that contain a piece of text (wildcards work too!) 120 | - `grep` works great with piped data. 121 | - Options covered: 122 | - `-i`: case insensitive. 123 | - `-c`: count number of lines where word is matched. 124 | - `-v`: inverted match. 125 | - `-r`: directory recursive find. 126 | - `-n`: precede each line of output with the number of the line in the text file. 127 | - `-w`: search word only. -------------------------------------------------------------------------------- /Linux/03 Linux Advanced/03. Permissions.md: -------------------------------------------------------------------------------- 1 | 2 | # Permissions 3 | ## Listing the Contents of a Directory with ls 4 | The ls command lists the contents of the current directory. 5 | ```bash 6 | $ ls / 7 | bin dev home lib lib64 media opt root sbin srv tmp var 8 | boot etc init lib32 libx32 mnt proc run snap sys usr 9 | ``` 10 | 11 | By itself, the ls command shows just a list of names. Some are files, some are directories. However, using ls in this matter has some limitations. First, it does not show hidden files. Hidden files use filenames that start with a period (.) as the first character. They are often used for configuration of specific programs and are not accessed frequently. For this reason, they are not included in a basic directory listing. You can see all the hidden files by adding a switch to the command like this: 12 | 13 | ```bash 14 | $ ls -a 15 | . bin dev home lib lib64 media opt root sbin srv tmp var 16 | .. boot etc init lib32 libx32 mnt proc run snap sys usr 17 | ``` 18 | 19 | There is still more information available about each item in a directory. To include details such as the file/directory permissions, owner and group (all of which are discussed later in this chapter), as well as the size, and the date and time it was last modified, enter the following: 20 | 21 | ```bash 22 | $ ls -l 23 | lrwxrwxrwx 1 root root 7 Aug 4 2020 bin -> usr/bin 24 | drwxr-xr-x 1 root root 4096 Aug 4 2020 boot 25 | drwxr-xr-x 1 root root 4096 Feb 20 13:28 dev 26 | drwxr-xr-x 1 root root 4096 Feb 20 11:30 etc 27 | drwxr-xr-x 1 root root 4096 Dec 20 06:31 home 28 | -rwxr-xr-x 1 root root 631968 Dec 20 06:28 init 29 | lrwxrwxrwx 1 root root 7 Aug 4 2020 lib -> usr/lib 30 | lrwxrwxrwx 1 root root 9 Aug 4 2020 lib32 -> usr/lib32 31 | lrwxrwxrwx 1 root root 9 Aug 4 2020 lib64 -> usr/lib64 32 | lrwxrwxrwx 1 root root 10 Aug 4 2020 libx32 -> usr/libx32 33 | drwxr-xr-x 1 root root 4096 Aug 4 2020 media 34 | drwxr-xr-x 1 root root 4096 Dec 20 06:31 mnt 35 | drwxr-xr-x 1 root root 4096 Aug 4 2020 opt 36 | dr-xr-xr-x 30 root root 0 Feb 20 11:30 proc 37 | drwx------ 1 root root 4096 Jan 11 11:08 root 38 | drwxr-xr-x 1 root root 4096 Feb 20 13:42 run 39 | lrwxrwxrwx 1 root root 8 Aug 4 2020 sbin -> usr/sbin 40 | drwxr-xr-x 1 root root 4096 Jul 10 2020 snap 41 | drwxr-xr-x 1 root root 4096 Aug 4 2020 srv 42 | dr-xr-xr-x 12 root root 0 Feb 20 11:30 sys 43 | drwxrwxrwt 1 root root 4096 Feb 21 19:58 tmp 44 | drwxr-xr-x 1 root root 4096 Aug 4 2020 usr 45 | drwxr-xr-x 1 root root 4096 Aug 4 2020 var 46 | ``` 47 | 48 | The `ls -l` command displays a lot of information about the files in the directory: 49 | 50 | ![ls-l](../images/ls-l.jpg) 51 | 52 | File Type: 53 | |Symbol|Type| 54 | |--|--| 55 | |`-`|regular file| 56 | |`d`|directory| 57 | |`l`|symbolic link| 58 | 59 | ## Permissions 60 | - To read a file, you need to have read (`r`) permission for that file. 61 | - To write to a file, to modify a file, or to erase a file, you need to have write (`w`) permission for that file. 62 | - To run a program or to change to a directory, you need to have execute (`x`) permission for that program or directory. 63 | 64 | You can find out your login name with the `whoami` command. 65 | You can find out what groups you are in with the `groups` command. 66 | 67 | - If you are the owner of a file (you made it, it's yours), then that file's **user** permissions take effect. 68 | - If you are in the group that a file is assigned to, then that file's **group** permissions take effect. 69 | - Otherwise, the file's **other** permissions take effect. 70 | 71 | It is important that in most cases, it makes no sense to set permissions on yourself more restrictive than group or other. 72 | 73 | It is also important to remember that permissions basically do not apply to the root user. 74 | 75 | ### Permission Categories 76 | |Symbol|Category| 77 | |--|--| 78 | |`u`|User| 79 | |`g`|Group| 80 | |`o`|Other| 81 | |`a`|All| 82 | 83 | ### Groups 84 | - Every user is in at least one group 85 | - Users belong to many groups 86 | - Groups are used to organize users 87 | - The `groups` command displays a user's groups 88 | 89 | 90 | ### Change Permissions 91 | You can change the permissions on a file with the `chmod` command. 92 | 93 | - `chmod`: change mode command 94 | - `ugoa`: user category (user, group, other, all) 95 | - `+-=`: add, subtract, or set permissions 96 | - `rwx`: read write, execute 97 | 98 | Examples: 99 | ```bash 100 | $ ls -l sales.data 101 | -rw-r--r-- 1 jason users 10400 Sep 27 08:52 sales.data 102 | ``` 103 | 104 | - Add write permission to group: 105 | ```bash 106 | $ chmod g+w sales.data 107 | $ ls -l sales.data 108 | -rw-rw-r-- 1 jason users 10400 Sep 27 08:52 sales.data 109 | ``` 110 | 111 | - Revoke write permission from group: 112 | ```bash 113 | $ chmod g-w sales.data 114 | $ ls -l sales.data 115 | -rw-r--r-- 1 jason users 10400 Sep 27 08:52 sales.data 116 | ``` 117 | 118 | - Add read, write, and execution permission to user: 119 | ```bash 120 | $ chmod u+rwx,g-r sales.data 121 | $ ls -l sales.data 122 | -rwx---r-- 1 jason users 10400 Sep 27 08:52 sales.data 123 | ``` 124 | 125 | - Set everybody permission to read only: 126 | ```bash 127 | $ chmod a=r sales.data 128 | $ ls -l sales.data 129 | -r--r--r-- 1 jason users 10400 Sep 27 08:52 sales.data 130 | ``` 131 | 132 | **Note:** If you don't specify anything after `=`, all permissions are revoked. 133 | 134 | Revoke all permissions from other: 135 | ```bash 136 | $ chmod o= sales.data 137 | $ ls -l sales.data 138 | -r--r----- 1 jason users 10400 Sep 27 08:52 sales.data 139 | ``` 140 | 141 | ### Numeric Based Permissions 142 | Many people find it easiset to set permissions using numbers, instead of letters. The numbers are represented like this in binary: 143 | 144 | |r|w|x|| 145 | |--|--|--|--| 146 | |0|0|0|Value for off| 147 | |1|1|1|Binary value for on| 148 | |4|2|1|Base 10 value for on| 149 | 150 | |Octal|Binary|String|Description| 151 | |--|--|--|--| 152 | |0|000|`---`|no permissions| 153 | |1|001|`--x`|execute only| 154 | |2|010|`-w-`|write only| 155 | |3|011|`-wx`|write and execute (2+1)| 156 | |4|100|`r--`|read only| 157 | |5|101|`r-x`|read and execute (4+1)| 158 | |6|110|`rw-`|read and write (4+2)| 159 | |7|111|`rwx`|read, write, and execute (4+2+1)| 160 | 161 | **Note:** In permission order has meaning! read, write, and then execute. 162 | 163 | ||U|G|O| 164 | |--|--|--|--| 165 | |Symbolic|`rwx`|`r-x`|`r--`| 166 | |Binary|111|101|100| 167 | |Decimal|7|5|4| 168 | 169 | ### Commonly Used Permissions 170 | 171 | |Symbolic|Octal|| 172 | |--|--|--| 173 | |`-rwx------`|700|ensure that the file can be read, edited, and executed by the owner, but no one else| 174 | |`-rwxr-xr-x`|755|allows everyone to execute the file, but only the user can edit| 175 | |`-rw-rw-r--`|664|allows a group of people to modify a file and let others read it| 176 | |`-rw-rw----`|660|allows a group of people to modify a file and NOT let others read it| 177 | |`rw-r--r--`|644|allows everyone on the system to read the file, but only the user can edit| 178 | 179 | Notes: 180 | - For 777 (gives full permission) and 666, always ask if there is a better way to do that 181 | - 777 gives full permission, anyone can make changes to the script or program and execute it. so if mallicious code was either inserted on purpose or by accident, it can cause trouble. 182 | - If multiple people need access, consider creating a group and limit access to that group. 183 | 184 | ### Links 185 | 186 | #### Hard Links 187 | 188 | Directory entries point to data in the filesystem. There is nothing wrong with having two different entries point to the same data. This is called a hard link. 189 | 190 | To make a hard link, use the ln command. The usage is similar to the `cp` command: 191 | `ln existing_filename new_hard_link` 192 | 193 | This will make a new file name entry in the same inode making the file have 2 names (links) that are the same file. 194 | 195 | If you erase the original file, the data remains, since it is still linked to the new filename. You can see the number of hard links there are to a particular file in the `ls -l` listing, in the column to the right of the permissions. 196 | 197 | **Note:** You can't make a hard link across filesystems. If two different directories refer to data on two different hard drives, then a hard link cannot be made from a file on one to a new file on the other. Also, you can't make a hard link to a directory; the only hard links to directories are the . and .. special directories. 198 | 199 | #### Symbolic Links 200 | 201 | Symbolic links are similar to hard links, but instead of the new file pointing to the same data as the existing file, the new file points to the existing filename . 202 | 203 | To make a symbolic link , use the ln -s command: 204 | 205 | `ln -s existing_filename new_sym_link` 206 | Symbolic links don't point to the actual data on the filesystem, so if the original file is erased, then the symbolic link will still point to the now-erased original filename. 207 | 208 | Symbolic links have advantages over hard links, and so are used much more often: 209 | 210 | - Symbolic links can span filesystems; hard links cannot. 211 | - Symbolic links can be made for directories; hard links cannot. 212 | - Symbolic links can point to non-existent files; hard links cannot. 213 | - Symbolic links Do have seperate inodes (needed because they can reside on seperate filesystems) hard links are just another name added into the inode of the same file. 214 | -------------------------------------------------------------------------------- /Linux/02 Linux File System/08. Search for Files.md: -------------------------------------------------------------------------------- 1 | # Search for Files 2 | 3 | Do you want to know how to perform searches on a Linux computer or server? Then you’ve come to the right place! 4 | 5 | In this section, we’ll talk about the Linux find and locate commands, which will help you to look for any file on your machine. 6 | 7 | Linux gives users more options on how to search for files using certain commands. Besides searching based on common filters, you are also able to find files by user permissions, size, timestamps, and so on. To do that, we’ll utilize the **find** and **locate** commands in Linux. 8 | 9 | ## Find 10 | The most popular command to find and filter files on Linux is find. The basic syntax is as follows: 11 | 12 | ```bash 13 | find 14 | ``` 15 | The second argument `` is dedicated to your file. This could be the file’s name, type, date of creation, etc. The third argument `` is where you will specify the relevant search term. 16 | 17 | ### Searching by Name 18 | To run a simple search query using the name of the file, use the find command like this: 19 | 20 | ```bash 21 | find . -name my-file 22 | ``` 23 | We used the `-name` option, and searched for a file called my-file. Note that we started the search in our current directory by using the `.` (dot) argument. 24 | 25 | Keep in mind that the -name argument looks for case-sensitive terms in Linux. If you know the name of the file, but are not sure about its case-sensitivity, use the following find command: 26 | 27 | ```bash 28 | find . -iname my-file 29 | ``` 30 | 31 | You can look for multiple files with a common format like `.txt` as well: 32 | 33 | ```bash 34 | find . -name "*.txt" 35 | ``` 36 | This will list down all the text files starting with the current folder. 37 | 38 | Lastly, if you want to find a certain file by name and remove it, use the -delete argument after the file name: 39 | 40 | ```bash 41 | find . -name my-file -delete 42 | ``` 43 | 44 | **Note:** You can also use piping to delete files: `find . -name my-file | xargs rm` 45 | 46 | ### Searching by Type 47 | Linux allows users to list all information based on their types. There are several filters that you can use: 48 | 49 | - `d` – directory or folder 50 | - `f` – normal file 51 | - `l` – symbolic link 52 | - `c` – character devices 53 | - `b` – block devices 54 | 55 | This will list all of the current directories in your the current directory: 56 | ```bash 57 | find . -type d 58 | ``` 59 | 60 | You can also combine the –type and -name options to narrow down your searches further: 61 | 62 | ``` 63 | find . -type f -name my-file 64 | ``` 65 | 66 | ### Searching by Time 67 | If you want to search for files based on when they were accessed and modification time footprints. Linux keeps track of the files using these three timestamps. 68 | 69 | - Access Time (-atime) – when the file was either read or written into. 70 | - Modification Time (-mtime) – when the file was modified. 71 | - Change Time (-ctime) – when the file’s meta-data was updated. 72 | 73 | **Note:** "Modify" is the timestamp of the last time the file's content has been mofified. This is often called "mtime". "Change" is the timestamp of the last time the file's inode has been changed, like by changing permissions, ownership, file name, number of hard links. It's often called "ctime" 74 | 75 | This option has to be used with a number that specifies how many days passed since the file was accessed, modified or changed: 76 | 77 | 78 | |Command|Description| 79 | |:--|:--| 80 | |`find . -atime 1`|This command will show all files that were accessed a day ago starting from your current time.| 81 | |`find . -mtime +2`|It lists down all the files that have a modification time of more than two days ago.| 82 | |`find . -ctime -1`|To find all files whose meta-data was updated less than a day ago.| 83 | |`find . -mmin -1`|The `-mmin` argument looks for modified files on a minute basis.| 84 | |`find . -newer my-file`|Compare the age of two or more files and display the newer one.| 85 | 86 | ### Searching by Size 87 | Linux lets you search for files based on their sizes. The syntax for searching files by size is: 88 | 89 | ```bash 90 | find -size 91 | ``` 92 | 93 | You can specify the following size units: 94 | - c – bytes 95 | - k – kilobytes 96 | - M – megabytes 97 | - G – gigabytes 98 | - b – 512-byte chunks 99 | 100 | |Command|Description| 101 | |:--|:--| 102 | |`find . -size 10M`|Search for all of the files that are exactly 10 megabytes.| 103 | |`find . -size +5G`|Search for all the files that are more than five gigabytes in size.| 104 | 105 | ### Searching by Ownership 106 | |Command|Description| 107 | |:--|:--| 108 | |`find . -user ali`|Return a list of all files that the user named `ali` owns.| 109 | |`find . -group ali`|Similar to usernames, we can also find files through group names.| 110 | 111 | ### Searching by Permission 112 | Users can search for files based on file permissions using `-perm` option. 113 | 114 | |Command|Description| 115 | |:--|:--| 116 | |`find . -perm 644`|Search for all the files that have only read and write permissions..| 117 | |`find . -size -644`|Search for all the files that have at least 644 permission.| 118 | 119 | ### Other Useful Options 120 | |Command|Description| 121 | |:--|:--| 122 | |`find . -empty`|Look for empty files and folders.| 123 | 124 | ## Locate 125 | The locate command is a useful alternative, as it is faster than the find command when performing searches. That’s because the former only scans your Linux database instead of the whole system. Furthermore, the syntax is relatively easier to write. 126 | 127 | ### How to Install locate Package 128 | By default, Linux does not come with the locate command pre-installed. To get the package, run the following commands one after another: 129 | 130 | ```bash 131 | sudo apt-get update 132 | sudo apt-get install mlocate 133 | ``` 134 | 135 | locate 136 | 137 | 138 | ### Search Exact File Name 139 | 140 | The basic syntax only allows you to search for files that contain the search term. If you want to get the file with the exact name, you can use the `-r` option to search with regular expression and add dollar symbol `($)` at the end of your search term, for example: 141 | 142 | ```bash 143 | locate -r my-file$ 144 | ``` 145 | 146 | ### Count the Number of Files 147 | 148 | In order to tell how many files appear on your search result, insert -c after the locate command. 149 | 150 | ```bash 151 | locate -c my-file 152 | ``` 153 | 154 | You can also use piping with `wc` (word count) command that counts number of lines, words, and characters: 155 | 156 | ```bash 157 | locate my-file | wc -l 158 | ``` 159 | 160 | `wc`: 161 | - `wc -l`: number of lines 162 | - `wc -w`: number of words 163 | - `wc -c`: number of characters 164 | 165 | ### Ignore Case Sensitive 166 | Use `-i` on your linux locate command to ignore case sensitive files. For instance: 167 | 168 | ```bash 169 | locate -i my-file 170 | ``` 171 | 172 | ### Show Existing Files 173 | Linux locate command can even show you a deleted file if you haven’t updated the database. Thankfully, you can get around this problem by using `-e` option, like this: 174 | 175 | ```bash 176 | locate -e my-file 177 | ``` 178 | 179 | By doing this, you will only get files that exist at the time you perform the locate command. 180 | 181 | If you have created new files and want to include them in the search results, you have o update the locate database. To do so run: 182 | ```bash 183 | sudo updatedb 184 | ``` 185 | 186 | ### Limit the Number of Search Results 187 | If you want to limit the number of search results, `-n ` will do the trick. However, remember that you need to put the option at the end of the command line. Take a look at this example: 188 | ```bash 189 | locate my-file -n 10 190 | ``` 191 | 192 | ## `fd` Command 193 | The fd command isn’t meant to replace the traditional find command, which has been on Linux, well, forever. Instead, `fd` tries to satisfy the majority of common uses of find in a more straightforward way—and, it’s often eight or nine times faster than find. You can see some of its benchmarks on the project’s GitHub repository page. 194 | 195 | `fd` has a colorized output, similar to that of some ls modes. It’s recursive, but doesn’t search hidden directories by default. It knows about Git and will also automatically ignore any patterns in your `.gitignore` file. 196 | 197 | `fd` is case insensitive by default. However, if your search pattern contains an uppercase letter, `fd` operates in a case sensitive mode. Of course, you can override the defaults, but, in many cases, they work in your favor. 198 | 199 | ### Installing `fd` 200 | Type the following: 201 | ```bash 202 | sudo apt-get install fd-find 203 | ``` 204 | In Ubuntu, the command is fdfind to avoid a name clash with another existing utility. If you want it to be `fd`, you can set up an alias 205 | 206 | ```bash 207 | alias fd=fdfind 208 | ``` 209 | 210 | ### Simple Searches with `fd` 211 | If you use fd with no command-line options, it behaves a little like ls, except it lists files in subdirectories by default. 212 | 213 | ```bash 214 | fdfind 215 | ``` 216 | 217 | To see files of a specific type, use the `-e` (extension) option. Note that you don’t have to precede the extension with a period `(.)`, nor is it case sensitive. 218 | 219 | For example, you could type the following: 220 | ```bash 221 | fdfind -e png 222 | ``` 223 | 224 | To look for a single file, type its name on the command line, like so: 225 | ```bash 226 | fdfind myfile.txt 227 | ``` 228 | 229 | To have the search start in a particular directory, include a file path on the command line. The following command will start a search in the `/etc` directory, and look for files that include `myfile` in the file name: 230 | 231 | ```bash 232 | fdfind myfile /etc 233 | ``` 234 | 235 | ### File Types and Case Sensitivity 236 | You can ask `fd` to look for directories, files (including those that are executable and empty), and symbolic links. You can do so by using the -t (type) option, followed by one of the letters below: 237 | 238 | - `f`: File. 239 | - `d`: Directory. 240 | - `l`: Symbolic link. 241 | - `x`: Executable file. 242 | - `e`: Empty file. 243 | 244 | The following looks for a directory called images: 245 | ```bash 246 | fdfind -t d images 247 | ``` 248 | 249 | Let’s see how case sensitivity works with search patterns. We type the following to first search for files that contain “geo” in their file names, and then for those that contain “Geo” in their file names: 250 | 251 | - `fdfind -tf geo` 252 | - `fdfind -tf Geo` 253 | 254 | In the first command, we used a lowercase search pattern, which caused fd to operate in a case-insensitive way. This means both `Geo` and `geo` are valid matches. 255 | 256 | Our second command contained an uppercase character, which caused fd to operate in a case-sensitive manner. This means only `Geo` is a valid match. 257 | 258 | ## Summary 259 | 260 | You can search for files on your server using the find and locate commands in Linux. These two powerful tools have their own advantages. Therefore, we encourage you to give both of them a go and see which one is more suitable for you. Here’s a short summary of what we talked about: 261 | 262 | - Use **find** to search for files based on name, type, time, size, ownership and permissions, in addition to some other useful options 263 | - Install and use Linux **locate** command to perform faster system-wide searches for files. It also allows you to filter out by name, case-sensitive, folder, and so on. 264 | 265 | fdfind 266 | -------------------------------------------------------------------------------- /Linux/01 Introduction/03 WSL.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "54d71156-261e-48ca-9fe9-57408da9f229", 6 | "metadata": {}, 7 | "source": [ 8 | "" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "id": "42d5be0d-6794-4e53-87b1-df39cfcec434", 14 | "metadata": {}, 15 | "source": [ 16 | "# Windows Subsystem for Linux (WSL) \n" 17 | ] 18 | }, 19 | { 20 | "cell_type": "markdown", 21 | "id": "2ad41100", 22 | "metadata": {}, 23 | "source": [ 24 | "## Table of Contents \n", 25 | "* [Download Ubuntu](#download_ubuntu)\n", 26 | "* [Configure Ubuntu](#configure_ubuntu)\n", 27 | "* [Customising your Terminal with Windows Terminal Preview](#customising_your_terminal_with_windows_terminal_preview)\n", 28 | "* [Enjoy Ubuntu on WSL!](#enjoy_ubuntu_on_wsl!)\n", 29 | "\n", 30 | "---" 31 | ] 32 | }, 33 | { 34 | "cell_type": "markdown", 35 | "id": "6d521913-5ce4-4cfe-b253-1675c6e39f2f", 36 | "metadata": {}, 37 | "source": [ 38 | "Windows Subsystem for Linux (WSL) allows you to install a complete Ubuntu terminal environment in minutes on your Windows machine, allowing you to develop cross-platform applications without leaving Windows.\n", 39 | "\n", 40 | "In this tutorial, we’ll show you how to get up and running with Ubuntu on WSL. These instructions will work on both Windows 10 or Windows 11." 41 | ] 42 | }, 43 | { 44 | "cell_type": "markdown", 45 | "id": "450bb1bf-ec92-465a-9658-e135889b8891", 46 | "metadata": {}, 47 | "source": [ 48 | "\n", 49 | "\n", 50 | "\n", 51 | "# Install WSL \n" 52 | ] 53 | }, 54 | { 55 | "cell_type": "markdown", 56 | "id": "88baa93d-59c1-47e5-956b-f24cdd2ca727", 57 | "metadata": {}, 58 | "source": [ 59 | "Installing WSL is now easier than ever. First, **enable the windows subsystem for Linux** option in settings.\n", 60 | "\n", 61 | "- Go to Start. Search for \"Turn Windows features on or off.\"\n", 62 | "- Check the option Windows Subsystem for Linux." 63 | ] 64 | }, 65 | { 66 | "cell_type": "markdown", 67 | "id": "ad120cbe-aad3-47eb-8f14-c12f9a799e96", 68 | "metadata": {}, 69 | "source": [ 70 | "" 71 | ] 72 | }, 73 | { 74 | "cell_type": "markdown", 75 | "id": "3e942524-3a1d-451d-ac61-bc7ba0e7f47d", 76 | "metadata": {}, 77 | "source": [ 78 | "Next, search for Windows PowerShell in your Windows search bar, then select Run as administrator." 79 | ] 80 | }, 81 | { 82 | "cell_type": "markdown", 83 | "id": "54937863-4382-4f42-b373-efd38a19ba1e", 84 | "metadata": {}, 85 | "source": [ 86 | "" 87 | ] 88 | }, 89 | { 90 | "cell_type": "markdown", 91 | "id": "31d9765f-2626-4981-b192-b4da153220e6", 92 | "metadata": {}, 93 | "source": [ 94 | "At the command prompt type:\n", 95 | "\n", 96 | "`wsl --install`" 97 | ] 98 | }, 99 | { 100 | "cell_type": "markdown", 101 | "id": "19bd5dd7-edf5-4773-90eb-95755027bf85", 102 | "metadata": {}, 103 | "source": [ 104 | "And wait for the process to complete." 105 | ] 106 | }, 107 | { 108 | "cell_type": "markdown", 109 | "id": "cb70bd63-e564-41f9-aec2-5b1ffa5aa8ae", 110 | "metadata": {}, 111 | "source": [ 112 | "
\n", 113 | "For WSL to be properly activated, you will now need to restart your computer.\n", 114 | "
" 115 | ] 116 | }, 117 | { 118 | "cell_type": "markdown", 119 | "id": "53e19b36-0db7-4714-bd77-4f0c786b6022", 120 | "metadata": {}, 121 | "source": [ 122 | "> **Note:** This command will enable the required optional components, download the latest Linux kernel, set WSL 2 as your default, and install a Linux distribution for you (Ubuntu by default, see below to change this)." 123 | ] 124 | }, 125 | { 126 | "cell_type": "markdown", 127 | "id": "55c58247-38a1-468b-8a6f-bbcf25890182", 128 | "metadata": {}, 129 | "source": [ 130 | "\n", 131 | "\n", 132 | "\n", 133 | "## Download Ubuntu" 134 | ] 135 | }, 136 | { 137 | "cell_type": "markdown", 138 | "id": "7e188497-41fa-4b90-b6f9-95170c277b76", 139 | "metadata": {}, 140 | "source": [ 141 | "WSL supports a variety of Linux distributions, including the latest Ubuntu release, Ubuntu 22.04 LTS, Ubuntu 20.04 LTS and Ubuntu 18.04 LTS. You can find them by opening the [Microsoft store](https://www.microsoft.com/en-us/p/windows-terminal-preview/9n8g5rfz9xk3?activetab=pivot:overviewtab) app and searching for Ubuntu." 142 | ] 143 | }, 144 | { 145 | "cell_type": "markdown", 146 | "id": "5ce517d4-8c17-4a78-acce-7e6bd68fe628", 147 | "metadata": {}, 148 | "source": [ 149 | "" 150 | ] 151 | }, 152 | { 153 | "cell_type": "markdown", 154 | "id": "8aeec1ef-b56e-4a49-9b88-19cc6222f016", 155 | "metadata": {}, 156 | "source": [ 157 | "Choose the distribution you prefer and then click on Get as shown in the following screenshot:" 158 | ] 159 | }, 160 | { 161 | "cell_type": "markdown", 162 | "id": "ceda9c67-9f6b-42ad-b0b8-f03e3672b2cd", 163 | "metadata": {}, 164 | "source": [ 165 | "" 166 | ] 167 | }, 168 | { 169 | "cell_type": "markdown", 170 | "id": "9e48f56b-f930-4711-a258-3f5b3e844066", 171 | "metadata": {}, 172 | "source": [ 173 | "Ubuntu will then install on your machine." 174 | ] 175 | }, 176 | { 177 | "cell_type": "markdown", 178 | "id": "5f615cc9-bc53-45fb-87be-0c4008a31c93", 179 | "metadata": {}, 180 | "source": [ 181 | "Once installed, you can either launch the application directly from the store or search for Ubuntu in your Windows search bar." 182 | ] 183 | }, 184 | { 185 | "cell_type": "markdown", 186 | "id": "3a694519-1157-47a9-8759-d1024f99cda4", 187 | "metadata": {}, 188 | "source": [ 189 | "" 190 | ] 191 | }, 192 | { 193 | "cell_type": "markdown", 194 | "id": "c4c463ca-99da-46e0-be31-f612ab9e937a", 195 | "metadata": {}, 196 | "source": [ 197 | "\n", 198 | "\n", 199 | "\n", 200 | "## Configure Ubuntu" 201 | ] 202 | }, 203 | { 204 | "cell_type": "markdown", 205 | "id": "6e79281d-5792-491e-ae4f-e08e21a89db5", 206 | "metadata": {}, 207 | "source": [ 208 | "Congratulations, you now have an Ubuntu terminal running on your Windows machine!" 209 | ] 210 | }, 211 | { 212 | "cell_type": "markdown", 213 | "id": "c78ce5f4-2fc9-49b3-8a0a-4b694d509d6a", 214 | "metadata": {}, 215 | "source": [ 216 | "> If Ubuntu returns an error during this initial installation, then the most common issue is that virtualisation is disabled in your device’s BIOS menu. You will need to turn this on during your device’s boot sequence. The location of this option varies by manufacturer, so you will need to refer to their documentation to find it." 217 | ] 218 | }, 219 | { 220 | "cell_type": "markdown", 221 | "id": "90e87ee6-1dac-4e83-bd2e-98c81f555d5a", 222 | "metadata": {}, 223 | "source": [ 224 | "Once Ubuntu has finished its initial setup you will need to create a username and password (this does not need to match your Windows user credentials)." 225 | ] 226 | }, 227 | { 228 | "cell_type": "markdown", 229 | "id": "04233856-0298-408f-9330-a999a9cc55cd", 230 | "metadata": {}, 231 | "source": [ 232 | "" 233 | ] 234 | }, 235 | { 236 | "cell_type": "markdown", 237 | "id": "65b2a67a-39cf-4d91-8ea2-fb5995328b35", 238 | "metadata": {}, 239 | "source": [ 240 | "Finally, it’s always good practice to install the latest updates with the following commands, entering your password when prompted.\n", 241 | "\n", 242 | "`sudo apt update`\n", 243 | "\n", 244 | "Then\n", 245 | "\n", 246 | "`sudo apt upgrade`\n", 247 | "\n", 248 | "Press `Y` when prompted." 249 | ] 250 | }, 251 | { 252 | "cell_type": "markdown", 253 | "id": "d3f3a2f9-c745-432a-a1b7-951b86295a3e", 254 | "metadata": {}, 255 | "source": [ 256 | "\n", 257 | "\n", 258 | "\n", 259 | "## Customising your Terminal with Windows Terminal Preview" 260 | ] 261 | }, 262 | { 263 | "cell_type": "markdown", 264 | "id": "6d96a714-851f-453a-b0bb-0faa9bfc0ade", 265 | "metadata": {}, 266 | "source": [ 267 | "Since you’re likely to be using your Ubuntu terminal a fair bit, it’s always nice to do some customisation. We recommend installing Windows Terminal Preview to get the most user-friendly setup. You can find it in the [Microsoft Store](https://www.microsoft.com/en-us/p/windows-terminal-preview/9n8g5rfz9xk3?activetab=pivot:overviewtab)." 268 | ] 269 | }, 270 | { 271 | "cell_type": "markdown", 272 | "id": "e84bbb85-1f6d-4d80-adde-a5f04b6a8f29", 273 | "metadata": {}, 274 | "source": [ 275 | "" 276 | ] 277 | }, 278 | { 279 | "cell_type": "markdown", 280 | "id": "888266e2-7aab-40fb-9483-22bd5881fdf2", 281 | "metadata": {}, 282 | "source": [ 283 | "Windows Terminal allows you to open multiple Terminal instances as tabs, so you can have multiple terminals running. It also includes a number of customisation options. In the below screenshot, we’ve changed the tab name and colour, and configured the terminal appearance to use the Tango Dark theme and the [Ubuntu font](https://design.ubuntu.com/font/?_ga=2.191475502.580737161.1654751883-2119122224.1654751883)!" 284 | ] 285 | }, 286 | { 287 | "cell_type": "markdown", 288 | "id": "9f830f45-4ca0-45cf-9f07-ffef0e56c022", 289 | "metadata": {}, 290 | "source": [ 291 | "" 292 | ] 293 | }, 294 | { 295 | "cell_type": "markdown", 296 | "id": "1a7630c5-ad1b-4569-9ba4-0118c30e6bcf", 297 | "metadata": {}, 298 | "source": [ 299 | "These customisations can be applied universally using the Appearance menu in Settings or to individual profiles which each have their own Appearance menu. Try it yourself to find something you feel comfortable with!" 300 | ] 301 | }, 302 | { 303 | "cell_type": "markdown", 304 | "id": "307b3ac9-93c7-4d0c-88f4-595c4728997b", 305 | "metadata": {}, 306 | "source": [ 307 | "" 308 | ] 309 | }, 310 | { 311 | "cell_type": "markdown", 312 | "id": "69ba82d2-ae82-49d1-88d7-c03e05fbc3ed", 313 | "metadata": {}, 314 | "source": [ 315 | "\n", 316 | "\n", 317 | "\n", 318 | "## Enjoy Ubuntu on WSL!" 319 | ] 320 | }, 321 | { 322 | "cell_type": "markdown", 323 | "id": "42aaeb4b-cd7e-473b-8c1f-4c482c557504", 324 | "metadata": {}, 325 | "source": [ 326 | "That’s it! In this tutorial, you’ve seen how to install WSL and Ubuntu, set up your profile, and install your first package. You also got some tips on how to customise your experience." 327 | ] 328 | }, 329 | { 330 | "cell_type": "markdown", 331 | "id": "c4b9e9c9-984c-4b70-9b43-b3159504030d", 332 | "metadata": {}, 333 | "source": [ 334 | "> **Note**: You can also access your local machine’s filesystem from within the Linux Bash shell – you’ll find your local drives mounted under the `/mnt` folder. For example, your C: drive is mounted under `/mnt/c`. However, you need to know the basics on how to work with Linux terminal which are covered in later sections." 335 | ] 336 | } 337 | ], 338 | "metadata": { 339 | "kernelspec": { 340 | "display_name": "Python 3", 341 | "language": "python", 342 | "name": "python3" 343 | }, 344 | "language_info": { 345 | "codemirror_mode": { 346 | "name": "ipython", 347 | "version": 3 348 | }, 349 | "file_extension": ".py", 350 | "mimetype": "text/x-python", 351 | "name": "python", 352 | "nbconvert_exporter": "python", 353 | "pygments_lexer": "ipython3", 354 | "version": "3.8.11" 355 | } 356 | }, 357 | "nbformat": 4, 358 | "nbformat_minor": 5 359 | } 360 | -------------------------------------------------------------------------------- /Linux/02 Linux File System/11. Archiving and Compression.md: -------------------------------------------------------------------------------- 1 | # Archiving and Compression 2 | Archiving is the process of combining multiple files and directories (same or different sizes) into one file. On the other hand, compression is the process of reducing the size of a file or directory. Archiving is usually used as part of a system backup or when moving data from one system to another. 3 | 4 | Archives are also an essential component of the Linux ecosystem, because all the software you install via your distribution’s package manager will initially be downloaded as a compressed archive from a remote repository. Therefore, working with archives is an important aspect of using a Linux based operating system effectively. 5 | 6 | This section will introduce the standard archiving tool used on Linux — which is the `tar` software utility — and demonstrate its usage on the command line to create and work with archives, or tarballs. The `tar` utility is also able to compress an archive via a compression tool. This usage pattern of firstly creating an archive and then compressing it using a compression tool is often adopted for distributing packages remotely. 7 | 8 | tar-gzip 9 | 10 | Compressing an archive can reduce its storage space requirements and is an important step in preparing it for distribution. With these points in mind, this section will also introduce the major compression tools on Linux, and discuss their usage both with tar and individually on the command line. More specifically, we shall take a look at the gzip compression tool. 11 | 12 | ## Archiving 13 | 14 | ### `tar` 15 | Tar is a Unix command representative TAPE Archive (tape archive). It is used to combine or store multiple files (same or different sizes) into one file. 16 | 17 | When working with tar on the command line, you will often use the same command line options for achieving a specific task — such as creating and extracting archives, as well as listing files within an archive. These frequently used options are detailed here: 18 | 19 | - `c` – Create a new archive containing the specified items. 20 | - `f` - An archive file name will be specified. 21 | - `x` – Extract the specified items from the archive to disk. 22 | - `r` – Append file to archive 23 | - `t` - List an archive's content to standard output. 24 | - `v` - Produce verbose output. 25 | 26 | The tar utility also provides several options that enable filtering archives through specific compression tools. For example, if you wish to compress an archive with `gzip`, we would pass the `z` option along with the aforementioned cf options. The following table lists the filtering options available to `tar` that we shall use in this tutorial: 27 | 28 | #### Examples 29 | ##### Create 30 | Create `tar` archive: 31 | ```bash 32 | tar c file.txt image.png -f archive.tar 33 | tar cf archive.tar file.txt image.png 34 | tar cfv archive.tar file.txt image.png # verbose mode 35 | ``` 36 | 37 | ##### Extract 38 | Extract `tar` archive: 39 | ```bash 40 | tar x -f archive.tar 41 | tar xf archive.tar 42 | tar xfv archive.tar # verbose mode 43 | ``` 44 | 45 | We can also use the `-C` or `--one-top-level` option to extract the archive to a different directory. 46 | ```bash 47 | tar x -f archive.tar -C output_dir 48 | tar xf archive.tar -C output_dir 49 | tar xfv archive.tar -C output_dir # verbose mode 50 | 51 | tar xfv archive.tar --one-top-level=output_dir # verbose mode 52 | tar xfv archive.tar --one-top-level # verbose mode 53 | ``` 54 | If you don’t assign a directory name to the `--one-top-level` option, files will be extracted into a directory with the same name as the archive: 55 | 56 | To extract individual files and directories from the archive, simply append the items you’d like to extract to the end of the command: 57 | ```bash 58 | tar xfv archive.tar --one-top-level file.txt image.png 59 | ``` 60 | 61 | ##### Append/Delete 62 | It is also possible to list the individual files and directories within an archive: 63 | 64 | ```bash 65 | tar tfv wallpapers.tar # verbose mode 66 | ``` 67 | 68 | If you intend to extract an archive, It is good practice to firstly list the archive’s files before performing the actual extract operation. For example, if you mistakenly downloaded a huge archive and immediately extract all the files before checking it’s content, you could be in some trouble! 69 | 70 | Files can also be deleted from an uncompressed.tar archive with the `-delete` option. Therefore, we must firstly decompress an archive before attempting to delete any of its content: 71 | 72 | ```bash 73 | tar f archive.tar --delete file.txt 74 | ``` 75 | 76 | Conversely, files are appended to an archive via the `-r` option: 77 | ```bash 78 | tar f archive.tar -r file.txt 79 | ``` 80 | 81 | ## Compression 82 | There are quite a few compression tools available on Linux, with each one implementing a specific compression algorithm. 83 | 84 | ### `gzip` 85 | Go ahead and install the `gzip` compression tools via your Linux distribution’s package manager: 86 | 87 | ```bash 88 | $ sudo pacman -S gzip # Arch 89 | $ sudo apt install gzip # Debian and Ubuntu 90 | $ sudo dnf install gzip # Fedora 91 | ``` 92 | 93 | Command line reference: 94 | - `gzip filename` - Compress a file. 95 | - `gzip -d filename.gz` - Decompress a file. 96 | - `-r`, `--recursive` - Travel the directory structure recursively and compress specified file names. 97 | - `-v`, `--verbose` - Verbose. Display the name and percentage reduction for each. 98 | 99 | #### Examples 100 | ```bash 101 | gzip archive.tar 102 | ``` 103 | The default behavior of `gzip` is to delete the original file. However, you can force the tool to not do that by using the `-k` command line option. 104 | 105 | ```bash 106 | gzip -k archive.tar 107 | ``` 108 | 109 | The `tar` utility also provides several options that enable filtering archives through specific compression tools. For example, if you wish to compress an archive with gzip, we would pass the z option along with the aforementioned cf options. 110 | 111 | ```bash 112 | tar czfv archive.tar.gz file.txt 113 | ``` 114 | 115 | To uncompress a file, use the -d command line option. 116 | ```bash 117 | gzip -d archive.tar.gz 118 | ``` 119 | 120 | To recursively compress files, use the `-r` command line option. This option, as the name suggests, will compress files in the main directory as well as all subdirectories. 121 | 122 | ```bash 123 | gzip -r * 124 | ``` 125 | All files - whether in main directory or subdirectory - were compressed. 126 | 127 | To list details related to compressed file, use `-l` command line option. 128 | 129 | ```bash 130 | gzip -l archive.tar.gz 131 | ``` 132 | 133 | The `gzip` command also lets you regulate the speed of compression. This you can do by specifying a hyphen `(-)` followed by a number as command line argument to the tool. For example: 134 | ```bash 135 | gzip -5 archive.tar 136 | ``` 137 | Note that you can use any number between 1 and 9, where `-1` (or `--fast`) indicates fastest compression while `-9` (or `--best`) indicates slowest (but best). 138 | 139 | ### `zip` 140 | Zip is the most widely used archive file format that supports lossless data compression. A `zip` file is a data container containing one or more compressed files or directories. 141 | 142 | Go ahead and install the `zip` compression tools via your Linux distribution’s package manager: 143 | 144 | ```bash 145 | $ sudo apt install zip # Debian and Ubuntu 146 | $ sudo yum install zip # CentOS and Fedora 147 | ``` 148 | 149 | To zip one or more files, specify the files you want to add to the archive separated by space, as shown below: 150 | 151 | ```bash 152 | zip archive.zip file.txt image.png 153 | ``` 154 | If the archive name doesn’t end with .zip, the extension is added automatically unless the archive name contains a dot. `zip archivename.zip filename` will create an archive with the same name as would `zip archivename filename`. 155 | 156 | To suppress the output of the zip command, use the -q option: 157 | ```bash 158 | zip -q archive.zip file.txt image.png 159 | ``` 160 | 161 | Often, you’ll create a zip archive of a directory including the content of subdirectories. The `-r` option allows you to traverse the whole directory structure recursively: 162 | ```bash 163 | zip -r archive.zip directory_name 164 | ``` 165 | You can also add multiple files and directories in the same archive: 166 | ```bash 167 | zip -r archive.zip directory_name1 directory_name2 file1 file1 168 | ``` 169 | 170 | The zip command allows you to specify a compression level using a number prefixed with a dash from 0 to 9. The default compression level is `-6`. When using `-0`, all files will be stored without compression. `-9` will force the zip command to use an optimal compression for all files. 171 | 172 | For example, to use the compression level `-9`, you would type something like this: 173 | 174 | ```bash 175 | zip -9 -r archive.zip directory_name 176 | ``` 177 | The higher the compression level, the more CPU-intensive the zip process is, and it will take more time to complete. 178 | 179 | #### Creating a Password Protected ZIP file 180 | If you have sensitive information that needs to be stored in the archive, you can encrypt it using the `-e` option: 181 | ```bash 182 | zip -e archive.zip directory_name 183 | ``` 184 | The command will be prompted to enter and verify the archive password: 185 | ```bash 186 | Enter password: 187 | Verify password: 188 | ``` 189 | 190 | #### Creating Split Zip File 191 | Imagine you want to store the Zip archive on a file hosting service that has a file size upload limit of 1GB, and your Zip archive is 5GB. 192 | 193 | You can create a new split Zip file using the -s option followed by a specified size. The multiplier can be `k` (kilobytes), `m` (megabytes), `g` (gigabytes), or `t` (terabytes). 194 | 195 | ```bash 196 | zip -s 1g -r archivename.zip directory_name 197 | ``` 198 | The command above will keep creating new archives in a set after it reaches the specified size limit. 199 | ```bash 200 | archivename.zip 201 | archivename.z01 202 | archivename.z02 203 | archivename.z03 204 | archivename.z04 205 | ``` 206 | #### `unzip` 207 | `unzip` is not installed by default in most Linux distributions, but you can easily install it using the package manager of your distribution. 208 | ```bash 209 | $ sudo apt install unzip # Debian and Ubuntu 210 | $ sudo yum install unzip # CentOS and Fedora 211 | ``` 212 | 213 | In it’s simplest form, when used without any option, the unzip command extracts all files from the specified ZIP archive to the current directory. 214 | ```bash 215 | unzip latest.zip 216 | ``` 217 | 218 | By default, unzip prints the names of all the files it’s extracting and a summary when the extraction is completed. 219 | 220 | Use the `-q` switch to suppress the printing of these messages. 221 | ```bash 222 | unzip archive.zip 223 | ``` 224 | 225 | To unzip a ZIP file to a different directory than the current one, use the `-d` switch: 226 | ```bash 227 | unzip filename.zip -d /path/to/directory 228 | ``` 229 | ##### Unzip a Password Protected ZIP file 230 | To unzip a file that is password-protected, invoke the unzip command with the `-P` option followed by the password: 231 | ```bash 232 | unzip -P PasswOrd filename.zip 233 | ``` 234 | Typing a password on the command line is insecure and should be avoided. A more secure option is to extract the file normally without providing the password. If the ZIP file is encrypted, unzip will prompt you to enter the password: 235 | 236 | ```bash 237 | unzip filename.zip 238 | ``` 239 | 240 | ##### Exclude Files when Unzipping a ZIP File 241 | To exclude specific files or directories from being extracted, use the `-x` option followed by space-separated list of archive files you want to exclude from extracting: 242 | 243 | ```bash 244 | unzip filename.zip -x file1-to-exclude file2-to-exclude 245 | ``` 246 | 247 | In the following example we are extracting all files and directories from the ZIP archive except the `.git` directory 248 | ```bash 249 | unzip filename.zip -x "*.git/*" 250 | ``` 251 | 252 | ##### Overwrite Existing Files 253 | Let’s say you’ve already unzipped a ZIP file and you are running the same command again: 254 | 255 | ```bash 256 | unzip latest.zip 257 | ``` 258 | 259 | By default, `unzip` will ask you whether you like to overwrite only the current file, overwrite all files, skip extraction of the current file, skip extraction of all files, or rename the current file. 260 | ```bash 261 | Archive: latest.zip 262 | replace wordpress/xmlrpc.php? [y]es, [n]o, [A]ll, [N]one, [r]ename: 263 | ``` 264 | 265 | If you want to overwrite existing files without prompting, use the -o option: 266 | ```bash 267 | unzip -o filename.zip 268 | ``` 269 | Use this option with caution. If you made any changes to the files, the changes are lost. 270 | 271 | ##### Unzip a ZIP File Without Overwriting Existing Files 272 | Let’s say you’ve already unzipped a ZIP file, and you made changes to some files, but you accidentally deleted few files. You want to keep the changes and to restore the deleted files from the ZIP archive. 273 | 274 | In this case, use the -n option which forces unzip to skip the extraction of a file that already exists: 275 | ```bash 276 | unzip -n filename.zip 277 | ``` 278 | 279 | #### List the Contents of a Zip File 280 | To list the contents of a ZIP file, use the -l option: 281 | ```bash 282 | unzip -l filename.zip 283 | ``` 284 | 285 | 286 | ## Summary 287 | - Tarballs are containers to store files in for compression. 288 | - Tarballs can be compressed using various compression algorithms. 289 | - `gzip` and `bzip2` (not convered here) are common options on linux. `xz` is another option. 290 | - You can also use the `zip` and `unzip` commands to create/extract `.zip` files. 291 | -------------------------------------------------------------------------------- /Linux/01 Introduction/02 Linux Fundamentals.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "# Linux Fundamentals\n" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "## Table of Contents\n", 22 | "\n", 23 | "\n", 24 | "* [What is a “distribution?”](#what_is_a_“distribution?”)\n", 25 | " * [Which distribution is right for you?](#which_distribution_is_right_for_you?)\n", 26 | "* [Why Switch?](#why_switch?)\n", 27 | "* [Installing software on Linux](#installing_software_on_linux)\n", 28 | "\n", 29 | "---" 30 | ] 31 | }, 32 | { 33 | "cell_type": "markdown", 34 | "metadata": {}, 35 | "source": [ 36 | "Just like Windows, iOS, and Mac OS, Linux is an operating system. In fact, one of the most popular platforms on the planet, Android, is powered by the Linux operating system. An operating system is software that manages all of the hardware resources associated with your desktop or laptop. To put it simply, the operating system manages the communication between your software and your hardware. Without the operating system (OS), the software wouldn't function." 37 | ] 38 | }, 39 | { 40 | "cell_type": "markdown", 41 | "metadata": {}, 42 | "source": [ 43 | "The Linux operating system comprises several different pieces:\n", 44 | "\n", 45 | "1. **Bootloader** – The software that manages the boot process of your computer. For most users, this will simply be a splash screen that pops up and eventually goes away to boot into the operating system.\n", 46 | "2. **Kernel** – This is the one piece of the whole that is actually called ?Linux?. The kernel is the core of the system and manages the CPU, memory, and peripheral devices. The kernel is the lowest level of the OS.\n", 47 | "3. **Init system** – This is a sub-system that bootstraps the user space and is charged with controlling daemons. One of the most widely used init systems is systemd? which also happens to be one of the most controversial. It is the init system that manages the boot process, once the initial booting is handed over from the bootloader (i.e., GRUB or GRand Unified Bootloader).\n", 48 | "4. **Daemons** – These are background services (printing, sound, scheduling, etc.) that either start up during boot or after you log into the desktop.\n", 49 | "5. **Graphical server** – This is the sub-system that displays the graphics on your monitor. It is commonly referred to as the X server or just X.\n", 50 | "6. **Desktop environment** – This is the piece that the users actually interact with. There are many desktop environments to choose from (GNOME, Cinnamon, Mate, Pantheon, Enlightenment, KDE, Xfce, etc.). Each desktop environment includes built-in applications (such as file managers, configuration tools, web browsers, and games).\n", 51 | "7. **Applications** – Desktop environments do not offer the full array of apps. Just like Windows and macOS, Linux offers thousands upon thousands of high-quality software titles that can be easily found and installed. Most modern Linux distributions (more on this below) include App Store-like tools that centralize and simplify application installation. For example, Ubuntu Linux has the Ubuntu Software Center (a rebrand of GNOME Software? Figure 1) which allows you to quickly search among the thousands of apps and install them from one centralized location." 52 | ] 53 | }, 54 | { 55 | "cell_type": "markdown", 56 | "metadata": {}, 57 | "source": [ 58 | "A combination of these sub-systems will make up a \"distribution\" (You will learn more about it later in this section). So you can imagine the possible variations. Most variations come from the default GUI5 (Desktop Environment), Package Manager and default applications. However, since the kernel, system tools/libraries and CLI (Command Line Interface) are relatively constant, the core of any distribution is similar." 59 | ] 60 | }, 61 | { 62 | "cell_type": "markdown", 63 | "metadata": {}, 64 | "source": [ 65 | "Historically, distributions have evolved over time each with its own development philosophy, plan and strategy. In many cases, active development may derive from another distribution (see the simplified Linux distribution timeline below). But the bottom line is that they are more similar than different – simply a GNU/Linux Operating System." 66 | ] 67 | }, 68 | { 69 | "cell_type": "markdown", 70 | "metadata": {}, 71 | "source": [ 72 | "\n", 73 | "\n", 74 | "\n", 75 | "## What is a “distribution?”" 76 | ] 77 | }, 78 | { 79 | "cell_type": "markdown", 80 | "metadata": {}, 81 | "source": [ 82 | "" 83 | ] 84 | }, 85 | { 86 | "cell_type": "markdown", 87 | "metadata": {}, 88 | "source": [ 89 | "Windows OS has versions (Windows 2000, XP, Vista, 7, 8, 10) but GNU/Linux OS has distributions which in turn have versions (typically a number). These distributions (or distros) are a source of confusion for Windows users." 90 | ] 91 | }, 92 | { 93 | "cell_type": "markdown", 94 | "metadata": {}, 95 | "source": [ 96 | "Linux has a number of different versions to suit any type of user. From new users to hard-core users, you’ll find a “flavor” of Linux to match your needs. These versions are called distributions (or, in the short form, “distros”). Nearly every distribution of Linux can be downloaded for free, burned onto disk (or USB thumb drive), and installed (on as many machines as you like)." 97 | ] 98 | }, 99 | { 100 | "cell_type": "markdown", 101 | "metadata": {}, 102 | "source": [ 103 | "Popular Linux distributions include:\n", 104 | "- LINUX MINT\n", 105 | "- MANJARO\n", 106 | "- DEBIAN\n", 107 | "- UBUNTU\n", 108 | "- ANTERGOS\n", 109 | "- SOLUS\n", 110 | "- FEDORA\n", 111 | "- ELEMENTARY OS\n", 112 | "- OPENSUSE" 113 | ] 114 | }, 115 | { 116 | "cell_type": "markdown", 117 | "metadata": {}, 118 | "source": [ 119 | "Each distribution has a different take on the desktop. Some opt for very modern user interfaces (such as GNOME and Elementary OS’s Pantheon), whereas others stick with a more traditional desktop environment (openSUSE uses KDE)." 120 | ] 121 | }, 122 | { 123 | "cell_type": "markdown", 124 | "metadata": {}, 125 | "source": [ 126 | "\n", 127 | "\n", 128 | "\n", 129 | "### Which distribution is right for you?\n", 130 | "Which distribution you use will depend on the answer to three simple questions:\n", 131 | "- How skilled of a computer user are you?\n", 132 | "- Do you prefer a modern or a standard desktop interface?\n", 133 | "- Server or desktop?" 134 | ] 135 | }, 136 | { 137 | "cell_type": "markdown", 138 | "metadata": {}, 139 | "source": [ 140 | "If your computer skills are fairly basic, you’ll want to stick with a newbie-friendly distribution such as Linux Mint, Ubuntu (Figure 3), Elementary OS or Deepin. If your skill set extends into the above-average range, you could go with a distribution like Debian or Fedora. If, however, you’ve pretty much mastered the craft of computer and system administration, use a distribution like Gentoo. If you really want a challenge, you can build your very own Linux distribution, with the help of Linux From Scratch.\n", 141 | "\n", 142 | "If you’re looking for a server-only distribution, you will also want to decide if you need a desktop interface, or if you want to do this via command-line only. The Ubuntu Server does not install a GUI interface. This means two things your server won’t be bogged down loading graphics and you’ll need to have a solid understanding of the Linux command line. However, you can install a GUI package on top of the Ubuntu Server with a single command like sudo apt-get install ubuntu-desktop. System administrators will also want to view a distribution with regards to features. Do you want a server-specific distribution that will offer you, out of the box, everything you need for your server? If so, CentOS might be the best choice. Or, do you want to take a desktop distribution and add the pieces as you need them? If so, Debian or Ubuntu Linux might serve you well." 143 | ] 144 | }, 145 | { 146 | "cell_type": "markdown", 147 | "metadata": {}, 148 | "source": [ 149 | "\n", 150 | "\n", 151 | "\n", 152 | "## Why Switch?\n", 153 | "One of the biggest reasons for someone to switch to Linux is to use what is arguably the most powerful feature of the Linux operating system and that is the terminal." 154 | ] 155 | }, 156 | { 157 | "cell_type": "markdown", 158 | "metadata": {}, 159 | "source": [ 160 | "Now if you've ever seen a film where a hacker or a computer genius has sat behind their computer typing commands into what looks like a big black box on their computer screen that black box is called the **terminal**." 161 | ] 162 | }, 163 | { 164 | "cell_type": "markdown", 165 | "metadata": {}, 166 | "source": [ 167 | "" 168 | ] 169 | }, 170 | { 171 | "cell_type": "markdown", 172 | "metadata": {}, 173 | "source": [ 174 | "Now Linux is unique in that the development of Linux is inseparable from the terminal and this means that knowing how to use the terminal gives you pretty much absolute control over how your computer works by using the terminal. You can do pretty much anything that you want with your Linux computer." 175 | ] 176 | }, 177 | { 178 | "cell_type": "markdown", 179 | "metadata": {}, 180 | "source": [ 181 | "Now you can't get this level of control over your computer in any other operating system and this makes the terminal an incredible skill to learn." 182 | ] 183 | }, 184 | { 185 | "cell_type": "markdown", 186 | "metadata": {}, 187 | "source": [ 188 | "**Note:** Don't worry about memorizing all the commands." 189 | ] 190 | }, 191 | { 192 | "cell_type": "markdown", 193 | "metadata": {}, 194 | "source": [ 195 | "\n", 196 | "\n", 197 | "\n", 198 | "## Installing software on Linux\n", 199 | "Just as the operating system itself is easy to install, so too are applications. Most modern Linux distributions include what most would consider an app store. This is a centralized location where software can be searched and installed. Ubuntu Linux (and many other distributions) rely on GNOME Software, Elementary OS has the AppCenter, Deepin has the Deepin Software Center, openSUSE has their AppStore, and some distributions rely on Synaptic." 200 | ] 201 | }, 202 | { 203 | "cell_type": "markdown", 204 | "metadata": {}, 205 | "source": [ 206 | "" 207 | ] 208 | }, 209 | { 210 | "cell_type": "markdown", 211 | "metadata": {}, 212 | "source": [ 213 | "Regardless of the name, each of these tools do the same thing? a central place to search for and install Linux software. Of course, these pieces of software depend upon the presence of a GUI. For GUI-less servers, you will have to depend upon the command-line interface for installation." 214 | ] 215 | }, 216 | { 217 | "cell_type": "markdown", 218 | "metadata": {}, 219 | "source": [ 220 | "Let’s look at two different tools to illustrate how easy even the command line installation can be. Our examples are for Debian-based distributions and Fedora-based distributions. The Debian-based distros will use the apt-get tool for installing software and Fedora-based distros will require the use of the yum tool. Both work very similarly. We’ll illustrate using the apt-get command. Let’s say you want to install the wget tool (which is a handy tool used to download files from the command line). To install this using apt-get, the command would like like this:\n", 221 | "`sudo apt-get install wget`" 222 | ] 223 | }, 224 | { 225 | "cell_type": "markdown", 226 | "metadata": {}, 227 | "source": [ 228 | "" 229 | ] 230 | }, 231 | { 232 | "cell_type": "markdown", 233 | "metadata": {}, 234 | "source": [ 235 | "The sudo command is added because you need super user privileges in order to install software. Similarly, to install the same software on a Fedora-based distribution, you would first su to the super user (literally issue the command su and enter the root password), and issue this command:\n", 236 | "`yum install wget`" 237 | ] 238 | }, 239 | { 240 | "cell_type": "markdown", 241 | "metadata": {}, 242 | "source": [ 243 | "That’s all there is to installing software on a Linux machine.\n", 244 | "\n", 245 | "[Read More](https://www.linux.com/what-is-linux/)" 246 | ] 247 | } 248 | ], 249 | "metadata": { 250 | "kernelspec": { 251 | "display_name": "Python 3", 252 | "language": "python", 253 | "name": "python3" 254 | }, 255 | "language_info": { 256 | "codemirror_mode": { 257 | "name": "ipython", 258 | "version": 3 259 | }, 260 | "file_extension": ".py", 261 | "mimetype": "text/x-python", 262 | "name": "python", 263 | "nbconvert_exporter": "python", 264 | "pygments_lexer": "ipython3", 265 | "version": "3.8.11" 266 | } 267 | }, 268 | "nbformat": 4, 269 | "nbformat_minor": 4 270 | } 271 | -------------------------------------------------------------------------------- /Linux/01 Introduction/01 Operating Systems.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "c6296518-1a76-4303-a7bb-daa349a32340", 6 | "metadata": {}, 7 | "source": [ 8 | "" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "id": "e8d181f3-99aa-4a0b-90ab-0da8e564ebaa", 14 | "metadata": {}, 15 | "source": [ 16 | "# Operating Systems\n" 17 | ] 18 | }, 19 | { 20 | "cell_type": "markdown", 21 | "id": "3bbb086c-38f4-4742-aa9b-e1d6d581ee57", 22 | "metadata": {}, 23 | "source": [ 24 | "## Table of Contents \n", 25 | "* [Operating System Definition and Function](#operating_system_definition_and_function)\n", 26 | "* [Process Management in OS](#process_management_in_os)\n", 27 | "* [Types of Operating Systems](#types_of_operating_systems)\n", 28 | " * [Linux](#linux)\n", 29 | " * [Mac OS](#mac)\n", 30 | " * [Windows](#windows)\n", 31 | "* [Operating Systems for Mobile Devices](#operating_systems_for_mobile_deviced)\n", 32 | "* [Conclusion](#conclusion)\n", 33 | "\n", 34 | "---" 35 | ] 36 | }, 37 | { 38 | "cell_type": "markdown", 39 | "id": "d6631d0e-80e2-4226-a04c-d450e0cf5813", 40 | "metadata": {}, 41 | "source": [ 42 | "Operating System can be defined as an **interface between user and the hardware**. It provides an environment to the user so that, the user can perform its task in convenient and efficient way. Most of the time, there are several different computer programs running at the same time, and they all need to access your computer's **Central Processing Unit (CPU)**, **memory**, and **storage**. The operating system coordinates all of this to make sure each program gets what it needs." 43 | ] 44 | }, 45 | { 46 | "cell_type": "markdown", 47 | "id": "e0711cb1-75f7-40ca-8108-2875d8962b21", 48 | "metadata": {}, 49 | "source": [ 50 | "\n", 51 | "\n", 52 | "# Operating System Definition and Function" 53 | ] 54 | }, 55 | { 56 | "cell_type": "markdown", 57 | "id": "ae34718e-580c-403f-9007-154199f7745a", 58 | "metadata": {}, 59 | "source": [ 60 | "In the Computer System (comprises of Hardware and software), Hardware can only understand machine code (in the form of 0 and 1) which doesn't make any sense to a naive user." 61 | ] 62 | }, 63 | { 64 | "cell_type": "markdown", 65 | "id": "6de3309b-76e4-42a3-9cc1-c3d7d366e0f6", 66 | "metadata": {}, 67 | "source": [ 68 | "We need a system which can act as an intermediary and manage all the processes and resources present in the system." 69 | ] 70 | }, 71 | { 72 | "cell_type": "markdown", 73 | "id": "55aef1ce-4054-4d38-a5ff-2a2b01e7d832", 74 | "metadata": {}, 75 | "source": [ 76 | "" 77 | ] 78 | }, 79 | { 80 | "cell_type": "markdown", 81 | "id": "d2f51d5d-3c83-4a25-97a9-da0f217831bd", 82 | "metadata": {}, 83 | "source": [ 84 | "An **Operating System** can be defined as an **interface between user and hardware**. It is responsible for the execution of all the processes, Resource Allocation, CPU management, File Management and many other tasks." 85 | ] 86 | }, 87 | { 88 | "cell_type": "markdown", 89 | "id": "9fb7b9bc-6498-4e6b-86d3-664e2d2d6d77", 90 | "metadata": {}, 91 | "source": [ 92 | "An Operating System can be defined as an interface between user and hardware. It is responsible for the execution of all the processes, Resource Allocation, CPU\n", 93 | "management, File Management and many other tasks." 94 | ] 95 | }, 96 | { 97 | "cell_type": "markdown", 98 | "id": "5c4776e3-f816-46c0-982d-726ab7634b57", 99 | "metadata": {}, 100 | "source": [ 101 | "\n", 102 | "\n", 103 | "# Process Management in OS" 104 | ] 105 | }, 106 | { 107 | "cell_type": "markdown", 108 | "id": "29245e45-1a16-4818-90e3-6f5a6c536008", 109 | "metadata": {}, 110 | "source": [ 111 | "" 112 | ] 113 | }, 114 | { 115 | "cell_type": "markdown", 116 | "id": "dc971fed-5174-4586-858f-2f68a281f02b", 117 | "metadata": {}, 118 | "source": [ 119 | "A Program does nothing unless its instructions are executed by a CPU. A program in execution is called a process. In order to accomplish its task, process needs the computer resources." 120 | ] 121 | }, 122 | { 123 | "cell_type": "markdown", 124 | "id": "dff9b3c7-5715-4dab-9d2e-4c2f0472fc79", 125 | "metadata": {}, 126 | "source": [ 127 | "There may exist more than one process in the system which may require the same resource at the same time. Therefore, the operating system has to manage all the processes and the resources in a convenient and efficient way." 128 | ] 129 | }, 130 | { 131 | "cell_type": "markdown", 132 | "id": "1ae83522-e5f2-49c2-ae9b-7e59fb188f78", 133 | "metadata": {}, 134 | "source": [ 135 | "Some resources may need to be executed by one process at one time to maintain the consistency otherwise the system can become inconsistent and deadlock may occur." 136 | ] 137 | }, 138 | { 139 | "cell_type": "markdown", 140 | "id": "e623c5d3-1c48-4de4-a1fc-4b6a0fab5ba9", 141 | "metadata": {}, 142 | "source": [ 143 | "The operating system is responsible for the following activities in connection with Process Management:\n", 144 | "- Scheduling processes and threads on the CPUs.\n", 145 | "- Creating and deleting both user and system processes.\n", 146 | "- Suspending and resuming processes.\n", 147 | "- Providing mechanisms for process synchronization.\n", 148 | "- Providing mechanisms for process communication." 149 | ] 150 | }, 151 | { 152 | "cell_type": "markdown", 153 | "id": "c05fb734-075a-4942-a61c-e05f3d6121f9", 154 | "metadata": {}, 155 | "source": [ 156 | "Read More: https://www.javatpoint.com/os-tutorial" 157 | ] 158 | }, 159 | { 160 | "cell_type": "markdown", 161 | "id": "8d2bd6d2-ccef-4f7c-bc94-0a17b41e3ff0", 162 | "metadata": {}, 163 | "source": [ 164 | "\n", 165 | "\n", 166 | "# Types of Operating Systems" 167 | ] 168 | }, 169 | { 170 | "cell_type": "markdown", 171 | "id": "eba2047d-e7a2-40c1-becd-65ce367074e3", 172 | "metadata": {}, 173 | "source": [ 174 | "" 175 | ] 176 | }, 177 | { 178 | "cell_type": "markdown", 179 | "id": "2f7ed09d-08bb-48a3-969e-daf2f0bb15a4", 180 | "metadata": {}, 181 | "source": [ 182 | "Operating systems usually come **pre-loaded** on any computer you buy. Most people use the operating system that comes with their computer, but it's possible to upgrade or even change operating systems. The three most common operating systems for personal computers are **Microsoft Windows**, **macOS**, and **Linux**." 183 | ] 184 | }, 185 | { 186 | "cell_type": "markdown", 187 | "id": "6dc43b41-6cf9-4b6f-aa3c-329ecfb1a9dc", 188 | "metadata": {}, 189 | "source": [ 190 | "Modern operating systems use a **graphical user interface**, or GUI (pronounced **gooey**). A GUI lets you use your mouse to click **icons**, **buttons**, and **menus**, and everything is clearly displayed on the screen using a combination of graphics and text." 191 | ] 192 | }, 193 | { 194 | "cell_type": "markdown", 195 | "id": "44e48cf4-fed3-4a53-a512-fa387e99a4c9", 196 | "metadata": {}, 197 | "source": [ 198 | "Each operating system's GUI has a different look and feel, so if you switch to a different operating system it may seem unfamiliar at first. However, modern operating systems are designed to be **easy to use**, and most of the basic principles are the same." 199 | ] 200 | }, 201 | { 202 | "cell_type": "markdown", 203 | "id": "d9e5249a-e948-435a-94de-eb46cd0944f2", 204 | "metadata": {}, 205 | "source": [ 206 | "But this wasn't allways the case! Let's take it from the top. This is going to be fun, I promise!" 207 | ] 208 | }, 209 | { 210 | "cell_type": "markdown", 211 | "id": "dbaa2510-6d62-4e2c-9bc0-338c438be1d4", 212 | "metadata": {}, 213 | "source": [ 214 | "In the beginning, there was UNIX. This was an operating system so that BIG computers could run programs and talk to each other. It was developed at Bell Labs. It wasn’t important for Bell to control who got a copy of the software, since the computers to run it were rare anyway. Other companies licensed UNIX from Bell and made their own versions." 215 | ] 216 | }, 217 | { 218 | "cell_type": "markdown", 219 | "id": "f2cd14b2-1cbb-46a5-bef1-d1acc9c89b16", 220 | "metadata": {}, 221 | "source": [ 222 | "Computers got more common, so Bell got more restrictive. It eventually went to court to try to shut down the Berkeley Software Distribution (BSD) version of UNIX, which was being given away for free. It failed, because it had lost its copyright over the software. The decision in the trial was kept secret until 2004. These days, there are several versions of BSD UNIX." 223 | ] 224 | }, 225 | { 226 | "cell_type": "markdown", 227 | "id": "c7d7a4fc-dd53-419e-bcf1-3338f29b7fa6", 228 | "metadata": {}, 229 | "source": [ 230 | "" 231 | ] 232 | }, 233 | { 234 | "cell_type": "markdown", 235 | "id": "4f10c753-60bc-426c-8865-3b2046e31063", 236 | "metadata": {}, 237 | "source": [ 238 | "\n", 239 | "\n", 240 | "## Linux" 241 | ] 242 | }, 243 | { 244 | "cell_type": "markdown", 245 | "id": "12e4d84a-8ccc-4ef8-bba1-5d999c09b545", 246 | "metadata": {}, 247 | "source": [ 248 | "While the outcome of the UNIX trial was uncertain, a Finnish university student named Linus Torvalds wrote a “kernel” for a UNIX system that he could run on his personal computer. He combined that with a bunch of programs written for the Free Software Foundation, which had just about everything needed for a UNIX-style operating system except the kernel. Together, they made **Linux**. It’s like UNIX, but since the kernel is different, it isn’t called UNIX." 249 | ] 250 | }, 251 | { 252 | "cell_type": "markdown", 253 | "id": "a20844d9-5f0a-47e4-9642-b4cd87574481", 254 | "metadata": {}, 255 | "source": [ 256 | "Linux (the kernel) has since been combined with an Operating System called GNU (stands for “GNU’S NOT UNIX”) to make the fully operational GNU/Linux (what you call, erroneously, Linux). Many different vendors and communities started packaging GNU/Linux with some other software to produce different OS distributions, called distributions (\"distros\") for short, and the most famous of them these days are Ubuntu (put out by a company called Canonical), Fedora (put out by a company called Red Hat) and Mint (a community-driven project)." 257 | ] 258 | }, 259 | { 260 | "cell_type": "markdown", 261 | "id": "d9008b05-fdf8-4e78-9678-f8343fc59566", 262 | "metadata": {}, 263 | "source": [ 264 | "\n", 265 | "\n", 266 | "## Mac OS" 267 | ] 268 | }, 269 | { 270 | "cell_type": "markdown", 271 | "id": "c169d351-a647-4e51-9fb2-874de0063555", 272 | "metadata": {}, 273 | "source": [ 274 | "The **Mac OS** was originally an Apple-only operating system, written from scratch, and mostly famous for its excellent user interface. You know, the whole “Windows, icons, menus, pointer” or WIMP interface that everyone is using now. Later, it decided to adapt a BSD UNIX as its kernel, so it is, strictly speaking, a UNIX itself. It just doesn’t look like the others, and you’re not supposed to run it on non-Apple computers." 275 | ] 276 | }, 277 | { 278 | "cell_type": "markdown", 279 | "id": "599a5c83-e917-4b99-80ea-ab012cc7a94f", 280 | "metadata": {}, 281 | "source": [ 282 | "" 283 | ] 284 | }, 285 | { 286 | "cell_type": "markdown", 287 | "id": "18650bd8-527d-4deb-9bb6-022b4b84852a", 288 | "metadata": {}, 289 | "source": [ 290 | "\n", 291 | "\n", 292 | "## Windows" 293 | ] 294 | }, 295 | { 296 | "cell_type": "markdown", 297 | "id": "2cc3325a-cdde-4862-a389-39b1fe42834c", 298 | "metadata": {}, 299 | "source": [ 300 | "**Windows** was originally a WIMP interface for Microsoft’s Disk Operating System, or DOS. A pretty wimpy interface it was, too, until about version 3.3, when people began to find using it less painful than having root canals. It is the one mainstream operating system that is not UNIX or derived from UNIX. Before Windows NT, it was derived from DOS; Windows NT and after are derived from an operating system called VMS." 301 | ] 302 | }, 303 | { 304 | "cell_type": "markdown", 305 | "id": "111c4b17-f0ff-42ea-8c30-2aadf7542e9d", 306 | "metadata": {}, 307 | "source": [ 308 | "" 309 | ] 310 | }, 311 | { 312 | "cell_type": "markdown", 313 | "id": "fe8f546d-a249-4ed8-801f-b87866ee7db5", 314 | "metadata": {}, 315 | "source": [ 316 | "\n", 317 | "\n", 318 | "# Operating Systems for Mobile Devices" 319 | ] 320 | }, 321 | { 322 | "cell_type": "markdown", 323 | "id": "972f15dc-6a5d-46a5-93f2-5518c1914fbe", 324 | "metadata": {}, 325 | "source": [ 326 | "The operating systems we've been talking about so far were designed to run on desktop and laptop computers. Mobile devices such as phones, tablet computers, and MP3 players are different from desktop and laptop computers, so they run operating systems that are designed specifically for mobile devices. Examples of mobile operating systems include Apple iOS and Google Android. In the screenshot below, you can see iOS running on an iPad." 327 | ] 328 | }, 329 | { 330 | "cell_type": "markdown", 331 | "id": "9e84fda5-809d-44b0-9b1b-201ee994cd80", 332 | "metadata": {}, 333 | "source": [ 334 | "" 335 | ] 336 | }, 337 | { 338 | "cell_type": "markdown", 339 | "id": "52166cc6-da3f-49f8-b6b8-c190b3576e7c", 340 | "metadata": {}, 341 | "source": [ 342 | "Operating systems for mobile devices generally aren't as fully featured as those made for desktop and laptop computers, and they aren't able to run all of the same software. However, you can still do a lot of things with them, like watch movies, browse the Web, manage your calendar, and play games." 343 | ] 344 | }, 345 | { 346 | "cell_type": "markdown", 347 | "id": "daab96ce-04bd-4731-92cb-aeadb83bb464", 348 | "metadata": {}, 349 | "source": [ 350 | "\n", 351 | "\n", 352 | "# Conclusion" 353 | ] 354 | }, 355 | { 356 | "cell_type": "markdown", 357 | "id": "2deac8ff-f9cf-47c4-ac02-65103cb9bc80", 358 | "metadata": {}, 359 | "source": [ 360 | "That's it. Now you have a basic understanding of the purpose of operating systems and how they work under the hood." 361 | ] 362 | }, 363 | { 364 | "cell_type": "markdown", 365 | "id": "80499577-9e50-4325-9fd2-364dbb9aa2ce", 366 | "metadata": {}, 367 | "source": [ 368 | "In this course, we follow Ubuntu (the most common GNU/Linux distro) for the purposes of data science. Since Ubuntu and Mac-OS are unix based, 99% of what you learn from Ubuntu for data science purposes is applicable to Mac OS as well, especially when it comes to using terminal (You'll learn what it is later, that's the cool usually black screen you see in hacker/tech movies)." 369 | ] 370 | }, 371 | { 372 | "cell_type": "markdown", 373 | "id": "42485053-16c1-4e0d-baa1-bebbd5b09ed0", 374 | "metadata": {}, 375 | "source": [ 376 | "If you only have experience with windows as operating systems and it is hard for you to switch, don't worry. You don't have to immediately jump into linux. You can use **Windows Subsytem for Linux**. The Windows Subsystem for Linux lets developers run a GNU/Linux environment --including most command-line tools, utilities, and applications-- directly on Windows, unmodified, without the overhead of a traditional virtual machine or dualboot setup. We will cover how to set it up in the later sections." 377 | ] 378 | }, 379 | { 380 | "cell_type": "markdown", 381 | "id": "84459ef9-5a61-42c3-9cde-3578f4ce40c8", 382 | "metadata": {}, 383 | "source": [ 384 | "However, after feeling confident with WSL, we highly recommend you to switch to either one of linux distros (preferably Ubuntu) or Mac-OS for data science purposes." 385 | ] 386 | } 387 | ], 388 | "metadata": { 389 | "kernelspec": { 390 | "display_name": "Python 3", 391 | "language": "python", 392 | "name": "python3" 393 | }, 394 | "language_info": { 395 | "codemirror_mode": { 396 | "name": "ipython", 397 | "version": 3 398 | }, 399 | "file_extension": ".py", 400 | "mimetype": "text/x-python", 401 | "name": "python", 402 | "nbconvert_exporter": "python", 403 | "pygments_lexer": "ipython3", 404 | "version": "3.8.11" 405 | } 406 | }, 407 | "nbformat": 4, 408 | "nbformat_minor": 5 409 | } 410 | -------------------------------------------------------------------------------- /Linux/01 Introduction/04 Linux Terminal Basics.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "4f6cf3f2-e8b5-4db2-97c3-86a7ced8c243", 6 | "metadata": {}, 7 | "source": [ 8 | "" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "id": "d232a9ab-4018-4d8c-8b84-0ade1454cfbc", 14 | "metadata": {}, 15 | "source": [ 16 | "# Linux Terminal \n" 17 | ] 18 | }, 19 | { 20 | "cell_type": "markdown", 21 | "id": "9664b43f", 22 | "metadata": {}, 23 | "source": [ 24 | "## Table of Contents \n", 25 | "* [Opening a terminal](#opening_a_terminal)\n", 26 | "* [A sense of location](#a_sense_of_location)\n", 27 | "* [Relative and absolute paths](#relative_and_absolute_paths)\n", 28 | "\n", 29 | "---" 30 | ] 31 | }, 32 | { 33 | "cell_type": "markdown", 34 | "id": "dc42a736-06cf-4076-9dd0-22f4f50e3ae5", 35 | "metadata": {}, 36 | "source": [ 37 | "The Linux command line is a text interface to your computer. Often referred to as the shell, terminal, console, prompt or various other names, it can give the appearance of being complex and confusing to use. Yet the ability to copy and paste commands from a website, combined with the power and flexibility the command line offers, means that using it may be essential when trying to follow instructions online, including many on this very website!\n", 38 | "\n", 39 | "This tutorial will teach you a little of the history of the command line, then walk you through some practical exercises to become familiar with a few basic commands and concepts. We’ll assume no prior knowledge, but by the end we hope you’ll feel a bit more comfortable the next time you’re faced with some instructions that begin “Open a terminal”." 40 | ] 41 | }, 42 | { 43 | "cell_type": "markdown", 44 | "id": "b2ae58b9-ba3b-41e7-bf94-2c3f91dd729e", 45 | "metadata": {}, 46 | "source": [ 47 | "What you’ll need\n", 48 | "- A computer running WSL or Ubuntu or some other version of Linux or a Mac laptop (Mac-OS is unix based also if you remember from prior sessions)." 49 | ] 50 | }, 51 | { 52 | "cell_type": "markdown", 53 | "id": "29b31640-9aed-4351-91fc-1eb537f52979", 54 | "metadata": {}, 55 | "source": [ 56 | "Every Linux system includes a command line of one sort or another. This tutorial includes some specfic steps for Ubuntu 18.04 but most of the content should work regardless of your Linux distribution. That's also the case for WSL and Mac-OS terminal." 57 | ] 58 | }, 59 | { 60 | "cell_type": "markdown", 61 | "id": "c37fe82f-9070-4f47-a3dc-5e760fe44206", 62 | "metadata": {}, 63 | "source": [ 64 | "> **Note:** These materials are designed for Linux OS, but most, if not all, of the content should work on WSL and Mac OS as well." 65 | ] 66 | }, 67 | { 68 | "cell_type": "markdown", 69 | "id": "aa779548-04e5-49e8-a9c3-e70fffa76146", 70 | "metadata": {}, 71 | "source": [ 72 | "\n", 73 | "\n", 74 | "\n", 75 | "## Opening a terminal" 76 | ] 77 | }, 78 | { 79 | "cell_type": "markdown", 80 | "id": "dd64afcc-4796-475f-a6dd-582c8d21436a", 81 | "metadata": {}, 82 | "source": [ 83 | "On a Ubuntu 18.04 system you can find a launcher for the terminal by clicking on the Activities item at the top left of the screen, then typing the first few letters of “terminal”, “command”, “prompt” or “shell”. Yes, the developers have set up the launcher with all the most common synonyms, so you should have no problems finding it." 84 | ] 85 | }, 86 | { 87 | "cell_type": "markdown", 88 | "id": "df943bb5-f1c8-49e8-a80f-a1cd4805fe29", 89 | "metadata": {}, 90 | "source": [ 91 | "" 92 | ] 93 | }, 94 | { 95 | "cell_type": "markdown", 96 | "id": "7a7aac50-c14b-41f1-9ff3-c643dbc971e6", 97 | "metadata": {}, 98 | "source": [ 99 | "Other versions of Linux, or other flavours of Ubuntu, will usually have a terminal launcher located in the same place as your other application launchers. It might be hidden away in a submenu or you might have to search for it from within your launcher, but it’s likely to be there somewhere." 100 | ] 101 | }, 102 | { 103 | "cell_type": "markdown", 104 | "id": "b4d26ae1-0a62-44c4-83c7-ec90be4f0013", 105 | "metadata": {}, 106 | "source": [ 107 | "If you can’t find a launcher, or if you just want a faster way to bring up the terminal, most Linux systems use the same default keyboard shortcut to start it: **Ctrl-Alt-T**." 108 | ] 109 | }, 110 | { 111 | "cell_type": "markdown", 112 | "id": "8370765c-4b67-4792-93ae-442bce78bcdb", 113 | "metadata": {}, 114 | "source": [ 115 | "However you launch your terminal, you should end up with a rather dull looking window with an odd bit of text at the top, much like the image below. Depending on your Linux system the colours may not be the same, and the text will likely say something different, but the general layout of a window with a large (mostly empty) text area should be similar." 116 | ] 117 | }, 118 | { 119 | "cell_type": "markdown", 120 | "id": "7408f120-5111-4960-9c5b-e96452b41060", 121 | "metadata": {}, 122 | "source": [ 123 | "Linux, WSL, and Mac OS terminals (and terminals in general) look pretty much the same. After all, they are just a text interface." 124 | ] 125 | }, 126 | { 127 | "cell_type": "markdown", 128 | "id": "070ebed9-64a7-4665-b0fb-a568d8b92eb1", 129 | "metadata": {}, 130 | "source": [ 131 | "Linux | WSL | Mac\n", 132 | "- | - | -\n", 133 | " | | " 134 | ] 135 | }, 136 | { 137 | "cell_type": "markdown", 138 | "id": "ec3a3d24-602c-474d-96ec-02b34a056ce2", 139 | "metadata": {}, 140 | "source": [ 141 | "Let’s run our first command. Click the mouse into the window to make sure that’s where your keystrokes will go, then type the following command, all in lower case, before pressing the Enter or Return key to run it." 142 | ] 143 | }, 144 | { 145 | "cell_type": "markdown", 146 | "id": "ad4524b4-37ae-4afa-bf00-c71077b066dc", 147 | "metadata": {}, 148 | "source": [ 149 | "```bash\n", 150 | "$ pwd\n", 151 | "```" 152 | ] 153 | }, 154 | { 155 | "cell_type": "markdown", 156 | "id": "2f3174d8-9b2d-4844-ab38-0498cd0ba090", 157 | "metadata": {}, 158 | "source": [ 159 | "You should see a directory path printed out (probably something like `/home/YOUR_USERNAME`), then another copy of that odd bit of text." 160 | ] 161 | }, 162 | { 163 | "cell_type": "markdown", 164 | "id": "c6c749f2-7b56-4b2c-b244-163ad9f33755", 165 | "metadata": {}, 166 | "source": [ 167 | "" 168 | ] 169 | }, 170 | { 171 | "cell_type": "markdown", 172 | "id": "40701eee-3335-4787-8782-2172929e26fa", 173 | "metadata": {}, 174 | "source": [ 175 | "There are a couple of basics to understand here, before we get into the detail of what the command actually did. First is that when you type a command it appears on the same line as the odd text. That text is there to tell you the computer is ready to accept a command, it’s the computer’s way of prompting you. In fact it’s usually referred to as the prompt, and you might sometimes see instructions that say “bring up a prompt”, “open a command prompt”, “at the bash prompt” or similar. They’re all just different ways of asking you to open a terminal to get to a shell." 176 | ] 177 | }, 178 | { 179 | "cell_type": "markdown", 180 | "id": "7cd652ca-20d2-439e-a8fb-c3049e653d33", 181 | "metadata": {}, 182 | "source": [ 183 | "On the subject of synonyms, another way of looking at the prompt is to say that there’s a line in the terminal into which you type commands. A command line, if you will. Again, if you see mention of “command line”, it’s just another way of talking about a shell running in a terminal." 184 | ] 185 | }, 186 | { 187 | "cell_type": "markdown", 188 | "id": "b77cacd7-3386-40d3-8440-89987b240b85", 189 | "metadata": {}, 190 | "source": [ 191 | "> **The importance of case**\n", 192 | "Be extra careful with case when typing in the command line. Typing `PWD` instead of `pwd` will produce an error, but sometimes the wrong case can result in a command appearing to run, but not doing what you expected. We’ll look at case a little more on the next page but, for now, just make sure to type all the following lines in exactly the case that’s shown." 193 | ] 194 | }, 195 | { 196 | "cell_type": "markdown", 197 | "id": "2f9fb643-bce2-4080-aa14-bf153f3405c4", 198 | "metadata": {}, 199 | "source": [ 200 | "\n", 201 | "\n", 202 | "\n", 203 | "## A sense of location" 204 | ] 205 | }, 206 | { 207 | "cell_type": "markdown", 208 | "id": "6e4828d2-945e-42da-b82f-428eb5ad9c6b", 209 | "metadata": {}, 210 | "source": [ 211 | "Now to the command itself. `pwd` is an abbreviation of \"**p**rint **w**orking **d**irectory\". All it does is print out the shell’s current working directory. But what’s a **working directory**?" 212 | ] 213 | }, 214 | { 215 | "cell_type": "markdown", 216 | "id": "41fa5a2c-c188-4ac5-94b6-91d57a13f091", 217 | "metadata": {}, 218 | "source": [ 219 | "One important concept to understand is that the shell has a notion of a default location in which any file operations will take place. This is its working directory. If you try to create new files or directories, view existing files, or even delete them, the shell will assume you’re looking for them in the current working directory unless you take steps to specify otherwise. So it’s quite important to keep an idea of what directory the shell is “in” at any given time, after all, deleting files from the wrong directory could be disastrous. If you’re ever in any doubt, the `pwd` command will tell you exactly what the current working directory is" 220 | ] 221 | }, 222 | { 223 | "cell_type": "markdown", 224 | "id": "cd7922ad-8d1c-4fe1-9ecb-9330ab568a79", 225 | "metadata": {}, 226 | "source": [ 227 | "You can change the working directory using the `cd` command, an abbreviation for ‘change directory’. Try typing the following:\n", 228 | "\n", 229 | "```bash\n", 230 | "$ cd /\n", 231 | "$ pwd\n", 232 | "```" 233 | ] 234 | }, 235 | { 236 | "cell_type": "markdown", 237 | "id": "f0dd9b92-787a-4495-b8c5-15179daa27c3", 238 | "metadata": {}, 239 | "source": [ 240 | "> Note that the directory separator is a forward slash (\"`/`\"), not the backslash that you may be used to from Windows or DOS systems" 241 | ] 242 | }, 243 | { 244 | "cell_type": "markdown", 245 | "id": "11e0592c-3f9f-4da2-a78e-f945f435318d", 246 | "metadata": {}, 247 | "source": [ 248 | "> Too many roots\n", 249 | "Beware: although the `/` directory is sometimes referred to as the root directory, the word **root** has another meaning. root is also the name that has been used for the superuser since the early days of Unix. The superuser, as the name suggests, has more powers than a normal user, so can easily wreak havoc with a badly typed command. We’ll look at the superuser account more in later sections. For now you only have to know that the word **root** has multiple meanings in the Linux world, so context is important." 250 | ] 251 | }, 252 | { 253 | "cell_type": "markdown", 254 | "id": "754893fa-4d05-4f55-8077-07a5f6e5e682", 255 | "metadata": {}, 256 | "source": [ 257 | "From the root directory, the following command will move you into the **home** directory (which is an immediate subdirectory of `/`):\n", 258 | "\n", 259 | "```bash\n", 260 | "$ cd home\n", 261 | "$ pwd\n", 262 | "```" 263 | ] 264 | }, 265 | { 266 | "cell_type": "markdown", 267 | "id": "bb4442a0-4860-4835-941d-540c6b7b8ce0", 268 | "metadata": {}, 269 | "source": [ 270 | "To go up to the parent directory, in this case back to `/`, use the special syntax of two dots (`..`) when changing directory (note the space between `cd` and `..`, unlike in DOS you can’t just type `cd..` as one command):\n", 271 | "\n", 272 | "```bash\n", 273 | "$ cd ..\n", 274 | "$ pwd\n", 275 | "```" 276 | ] 277 | }, 278 | { 279 | "cell_type": "markdown", 280 | "id": "8973db0d-26a5-4f72-9988-91dd055a6acd", 281 | "metadata": {}, 282 | "source": [ 283 | "Typing cd on its own is a quick shortcut to get back to your home directory:\n", 284 | "\n", 285 | "```bash\n", 286 | "$ cd\n", 287 | "$ pwd\n", 288 | "```" 289 | ] 290 | }, 291 | { 292 | "cell_type": "markdown", 293 | "id": "08f18887-da08-44cf-8111-083cc7dfb4f6", 294 | "metadata": {}, 295 | "source": [ 296 | "You can also use `..` more than once if you have to move up through multiple levels of parent directories:\n", 297 | "\n", 298 | "```bash\n", 299 | "$ cd ../..\n", 300 | "$ pwd\n", 301 | "```" 302 | ] 303 | }, 304 | { 305 | "cell_type": "markdown", 306 | "id": "4a9bfbcb-34f6-4f8c-8565-29978ebc56c9", 307 | "metadata": {}, 308 | "source": [ 309 | "Notice that in the previous example we described a route to take through the directories. The path we used means “starting from the working directory, move to the parent `/` from that new location move to the parent again”. So if we wanted to go straight from our home directory to the “etc” directory (which is directly inside the root of the file system), we could use this approach:\n", 310 | "\n", 311 | "```bash\n", 312 | "$ cd\n", 313 | "$ pwd\n", 314 | "\n", 315 | "$ cd ../../etc\n", 316 | "$ pwd\n", 317 | "```" 318 | ] 319 | }, 320 | { 321 | "cell_type": "markdown", 322 | "id": "d09175db-723f-478d-9dbd-a0aa7bb073b9", 323 | "metadata": {}, 324 | "source": [ 325 | "\n", 326 | "\n", 327 | "\n", 328 | "## Relative and absolute paths" 329 | ] 330 | }, 331 | { 332 | "cell_type": "markdown", 333 | "id": "874f52fc-c96f-4387-80d1-28581f80451d", 334 | "metadata": {}, 335 | "source": [ 336 | "Most of the examples we’ve looked at so far use relative paths. That is, the place you end up at depends on your current working directory. Consider trying to cd into the “etc” folder. If you’re already in the root directory that will work fine:\n", 337 | "\n", 338 | "```bash\n", 339 | "$ cd /\n", 340 | "$ pwd\n", 341 | "$ cd etc\n", 342 | "$ pwd\n", 343 | "```" 344 | ] 345 | }, 346 | { 347 | "cell_type": "markdown", 348 | "id": "c32f1898-3cfd-4cf8-b813-8af49fc0c91f", 349 | "metadata": {}, 350 | "source": [ 351 | "But what if you’re in your home directory?\n", 352 | "\n", 353 | "```bash\n", 354 | "$ cd\n", 355 | "$ pwd\n", 356 | "$ cd etc\n", 357 | "$ pwd\n", 358 | "```" 359 | ] 360 | }, 361 | { 362 | "cell_type": "markdown", 363 | "id": "be862d08-e303-4c12-b119-90d5a42a38e0", 364 | "metadata": {}, 365 | "source": [ 366 | "You’ll see an error saying “No such file or directory” before you even get to run the last pwd. Changing directory by specifying the directory name, or using .. will have different effects depending on where you start from. The path only makes sense relative to your working directory.\n", 367 | "\n", 368 | "But we have seen two commands that are absolute. No matter what your current working directory is, they’ll have the same effect. The first is when you run cd on its own to go straight to your home directory. The second is when you used cd / to switch to the root directory. In fact any path that starts with a forward slash is an absolute path. You can think of it as saying “switch to the root directory, then follow the route from there”. That gives us a much easier way to switch to the etc directory, no matter where we currently are in the file system:\n", 369 | "\n", 370 | "```bash\n", 371 | "$ cd\n", 372 | "$ pwd\n", 373 | "$ cd /etc\n", 374 | "$ pwd\n", 375 | "```" 376 | ] 377 | }, 378 | { 379 | "cell_type": "markdown", 380 | "id": "c2e0a591-fb0c-4a97-86f4-053399415682", 381 | "metadata": {}, 382 | "source": [ 383 | "It also gives us another way to get back to your home directory, and even to the folders within it. Suppose you want to go straight to your “Desktop” folder from anywhere on the disk (note the upper-case “D”). In the following command **you’ll need to replace USERNAME with your own username**, the `whoami` command will remind you of your username, in case you’re not sure:\n", 384 | "\n", 385 | "```bash\n", 386 | "$ whoami\n", 387 | "$ cd /home/USERNAME/Desktop\n", 388 | "$ pwd\n", 389 | "```" 390 | ] 391 | }, 392 | { 393 | "cell_type": "markdown", 394 | "id": "aebb8e31-eabb-4fd8-8bf9-d298d313bfaa", 395 | "metadata": {}, 396 | "source": [ 397 | "There’s one other handy shortcut which works as an absolute path. As you’ve seen, using “`/`” at the start of your path means “starting from the root directory”. Using the tilde character (”`~`”) at the start of your path similarly means “starting from my home directory”.\n", 398 | "\n", 399 | "```bash\n", 400 | "$ cd ~\n", 401 | "$ pwd\n", 402 | "\n", 403 | "$ cd ~/Desktop\n", 404 | "$ pwd\n", 405 | "```" 406 | ] 407 | }, 408 | { 409 | "cell_type": "markdown", 410 | "id": "409410e6-8237-4299-b0ab-0180517077cc", 411 | "metadata": {}, 412 | "source": [ 413 | "Now that odd text in the prompt might make a bit of sense. Have you noticed it changing as you move around the file system? On a Ubuntu system it shows your username, your computer’s network name and the current working directory. But if you’re somewhere inside your home directory, it will use “`~`” as an abbreviation. Let’s wander around the file system a little, and keep an eye on the prompt as you do so:\n", 414 | "\n", 415 | "```bash\n", 416 | "$ cd\n", 417 | "$ cd /\n", 418 | "$ cd ~/Desktop\n", 419 | "$ cd /etc\n", 420 | "$ cd /var/log\n", 421 | "$ cd ..\n", 422 | "$ cd\n", 423 | "```" 424 | ] 425 | }, 426 | { 427 | "cell_type": "markdown", 428 | "id": "ae0d09dc-c803-4847-9536-24c1813c0a39", 429 | "metadata": {}, 430 | "source": [ 431 | "You must be bored with just moving around the file system by now, but a good understanding of absolute and relative paths will be invaluable as we move on to later sections and learn more commmands." 432 | ] 433 | } 434 | ], 435 | "metadata": { 436 | "kernelspec": { 437 | "display_name": "Python 3", 438 | "language": "python", 439 | "name": "python3" 440 | }, 441 | "language_info": { 442 | "codemirror_mode": { 443 | "name": "ipython", 444 | "version": 3 445 | }, 446 | "file_extension": ".py", 447 | "mimetype": "text/x-python", 448 | "name": "python", 449 | "nbconvert_exporter": "python", 450 | "pygments_lexer": "ipython3", 451 | "version": "3.8.11" 452 | } 453 | }, 454 | "nbformat": 4, 455 | "nbformat_minor": 5 456 | } 457 | --------------------------------------------------------------------------------