fix(guide): simplify directory structure

This commit is contained in:
Mrugesh Mohapatra
2018-10-16 21:26:13 +05:30
parent f989c28c52
commit da0df12ab7
35752 changed files with 0 additions and 317652 deletions

View File

@@ -0,0 +1,57 @@
---
title: 10 Simple and Useful Linux Commands
---
# 10 Simple and Useful Linux Commands
The commands listed here are basic, and will help you get started quickly. But theyre also powerful, and theyll continue to be useful as your Linux expertise expands.
1. `echo` This takes the text you give it and sends it somewhere—back to the screen, to a file, or to another command. By default it echoes back to the screen, unless used with redirection `>`
Example: `echo "hello!"`
Example 2: `echo "Hello world" > hello.txt`
1. `cat` To display the contents of a text file, just type `cat myfile`.
1. `find` It does what it says, and its good at it. Use it to locate files by path, size, date, owner and a bunch of other useful filters. Example: `find . -type f -mtime -1h # List files in this directory modified in the past hour`.
1. `date` Just type date when you want to know what time it is. Example: `date "+It's %l:%m%p on %A"`. Use it in a script to name files according to the current date.
1. `ls` What's in this directory? Combine `ls` with some useful flags to display and sort directory contents by date and size. It also gives you lots of options for formatting the output.
1. `pwd` Where am I? Linux can be unforgiving, particularly when you delete something. Make sure you know are before you issue your commands.
1. `mail` Linux's mail program isnt good looking, but it can be really helpful. You can create a message and add text, recipients, and attachments all in one command. Example: `echo "We're having a great time." | mail -s "Wish you were here!" -A postcard.png -t mom@example.com`
1. `cut` When you have a string with separators in it, use `cut` to filter out certain fields. Example: `echo "this, that, and the other" | cut -d, -f2 # "that"`
1. `grep` To find lines of text that contain a certain string, use grep. Example: `grep 'root' /etc/passwd # root:x:0:0:root:/root:/bin/bash`
1. `sed` Use sed to find and change a substring in a piece of text. Example: `echo "this, that, and the other" | sed 's/that/those/' # "this, those, and the other"`
1. `shutdown` use shut down the system and turn off the power. Example: `shutdown -h now`shuts down system immediately. `shutdown -h +5` shuts down system after five minutes.
Use these commands in scripts and at the command line. They're all very powerful commands, and Linux's man page has a lot more information about each one.
***********
Also, important commands used for System Administrators are following:
1. `uptime` Command
In Linux uptime command shows since how long your system is running and the number of users are currently logged in and also displays load average for 1,5 and 15 minutes intervals.
2. `w` Command
It will displays users currently logged in and their process along-with shows load averages. also shows the login name, tty name, remote host, login time, idle time, JCPU, PCPU, command and processes.
3. `users` Command
Users command displays currently logged in users. This command dont have other parameters other than help and version.
4. `who` Command
who command simply return user name, date, time and host information. who command is similar to w command. Unlike w command who doesnt print what users are doing. Lets illustrate and see the different between who and w commands.
5. `whoami` Command
whoami command print the name of current user. You can also use “who am i” command to display the current user. If you are logged in as a root using sudo command “whoami” command return root as current user. Use “who am i” command if you want to know the exact user logged in.
6. `ls` Command
ls command display list of files in human readable format.
7. `crontab` Command
List schedule jobs for current user with crontab command and -l option.
8. `less` Command
less command allows quickly view file. You can page up and down. Press q to quit from less window.
9. `more` Command
more command allows quickly view file and shows details in percentage. You can page up and down. Press q to quit out from more window.
10. `cp` Command
Copy file from source to destination preserving same mode.
Here are the list of commands frequently used by adiminstrator.
This is not a complete but its a compact list of commands to refer when needed.

View File

@@ -0,0 +1,50 @@
---
title: Advantages of Linux
---
## Constant and efficient improvements.
Linux updates happen through the global collaboration of developers. Bugs are documented and resolved much quicker with this type of support. Also, since the developers are also the end-users they have the proper motivation to make sure it meets user's needs and that it is designed to run well.
## Less risk.
Software is only as good as the support its given. Imagine this: a piece of software is created by the company XYZ and later down the road, they go bankrupt or get bought by another company that decides to cut its support. The software would never see improvements or fixes and therefore its usefulness would inevitably erode and die. Linux is owned and operated by no single entity or company, so this situation cannot happen. More than that anyone is free to pick it up and contribute as well. The risk of losing support for Linux is very unlikely due to its overwhelming popularity and use.
## Lightweight.
Linux's requirements for running on a system are much lower than that of Windows or Mac. With the right Linux distribution a user can have a modest setup and Linux will give the system value. Disk space and memory footprint can also be lower too. Some distributions are suitable for CPUs dating back to the Pentium family, others have a requirement of as little as 128MB of RAM and around the same amount for disk space!
## Heavily documented for beginners and advanced users alike.
Linux has an active community of those willing to share their knowledge and help (much like FreeCodeCamp!). There are command line utilities built into Linux that provide documentation on commands, libraries, standards, etc. (<a href='https://en.wikipedia.org/wiki/Man_page' target='_blank' rel='nofollow'>Man pages</a> and <a href='https://en.wikipedia.org/wiki/Info_(Unix' target='_blank' rel='nofollow'>Info pages</a>), and there is documentation available on the Internet in a variety of formats including <a href='http://www.tldp.org/' target='_blank' rel='nofollow'>The Linux Documentation Project</a>, <a href='http://www.linuxquestions.org/' target='_blank' rel='nofollow'>LinuxQuestions</a>, <a href='http://serverfault.com/' target='_blank' rel='nofollow'>ServerFault</a>, and <a href='https://wiki.archlinux.org/' target='_blank' rel='nofollow'>The Arch Wiki</a>.
In addition to documentation, there are plenty of helpful and welcoming communities for newcomers to ask questions such as <a href='https://askubuntu.com/' target='_blank' rel='nofollow'>Ask Ubuntu</a> and <a href='https://www.reddit.com/r/linuxquestions/' target='_blank' rel='nofollow'> Reddit's r/linuxquestions</a>.
There are self-paced certifications that can be taken that are recognized in the IT industry (<a href='https://certification.comptia.org/certifications/linux' target='_blank' rel='nofollow'>CompTIA's Linux+</a> and <a href='https://www.lpi.org' target='_blank' rel='nofollow'>LPI's LPIC tests</a>). Although not required, learning <a href='https://en.wikipedia.org/wiki/C_(programming_language' target='_blank' rel='nofollow'>C</a>) gives the ability for a user to review the Linux code to see what they are running.
## Business support.
The world depends on Linux supporting critical systems so the demand is not going away. This is important not only to those that help contribute to Linux, but also to those who support it (Jobs!). Linux support becomes more critical in IT, but also having that knowledge as a developer will make them more rounded and useful (i.e. <a href='https://medium.com/chris-messina/the-full-stack-employee-ed0db089f0a1#.ubttrv255' target='_blank' rel='nofollow'>Full stack developers</a>).
## Interoperability with other Operating Systems.
Linux has driver support for NTFS and HFS+ filesystems (used by Windows and Macs) and also <a href='https://www.samba.org/' target='_blank' rel='nofollow'>Samba</a> for file/print service support on Windows machines.
## Better hardware support.
For other OSs, usually a user would have to go to the manufacturer's website to get driver support for different types of hardware. The Linux kernel supports a majority of hardware automatically via plug-and-play (largely in part because of the open source community). Some manufacturers also develop Linux versions of their proprietary drivers which could be easilly installed via the software repository of a distribution or by manually installing the provided binaries.
## Software Availability/Compatibility.
Linux has a rich set of applications that are available. It has <a href='https://www.libreoffice.org/discover/libreoffice/' target='_blank' rel='nofollow'>office applications</a>, web browsers (<a href='https://www.google.com/chrome/browser/desktop/' target='_blank' rel='nofollow'>Google Chrome</a> and <a href='https://www.mozilla.org/en-US/firefox/new/' target='_blank' rel='nofollow'>Mozilla Firefox</a>), <a href='http://www.videolan.org/vlc/' target='_blank' rel='nofollow'>media players</a>, <a href='https://www.gimp.org/' target='_blank' rel='nofollow'>image</a>/<a href='http://www.openshot.org/' target='_blank' rel='nofollow'>video processing</a>, etc. For video gaming, <a href='http://store.steampowered.com/about/' target='_blank' rel='nofollow'>Steam</a> runs on Linux which has many supported games. Windows applications can also run within Linux (see <a href='https://www.winehq.org/' target='_blank' rel='nofollow'>Wine</a> for details).
## Built for development.
As Linux was originally made for developers by developers, they have spent much time and effort perfecting the tools that they would come to use. It has a powerful <a href='https://en.wikipedia.org/wiki/Unix_shell' target='_blank' rel='nofollow'>shell</a> that can be used for a variety of both programming and administrative tasks (<a href='https://en.wikipedia.org/wiki/Bash_(Unix_shell' target='_blank' rel='nofollow'>Bash</a>) is the most popular and default choice for Linux). While Linux has a "notepad" equivalent in <a href='https://en.wikipedia.org/wiki/Gedit' target='_blank' rel='nofollow'>gedit</a>, it also provides more powerful and customizable text-based editors such as <a href='https://en.wikipedia.org/wiki/Vim_(text_editor)' target='_blank' rel='nofollow'>Vim</a>) and <a href='https://en.wikipedia.org/wiki/Emacs' target='_blank' rel='nofollow'>Emacs</a> (It is recommended Linux users know at least one of these editors). There are also IDEs available for web-development such as <a href='https://atom.io/' target='_blank' rel='nofollow'>Atom</a>, <a href='http://www.aptana.com/' target='_blank' rel='nofollow'>Aptana</a>/<a href='https://eclipse.org/' target='_blank' rel='nofollow'>Eclipse</a>, <a href='https://www.sublimetext.com/' target='_blank' rel='nofollow'>Sublime</a>, <a href='http://komodoide.com/' target='_blank' rel='nofollow'>KomodoIDE</a>, to name a few. Linux also can utilize software such as <a href='https://httpd.apache.org/' target='_blank' rel='nofollow'>Apache</a> to setup a local web server for testing, <a href='https://git-scm.com/' target='_blank' rel='nofollow'>Git</a> for version control, and other tools/languages such as <a href='https://nodejs.org/en/' target='_blank' rel='nofollow'>Node.js</a>/<a href='https://www.ruby-lang.org/en/' target='_blank' rel='nofollow'>Ruby</a>/<a href='http://sass-lang.com/' target='_blank' rel='nofollow'>SaSS</a>/<a href='https://www.heroku.com/' target='_blank' rel='nofollow'>Heroku</a> all have support on Linux and have command line tools that can be used in lieu of a GUI.
## Customizable.
Linux allows user to change desktop design and themes, add widgets and more. These changes can be done with desktop environments. Different environments have different set of options. Some popular ones are : KDE, GNOME, XFCE, Pantheon.
## It's Free.
Hard to beat that!

View File

@@ -0,0 +1,56 @@
---
title: Basic Linux Commands
---
## Basic Linux Commands
When starting out with linux, there are some basic commands everyone should know.
 1. **cd** - change directory
- cd followed by a directory or file path will take you inside that directory(folder).
 2. **ls** - list command
- Type `ls` and the contents of the current directory will be displayed.
- Two common flags used with `ls` are `-l` and `-a`, they can be used together and chained as such: `ls -la`. The `-l` flag will show you files in list order and in long format including a display of permissions, `-a` will show dot type files which are typically hidden in a GUI file finder such as `.env` files
- Flag ordering does not matter, so the previous command could be written as `ls -al`
 3. **man** - manual command
- Shows you the manual for the following command. This is very helpful when trying to figure out how an unfamiliar command works. For example, type `man ls` for everything you need to know about the ls command. Type `q` to exit.
 4. **pwd** - path
- Type `pwd` to display the path to your current directory.
 5. **mkdir** - make directory
- This command, followed by the name you wish to name your directory, creates a new directory. `mkdir folder1` will make a new directory called folder1.
 6. **rmdir** - remove directory
- Removes the directory that follows the command. `rmdir folder1` will delete the directory named folder1 if it exists.
 7. **rm** - remove
- This command removes files, not directories. `rm file.txt` will remove the file named file.txt as long as it exists and is in the current directory.
 8. **touch** - creates file
- The touch command is used to create a file. It can be anything, from an empty txt file to an empty zip file. 'touch new.txt' will create a new file with name new.
 9. **mv** - move
- Use the mv command to move files through the command line. We can also use the mv command to rename a file. For example, if we want to rename the file “text” to “new”, we can use 'mv text new'.
 10. **right-click** - copy and paste
- This one is less of a command and more of a how-to, however, it is very useful for doing almost anything in a terminal on linux. To begin, highlight text like normal and then "right-click" on your mouse to copy a selection. You should see the highlighted portion become un-highlighted, this means you copied the selection. Now "right-click" on where you want to paste the selection and you're done.
 11. **less** - view file content
- Use `less filename.txt` to view contents of a file and navigate through them. By default, less will go through the file page by page.
12. **cat** - display file's textual contents
- Use this command to display text from within a given file on your terminal. Entering `cat myFile.txt` in your terminal will display the contents of the file `myFile.txt` on screen. The `cat` command can be a very handy tool when used with the terminal _pipes_.
13. **clear** - clear terminal
- Use `clear` to simply clear all output from your terminal.
14. **cp** - copy files and directories
- Use 'cp' to copy a file or a direcotry with files inside it to another location using command 'cp CURRENT_FILE-LOCATION DESTINATION_FOLDER'. Add '-r' flag to copy a directory that is not empty.
### Useful Resources for Practice:
- [JSLinux](https://bellard.org/jslinux/vm.html?url=https://bellard.org/jslinux/buildroot-x86.cfg): Run the terminal inside your browser. Great for practice.
- [LearnShell](https://www.learnshell.org/): Interactive Linux shell (terminal) tutorials.
- [LinuxJourney](https://linuxjourney.com/lesson/the-shell): A collection of beginner-friendly terminal tutorials.

View File

@@ -0,0 +1,31 @@
---
title: common terms every Linux user should know.
---
# Common terms every Linux user should know.
* <strong>Distro:</strong> it is a shortened word for distribution; and a distribution is a particular brand of GNU/Linux operating system like Redhat, Fedora, Ubuntu, and Debian.
* <strong>Shell:</strong> this is the program that reads your command input and runs the specified commands. The dollar sign (`$) preceding the cursor is called the shell prompt; it tells you that the system is ready and waiting for inputs in the form of commands.
* <strong>CLI:</strong> stands for <em>Command Line Interface</em>. Its the simple user interface that provides the services needed by the user to interact with Linux OS using text commands. It protect the user from having to know intricate hardware details.
* <strong>GUI:</strong> stands for graphic user interface. It is the part of the Linux system that comprises windows, icon, pictures (graphics in general), that make point and click possible.
* <strong>Terminal:</strong> is an application that is used to access the Linux shell.
* <strong>Kernel:</strong> this the core of the Linux system what you could call a “brain”. The kernel controls the resources of a computer and determines how they are used by interacting directly with the computer hardware.
* <strong>Tux:</strong> it is the official mascot of Linux. That is the penguin that is usually associated with Linux if youve seen the yellow and black penguin online, then you have seen tux.
* <strong>Root:</strong> also known as the super-user, is the "default" username for the administrator of a linux machine. It is usally represented on the linux terminal witjh the <strong>"#"</strong> symbol.
* <strong>Commands:</strong> are text inputs or instruction given to the linux machine (by typing it in the terminal) to tell it what to do (that is, for a required outcome).
* <strong>Repository:</strong> a repository (or “repo” for short) is a collection of software packages for a distro usually hosted online. Software programs can be installed from both the default repositories provided by the distro and third-party ones when theyre added to the package manager.
* <strong>Package Manager:</strong> is a software program that enables you to search, install, update, and remove apps and other application management functions. Every distro has graphic from end package managers (like the Ubuntu Software Centre) and command line package management tools like the “apt-get”.
* <strong>Dependency:</strong> a dependency is a software program that the program you want to install needs to run. When a program is being installed it gives a list of its dependencies to the default package manager to check if they are already installed, and download them from a repository if theyre not.

View File

@@ -0,0 +1,21 @@
---
title: Create a dummy file with a specific size
---
## How to create dummy files with a specific size using the "dd" command:
The "dd" command can be used to create a file of a specific size. This is useful if you would like to test download speeds, or any other tests, and need a file of a specific size.
```
dd if=/dev/zero of=file_name.txt bs=1024k count=10
```
This will create a file of 1MB called file_name.txt.
bs is your byte size and count represent the number of blocks. An easy way to look at is 1024K X 10.
Here is an even simpler way to create a 1MB file:
```
dd if=/dev/zero of=file_name.txt bs=1MB count=1
```

View File

@@ -0,0 +1,38 @@
---
title: Getting Started
---
## Choosing a distribution.
There are various types of Linux distributions to choose from nowadays, choosing one is a major concern in the currently Linux world. Taking in consideration easy to use OSs, the top dogs in this category are:
Ubuntu - Derivative of the stable Debian system, Ubuntu thrives in the a easy to use and up to date environment.
Mint - Based on Ubuntu and Debian, this OS has great features like Ubuntu's PPA compatibility, the apt package manager. The base mint distribution remind of Windows, this can be a nice characteristic for users comming from Windows.
Trisquel - A distribution derived from Ubuntu that focuses on only utilizing fully free software, avoiding proprietary software. Trisquel is endorsed by the Free Software Foundation (FSF).
## Installing.
Most Linux distributions are extremely easy to install, all information is show between each step of the installation.
One important step to look out for is when deciding where to install your new Linux distro. For first users it's better to choose the "Guided" option as it will do all the work for you.
Remember to read all the steps carefully and leave some space in your HDD for the new distro, i would say about 30Gb minimum is a nice to have.
## The dreaded Terminal.
Linux's terminal is not to be feared, actually it is quite easy to use with some practice and it can make our daily task greatly automated.
In Debian/Ubuntu and derivatives, the shortcut to open the cli (Comman Line Interface) is "Ctrl + Alt + T". Let's open the terminal and try some commands.
cd (Change Directory) - The cd command is one of the commands you will use the most at the command line in linux. It allows you to change your working directory. You use it to move around within the hierarchy of your file system.
```unix
cd
```
Using the cd command alone will change the current directory to your user home directory, located in "/home/username" as in "/home/mark".
ls (List) - This command list the content in the current directory. It can be also used to list file information.
```unix
ls
```
Now we can see our directories in our home.

View File

@@ -0,0 +1,98 @@
---
title: Linux Booting Process
---
# Linux Booting Process - 6 Step Descriptive Process
Operating system is defined as the low-level software that supports a computers basic functions,such as scheduling tasks and controlling peripherals. OS holds down these 6 high level stages of a typical Linux boot process.
![Steps](https://raw.githubusercontent.com/Ayushverma8/tech-interview-handbook/master/LinuxBootingProcess.jpg)
### 1. BIOS
- BIOS stands for Basic Input/Output System
- Performs some system integrity checks over the HDD
- Searches, loads, and executes the boot loader program , mostly in the Master Boot Record (MBR)
- It looks for boot loader in floppy, cd-rom, or hard drive. We can press a key (typically F12 of F2, but it depends on your system) during the BIOS startup to change the boot sequence.
- Once the boot loader program is detected and loaded into the memory, BIOS gives the control to it.
- So, in simple terms BIOS loads and executes the MBR boot loader
### 2. MBR
- MBR stands for Master Boot Record.
- It is located in the 1st sector of the bootable disk. Typically /dev/hda, or /dev/sda. Why its sda and hda ? refer here for more.
- MBR is less than 512 bytes in size. This has three components 1) primary boot loader info in 1st 446 bytes 2) partition table info in next 64 bytes 3) mbr validation check in last 2 bytes.
- It contains information about GRUB (or LILO in old systems).
- So, in simple terms MBR loads and executes the GRUB boot loader.
### 3. GRUB
- It is located in the 1st sector of the bootable disk. Typically /dev/hda, or /dev/sda. Why its sda and hda ? refer here for more.
- If you have multiple kernel images installed on your system, you can choose which one to be executed, by default only the major one boots up .
- GRUB displays a splash screen, waits for few seconds, if you dont enter anything, it loads the default kernel image as specified in the grub configuration file.
- GRUB has the knowledge of the filesystem (the older Linux loader LILO didnt understand filesystem).
- Grub configuration file is /boot/grub/grub.conf (/etc/grub.conf is a link to this). The following is sample grub.conf of CentOS.
```
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/boot/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.18-194.el5PAE)
root (hd0,0)
kernel /boot/vmlinuz-2.6.18-194.el5PAE ro root=LABEL=/
initrd /boot/initrd-2.6.18-194.el5PAE.img
```
### 4. Kernel
- Mounts the root file system as specified in the “root=” in grub.conf
- Kernel executes the /sbin/init program
- It is the 1st program to be executed by Linux Kernel, it has the process id (PID) of 1. Do a ps -ef | grep init and check the pid. You can also use netstat
- initrd stands for Initial RAM Disk.
- initrd is used by kernel as temporary root file system until kernel is booted and the real root file system is mounted. It also contains necessary drivers compiled inside, which helps it to access the hard drive partitions, and other hardware.
### 5. Init
- Looks at the /etc/inittab file to decide the Linux run level.
- Following are the available run levels
- 0halt
- 1Single user mode
- 2Multiuser, without NFS
- 3Full multiuser mode
- 4unused
- 5X11
- 6reboot
- Init identifies the default initlevel from /etc/inittab and uses that to load all appropriate program.
- Execute grep initdefault /etc/inittab on your system to identify the default run level
- If you want to get into trouble, you can set the default run level to 0 or 6. Since you know what 0 and 6 means, probably you might not do that.
- Typically you would set the default run level to either 3 or 5.
### 6. Runlevel programs
- When the Linux system is booting up, you might see various services getting started. For example, it might say “starting sendmail …. OK”. Those are the runlevel programs, executed from the run level directory as defined by your run level.
- Depending on your default init level setting, the system will execute the programs from one of the following directories.
- Run level 0/etc/rc.d/rc0.d/
- Run level 1/etc/rc.d/rc1.d/
- Run level 2/etc/rc.d/rc2.d/
- Run level 3/etc/rc.d/rc3.d/
- Run level 4/etc/rc.d/rc4.d/
- Run level 5/etc/rc.d/rc5.d/
- Run level 6/etc/rc.d/rc6.d/
- Under the /etc/rc.d/rc*.d/ directories, you would see programs that start with S and K.
- Programs starts with S are used during startup. S for startup.
- Programs starts with K are used during shutdown. K for kill.
- There are numbers right next to S and K in the program names. Those are the sequence number in which the programs should be started or killed.

View File

@@ -0,0 +1,38 @@
---
title: How to download files using the "wget" utility in Linux
---
## How to download files using the "wget" utility in Linux
This article is a quick tutorial on using the ``wget`` utility on Unix based OS.
GNU Wget is a free utility for non-interactive download of files from the Web. It supports HTTP, HTTPS, and FTP protocols, as well as retrieval through HTTP proxies.
### Installing `wget`
The wget utility is freely available package and licensed under the GNU GPL License. This utility can be installed on any Unix-like OS including Windows and MacOS.
### Basic syntax
The basic syntax of the ``wget`` is...
```
wget [option]... [URL]...
```
### Details of wget
```
wget --version
```
```
wget --help
```
### Downloading a single file
```
wget http://ftp.gnu.org/gnu/wget/wget-1.5.3.tar.gz
```
### Downloading from FTP
```
wget ftp://ftp.gnu.org/gnu/wget/wget-1.10.1.tar.gz.sig
```
### Restrict download speed limits
```
wget --limit-rate=100k http://ftp.gnu.org/gnu/wget/wget-1.5.3.tar.gz
```
You can play with remaining features of the ``wget`` utility

View File

@@ -0,0 +1,13 @@
---
title: How to extract or decompress a compressed file in Linux
---
Before extracting the data from a compressed file, you must first determine the compressed file type.<br>
## How to extract or decompress a compressed file in Linux
Step 1: To Know the file type<br>
`file File-Name`
Step 2: To Decompress a tar file<br>
`tar xvf File-Name -C /Directory-Location`
`We Use (-C) for specific directory if we do not use (-C) then it automatically extract to current directory.`

View File

@@ -0,0 +1,62 @@
---
title: How to install phpmyadmin on Linux (Ubuntu).
---
# How to install phpmyadmin on Linux (Ubuntu)
The [MySQL](https://en.wikipedia.org/wiki/MySQL) database server can be administered using the command-line, by running commands in the terminal. But it is more convenient and less tedious to use a graphical user interface (GUI) most especially for those who are not comfortable with entering commands on a terminal.
[phpMyAdmin](https://en.wikipedia.org/wiki/PhpMyAdmin) is a free and open source GUI software tool written in PHP, intended to handle the administration of MySQL over the Web. phpMyAdmin supports a wide range of operations on MySQL and and its community-supported version - [MariaDB](https://en.wikipedia.org/wiki/MariaDB).
Frequently used database operations (managing databases, tables, columns, relations, indexes, users, permissions, etc) can be performed via the GUI, while you still have the ability to directly execute any SQL statement. And also perform exporting and importation of data in popular file formats (CSV, SQL, XML, PDF, Word, Excel, LaTeX and many others). You can install phpMyAdmin Linux, windows and Mac OS (it is cross-platform). It has become one of the most popular MySQL administration tool.
In this post, you will see how to install it on a Linux operating system. But before we begin ensure that you have Apache, MySQL and PHP install on your system. If not learn how to do it [here](https://fossnaija.com/install-lamp-server-linux-ubuntu/).
### Installing phpMyAdmin.
* Open the Linux terminal and use the Ubuntu software package manager `apt` to install,
<br>
sudo apt-get install phpmyadmin
<br>
* Then the installation begins. When prompted, select <em>“Apache2”</em> from the <strong>“Configuring phpMyAdmin”</strong> dialogue box.When asked for MySQL username and password enter “root” for username and choose an appropriate password for password.
<br>
* After installation is complete, configure phpMyAdmin to be recognised by the local web server. Open the apache configuration file in your favourite text editor;
```
sudo gedit /etc/apache2/apache2.conf
```
and add the following line at the bottom of the file (you can add it anywhere in the file, I just choose the bottom here so that you can easily access it for modification if need be):
`Include /etc/phpmyadmin/apache.conf`
<br>
* Then restart the web server;
```
sudo service apache2 restart
```
* Now enter the following url in your browser;
`https://localhost/phpmyadmin`
You should see a login page for you to enter your username and password, if youve not done so.
<strong>Username</strong> = <em>root</em>
<strong>Password</strong> = <em>YOUR_MYSQL_PASSWORD</em>
If successful the phpMyAdmin dashboard appears. Then you can start using phpMyAdmin.
### More Information:
* For a graphical installation steps check [here](https://fossnaija.com/install-phpmyadmin-linux-ubuntu/).
* [PhpMyAdmin Installation documentation](https://docs.phpmyadmin.net/en/latest/setup.html).

View File

@@ -0,0 +1,45 @@
---
title: How to Use SFTP to Securely Transfer Files with a Remote Server
---
## How to Use SFTP to Securely Transfer Files with a Remote Server
This article is a quick tutorial on how to use Secure File Transfer Protocol (SFTP) to exchange files with a server. This is useful for programming, as it allows you to code and test locally, and then send your work to the server when you are done.
### Testing SSH
If you haven't already, test that you are able to SSH into the server. SFTP uses the Secure Shell (SSH) protocol, so if you are unable to SSH you probably won't be able to SFTP either.
```unix
ssh your_username@hostname_or_ip_address
```
### Start SFTP Session
This uses the same syntax as SSH and opens a session in which you can transfer files.
```unix
sftp your_username@hostname_or_ip_address
```
To list helpful commands:
```unix
help
```
### Transfer files and folders
To download a file:
```unix
get <filename>
```
To download a folder and its contents, use the "-r" flag (also works for uploading):
```unix
get -r <foldername>
```
To upload a file:
```unix
put <filename>
```
### Change folders
To change the local folder:
```unix
lcd <path/to/folder>
```
To change the remote folder:
```unix
cd <path/to/folder>
```

View File

@@ -0,0 +1,49 @@
---
title: Linux
---
<img src="https://upload.wikimedia.org/wikipedia/commons/3/35/Tux.svg">
Linux is a name which broadly denotes a family of free and open-source software operating system distributions built around the Linux
kernel. The defining component of a Linux distribution is the Linux kernel, an operating system kernel first released on September 17,
1991 by Linus Torvalds. Many Linux distributions use the word "Linux" in their name. The Free Software Foundation uses the name
GNU/Linux to refer to the operating system family, as well as specific distributions, to emphasize that most Linux distributions are not
just the Linux kernel, and that they have in common not only the kernel, but also numerous utilities and libraries, a large proportion
of which are from the GNU project.
### GNU
The GNU operating system is a complete free software system, upward-compatible with Unix. GNU stands for “GNU's Not Unix”.
The project to develop the GNU system is called the “GNU Project”. The GNU Project was conceived in 1983 as a way of bringing back the cooperative spirit that prevailed in the computing community in earlier days—to make cooperation possible once again by removing the obstacles to cooperation imposed by the owners of proprietary software. *The GNU operating system and the Linux kernel are separate software projects that do complementary jobs. Typically they are packaged in a GNU/Linux distribution, and used together*. More at [Overview of GNU system](https://www.gnu.org/gnu/gnu-linux-faq.en.html#why)
The development of Linux is one of the most prominent examples of free and open-source software collaboration. The underlying source
code may be used, modified and distributed commercially or non-commercially by anyone under the terms of its respective licenses, such
as the GNU General Public License.
Linux was first started as a clone of the MINIX operating system. Open source contributors added onto the kernel and expanded its
hardware compatability. Linux's hardware supoort and free licensing made Linux a popular choice for desktop and server computing in the
mid 90s. Today, Linux is the most popular operating system in the world. It powers 90% of the world's servers, and is the basis of
Google's popular Android operating system.
There are also many versions of Linux designed to be run on personal computers, such as Debian or Ubuntu. More importantly, these
different versions of Linux (called distributions) allow the user varying degrees of personalization and control of the operating
system. This means that users can choose their Linux distributions based on their wants and needs.
There is also Kali Linux which is used for advanced penetration testing and auditing. It has over 700 tools, to be able to use it
efficiently you will need to know how to use command line. It is not advised for beginners.
Popular distributions of Linux include:
* Ubuntu
* Linux Mint
* CentOS
* RHEL
* Arch Linux
Package types are split between higher-level distributions, with Debian (.deb) and Red Hat (.rpm) being two of the most commonly used,
however there are others including Pacman (used for Arch Linux) and PetGet (Puppy Linux).
Linux distributions also come in all shapes and size and most if not all offer the ability to run directly via CD / DVD in what's known
as a 'Live CD' environment or even directly via USB if your motherboard supports booting from USB.
For more facts about Linux, read Quincy Larson's article [Linux is 25. Yay! Lets celebrate with 25 stunning facts about Linux](https://medium.freecodecamp.org/linux-is-25-yay-lets-celebrate-with-25-rad-facts-about-linux-c8d8ac30076d).

View File

@@ -0,0 +1,28 @@
---
title: Install and Configure Apache Server in Linux
---
Apache HTTP Server, colloquially called Apache, is free and open-source
cross-platform web server software.
Apache is developed and maintained by an
open community of developers under the auspices of the Apache Software Foundation.</div>
## Install and Configure Apache Server in Linux
Step 1: Install Apache Server<br>
`yum install httpd`
Step 2: Configuring http web sever <br>
`cd /etc/httpd/conf.d`
Step 3: Create a custom configration file with .conf extension.<br>
`vim *.conf`
Step 4: Starting Apache Server<br>
`systemctl start httpd.service`
Step 5: Automatically Start Apache Server when Operating System start.<br>
`systemctl enable httpd.service`
Step 6: Add firewall permission.<br>
`firewall-cmd --add-service=http --permanent`

View File

@@ -0,0 +1,42 @@
---
title: Install and configure FTP server in Redhat/Centos Linux
---
## Install and configure FTP server in Redhat/Centos Linux
FTP stands for File Transfer Protocol. It was written by Abhay Bhushan and published as RFC 114 on 16 April 1971.
It is supported by all operating system and browsers. It is built on a client-server architecture.
## Install and configure FTP server in Redhat/Centos Linux
Step 1: We will use localhost for our machine to setup ftp server.<br>
Step 2: Install vsftpd (very secure FTP daemon) package.<br>
`yum install -y vsftpd`<br>
Step 3: Start FTP Server when system on.<br>
`systemctl enable vsftpd.service`<br>
Step 4:</b> Checking the status of ftp server<br>
`systemctl status vsftpd.service`<br>
Step 5: Configure vsftpd package. We will edit<br>
`/etc/vsftpd/vsftpd.conf`
`Change the line which contain anonymous_enable=NO to anonymous_enable=YES`<br>
`This will give permit any one to access FTP server with authentication.`<br>
`Change the following to YES`<br>
`local_enable=YES`<br>
`write_enable=YES<br>`<br>
Step 6: Start FTP Server<br>
`systemctl start vsftpd.service`
Step 7: Install FTP Client<br>
`yum install -y lftpd`<br>
Step 8: Connect ftp to localhost<br>
`lftp localhost`

View File

@@ -0,0 +1,62 @@
---
title: Installing CLI Tools Developers Should not Live Without on Linux and Mac
---
This article is a short description on how to install key command line utilities that developers use everyday on Macintosh and Linux environments. The main CLI tools that will be shown are: Homebrew (Mac), Node and NPM, Bower, Gulp, Grunt and Tmux.
## Installing Homebrew (Macintosh Systems)
Homebrew is 'The missing package manager for OS X'. It is a great tool for downloading and installing packages straight from your command line. This is not needed on Linux distributions because they already have package managers installed by default such as `apt-get` or `pacman`. To install Homebrew, simply paste the following command in your terminal:
* `/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"`
In case you run into "Xcode Command Line Tools Missing" use the following to install it:
* `xcode-select --install`
## Installing NPM
`NPM`, or Node Package Manager, is another useful package manager for downloading mostly web tools. Downloading `NPM` will also install the Node.js framework.
### Mac:
* Using `Homebrew` type: `brew install node` and `NPM` should have been installed.
### Linux:
* Using `apt-get` first type: `curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -`, then `sudo apt-get install nodejs`
* Using `pacman` type: `pacman -S nodejs npm`
* Using `yum` type: `sudo yum install nodejs npm`
* Using `dnf` type: `sudo dnf install nodejs`
* Using `zypper` type: `sudo zypper install nodejs6`
## Installing Bower
Bower is a popular package manager that allows you to install front-end libraries. You can install it on Linux and Macintosh systems using `npm` with the following command:
* `npm install -g bower` (Same command for both Linux and OS X)
## Installing Gulp
`Gulp` is a framework and CLI tool that makes development faster and more enjoyable by automating tasks developers find themselves doing over, and over again. Also, you can install `Gulp` through `npm`:
* `npm install -g gulp-cli`
And in individual project folders:
* `npm install --save-dev gulp`
## Installing Grunt
`Grunt` is another popular automation tool similar to `Gulp`. To install it, use `npm` again:
* `npm install -g grunt-cli`
## Installing Tmux
`Tmux` is a terminal multiplexer for Linux and Mac. It gives you the ability to have multiple sessions and windows in the same Bash window, and also lets you "detach" sessions that you can connect to through SSH, leaving all programs that were currently running, running.
To install on Linux:
* `sudo apt install tmux`
And that's that! With these tools your development process and content will be enjoyable and efficient. As you can see, the main tool to install is `npm` and it allows you to install many other great web oriented CLI tools.

View File

@@ -0,0 +1,24 @@
---
title: The Linux, Apache, MySQL, and PHP Stack
---
## The LAMP Stack
One of the most common configurations for a Linux server is the LAMP stack, named after the most frequently used components (Linux, Apache, MySQL, and PHP). The standard LAMP stack is open source, freely available, and thoroughly documented, providing a flexible, standardized, and secure platform for website and web application development.
### Linux
The operating system component of the LAMP stack is usually a distribution of Linux, and many popular Linux distributions such as Ubuntu and Red Hat have semi-automated methods for installed and configuring the other components. When Mac OSX is substituted for Linux, the resulting stack is sometimes referred as the MAMP stack. Similarly, when the stack is built in a Windows environment, it is sometimes referred to as a WAMP stack.
### Apache
The web server component of the stack is usually Apache, the most popular web server on the internet. As of June 2014, Apache was estimated to serve 52.27% of all active websites. In recent years, many sysadmins and web developers have opted to replace Apache with nginx, a web server that can be more lightweight and faster in some situations. The resulting stack is sometimes referred to as the LEMP stack.
### MySQL
The relational database management system (RDBMS) layer of the LAMP stack is MySQL. It is sometimes replaced by MariaDB, a performant fork of MySQL, or even unrelated databases such as PostgreSQL or NoSQL databases such as MongoDB.
### PHP
The server programming language or middleware layer of the LAMP stack is usually PHP, though it has frequently been substituted with (or used alongside) Python, Perl, or other languages.

View File

@@ -0,0 +1,23 @@
---
title: Linux Brief History
---
## Linux in Brief
GNU/Linux (commonly referred to as just Linux) is a free, open-source, customizable operating system based on the Linux kernel and GNU utilities and libraries. It is developed by thousands of developers and used by millions of people, companies, and governments around the world. It is an alternative solution to other OS's such as Windows and Mac OSX and has many different distributions or "flavors." Some of the most popular distributions are Ubuntu, Red Hat Enterprise Linux (RHEL), Debian, Fedora, CentOS, OpenSuSE, Arch, Mint, and Solus. It includes software found in other OS's for common tasks such as running office applications, multimedia, graphics, and gaming. It also provides powerful tools for programming and web development. Linux is built to run on desktops, servers, Internet Of Things devices and mobile devices (Android).
##Who invented Linux?
Linux is germinated as an idea in the mind of young and bright <b>Linus Torvalds</b> when he was a computer science student. He used to work on the UNIX OS (proprietary software) and thought that it needed improvements.
However, when his suggestions were rejected by the designers of UNIX, he thought of launching an OS which will be receptive to changes, modifications suggested by its users.
So Linus devised a Kernel named Linux in 1991. Though he would need programs like File Manager, Document Editors, Audio -Video programs to run on it.
As time passed by, he collaborated with other programmers in places like MIT and applications for Linux started to appear. So around 1991, a working Linux operating system with some applications was officially launched, and this was the start of one of the most loved and open-source OS options available today.
The earlier versions of Linux were not so user-friendly as they were in use by computer programmers and Linus Torvalds never had it in mind to commercialize his product.
This definitely curbed the Linux's popularity as other commercially oriented Operating System Windows got famous. Nonetheless, the open-source aspect of the Linux operating system made it more robust.
#### More Information:
[Linux on Wikipedia](https://en.wikipedia.org/wiki/Linux)
[Kernel.org - the Linux kernel official website](https://www.kernel.org/)
[Distrowatch - the reference for Linux distributions](http://distrowatch.com)

View File

@@ -0,0 +1,65 @@
---
title: local-lamp-server-on-ubuntu
---
## Local LAMP Server on Ubuntu
The purpose of this brief guide is to take you through the process of setting up a LAMP (Linux, Apache, MySQL, PHP) server on a local Ubuntu Linux machine or virtual machine. This will allow a developer to develop using PHP and MySQL (with phpMyAdmin). This is a common stack that is necessary for Wordpress development.
### Install the necessary packages
You will need to install the following packages for the LAMP server. You can install them all at once by separating each package by a space, or one at a time like shown. I prefer to download one at a time because it is easier to see if there were any errors. Enter the terminal and type the following:
* `sudo apt-get install apache2`
* `sudo apt-get install php`
* `sudo apt-get install php-mysql`
* `sudo apt-get install mysql-server`
You should then be prompted to set a password for the MySQL root user. After setting the password continue to install:
* `sudo apt-get install libapache2-mod-php`
* `sudo apt-get install php-mcrypt`
* `sudo apt-get install phpmyadmin`
You should then be prompted which server to use select apache by pressing enter.
Select no for advanced server setup.
### Change permissions to the /var/www/html
In order for php scripts and files to be run by the LAMP server they need to be saved in the /var/www/html directory. You can think of this location as your local server. In order to make changes to this directory we need to change the permissions on it. In the terminal enter the command:
* `sudo chown {your ubuntu username} /var/www/html`
### Create a symbolic link to phpMyAdmin
By default, phpMyAdmin is installed in the /usr/share/ directory. We need to move it to our local server directory. We navigate to the server directory that we want the link in by:
* `cd /var/www/html`
Then create the link by entering the command:
* `ln -s /usr/share/phpmyadmin phpmyadmin`
### Restart Apache and test
Run the following command to restart Apache setting the changes that were made:
* `sudo systemctl restart apache2`
You should then be able to create an info.php file in the /var/www/html directory.
* `touch /var/www/html/info.php`
In the file type the following php code:
* `<?php
phpinfo();
?>`
Then, open a browser and type in localhost/info.php
You should see a page from the php file you just wrote that gives you information about php.
Finally, to access phpMyAdmin go to localhost/phpmyadmin in your browser. The defualt root username is 'root' and the password is the password you chose earlier for the MySQL database.
### More Information
<!-- Insert helpful links here -->

View File

@@ -0,0 +1,132 @@
---
title: Partitions
---
## PARTITIONS
- Without creating partitions in hard-disk, we cant create folder.
- Partitions in Linux-
- **df**
- **df -h** (human readable)
- Shows size in MiB, GiB
- **lvdisplay**
- Shows information about partition of disk -
- **fdisk -l**
- **fdisk -l /dev/sda** (sda is the name of hard-disk)
- For practicing partition, insert virtual hard-disk in Linux using virtual-box.
- Some points to remember
- Hard-disk doesnt understand GB or MB, its unit is sector.</br>
1 sector = 512 bytes.</br>
To find actual size of hard-disk, find number of sectors * 512.</br>
Allocates space in hard-disk in sectors.
- Only 4 partitions can be created in a single hard-disk.
</br>
## MAKING PARTITIONS IN HARD-DISK
1. Opens hard-disk prompt.
- **fdisk /dev/sdb**
2. Print partitions information of hard-disk.
- **p**
3. Create a new partition.
- **n**
4. Choose primary partition.
5. Press 1 (1st partition)
6. Initial some sectors (0-2047 = 2048 sectors = 1 MB) are reserved in hard-disk.
7. Actual space starts with 2048th sector.
8. **+1G**
9. Create 4 partitions like this.
10. After 4th partition you cant create more partitions.
11. Press **w** for save.
12. Press **q** for quit without saving any partition.
This will Remove all partitions made because that was temporary.
13. For deleting partition -
- **d**
</br>
## WHY THERE IS LIMIT OF 4 ?
- Because where we store the information of partitions, metadata of partitions, is fixed and of 64 bytes. This information is stored in partition table.
- 1 partition required 16 bytes so only 4 partitions can be created.
- In 1 MB (2048 sectors) reserved in hard-disk, 64 bytes are reserved for storing this information.
- To see partition table-
- **fdisk -l**
- When we first time use hard-disk, it is initialized or formatted. That format decides number of partitions in hard-disk.
- OS creates a format of hard-disk when it was first initialized and that format decides number of partitions.
- Format of partition that we use is DOS format = 64 bytes
- GPT format = 128 partitions can be created.
- Partition table --> format : DOS --> 4 partitions
- Partition table --> format : GPT --> 128 partitions
</br>
## INCREASING NUMBER OF PARTITIONS
- Create a new partition table in hard-disk.
- P4 partition will be created in such a way that its a separate hard-disk.
- This partition is extended partition in which we can create more partitions.
- Logical partition takes space in extended partition. Information or the partition table will be stored in extended partition.
- Create 3 primary and last 1 extended partition.
- Total 64 partitions can be made now. 3 primary + 60 logical + 1 extended.
- But 63 partitions can be used for data storage (remove 1 extended partition).
- There is no difference between primary and logical partition except that no one controls primary but logical is controlled by extended. So if we remove extended partition then all logical partitions will be removed.
- To see partitions information -
- **lsblk** (list of block devices)
- Hard-disk is also known as block devices
- Extended partition cant be used for data storage only logical and primary can be used.
- If partition has to be used for storage then follow these 3 steps -
1. Create physical partition.
2. Format it.
3. Activate/mount.
</br>
## FORMAT PARTITION
- Partition must create an index for every new file for faster processing.
- Whenever a file is to be opened, find that file in index.
- This index is formed in partition when its formatted first time. Its also called file system.
- This index table is known as inode (index node) table.  So, every partition has to be formatted.
- OS reads only inode table to show sizes of folders, files, drives etc.
- This inode table can be changed, then OS will show different sizes then the actual size.
- When we remove a file, it only removes inode entry of that file.
- For example, remove a file of size 1GB and 100 GB, time will be same.
- When we format a partition, it only removes index page, data will not be removed. So, we can recover data from that partition.
- File system creates inode table to manage files.
- To format partition -
- **mkfs.ext4 /dev/sdb1**
- Example - NTFS, ext2, ext3, ext4, xfs etc.
</br>
## Mounting or Activating
- Only two kinds of thing can be used in a OS - File and folder
- We cannot go directly in a device. So, the created device has to be converted in a folder Or link with a folder Or mount with a folder in order to use this.
- **mkdir /data**
- **mount /dev/sdb1 /data** (This data is like a pen drive mount and unmount)
- **cd /data**
- **cat > adarsh.txt**
- **umount /dev/sdb1**
- **cd /data/**
- **ls**
- Mount again
- To know about which partition is mounted on which folder.
- **df -h**
- Shows inode table.
- **ls -l**
- Shows inode number.
- ls -il

View File

@@ -0,0 +1,12 @@
---
title: Origins of Linux and the Free Software Movement
---
In the 1980s a famous MIT hacker working for the Artificial Intelligence lab named <a href='https://en.wikipedia.org/wiki/Richard_Stallman' target='_blank' rel='nofollow'>Richard Stallman</a> promoted the sharing of knowledge and ideas freely, specifically within the area of software. <a href='https://en.wikipedia.org/wiki/Unix' target='_blank' rel='nofollow'>UNIX</a> was the <a href='https://en.wikipedia.org/wiki/Operating_system' target='_blank' rel='nofollow'>operating system</a> (OS) of choice by many in the engineering and scientific community, but the problem was UNIX was <a href='https://en.wikipedia.org/wiki/Proprietary_software' target='_blank' rel='nofollow'>proprietary software</a>. This meant only the vendors of the OS had access to the <a href='https://en.wikipedia.org/wiki/Source_code' target='_blank' rel='nofollow'>source code</a>. That went against Stallman's philosophy. Not only did this mean the end users were not allowed to see how the software worked, they could not make any improvements or fixes to it if they could.
Stallman started the <a href='https://en.wikipedia.org/wiki/Free_Software_Foundation' target='_blank' rel='nofollow'>Free Software Foundation</a> (FSF) which supported the <a href='https://en.wikipedia.org/wiki/Free_software_movement' target='_blank' rel='nofollow'>free software movement</a>'s ideals (Individuals who use and collaboratively contribute to open and free software). It was also responsible for starting the <a href='https://en.wikipedia.org/wiki/GNU_Project' target='_blank' rel='nofollow'>GNU Project</a> in 1984 which was the first attempt at a free OS that was not UNIX (GNU is a <a href='https://en.wikipedia.org/wiki/Recursive_acronym' target='_blank' rel='nofollow'>recursive acronym</a> for 'GNUs not UNIX'). The GNU Project would include everything useful found on a UNIX system but written from scratch. More importantly, along with the OS the source code would also be legally available to those who wanted it. The idea was that freely exchanging the source code and inner knowledge of the OS would encourage collaborative development, which in turn would create a better OS product. The GNU Project eventually led to the <a href='https://en.wikipedia.org/wiki/GNU_General_Public_License' target='_blank' rel='nofollow'>GNU Public License</a> (GPL) which legalized all software released under it to be made freely available as well as require providing the source code. While the GPL was a success and still used today to license free software, the GNU Project never took off as planned. Another hacker stepped in and provided his implementation of a free Operating System to the world instead.
<a href='https://en.wikipedia.org/wiki/Linus_Torvalds' target='_blank' rel='nofollow'>Linus Torvalds</a>, a Finnish student from the University of Helsinki, first created <a href='https://en.wikipedia.org/wiki/Linux' target='_blank' rel='nofollow'>Linux</a> kernel while experimenting with a free and smaller version of UNIX used for educational purposes called <a href='https://en.wikipedia.org/wiki/MINIX' target='_blank' rel='nofollow'>MINIX</a> which was developed by <a href='https://en.wikipedia.org/wiki/Andrew_S._Tanenbaum' target='_blank' rel='nofollow'>Andrew Tanebatum</a>. Linus wanted to have a similar free OS that didn't have the constraints of being limited to pure educational use. He created Linux which he licensed under the GPL and distributed on the Internet in 1991 (The current source code and work on the Linux Kernel can be found on GitHub <a href='https://github.com/torvalds/linux' target='_blank' rel='nofollow'>here</a>. Linus didn't use any code from MINIX, but he incorporated the features found in MINIX/UNIX which is why Linux is often called <a href='https://en.wikipedia.org/wiki/Unix-like' target='_blank' rel='nofollow'>"UNIX-like"</a> or a "UNIX clone".
Despite the fact that GNU Project never created fully-fledged free OS it did create a lot of system software for interacting with the kernel that is vital for a well functioning OS. Thus the combination of Linux kernel and GNU core system programs made the fully free OS possible.
Over time Linux began to gather strong traction within the free software movement. Thousands of developers around the world started experimenting and using it, making contributions where they saw fit. As it became more stable and feature-rich, businesses slowly started to adopt Linux as a solution for their needs and even started contributing to Linux themselves. Linux reaches many devices and environments to this day and continues to grow in popularity.

View File

@@ -0,0 +1,45 @@
---
title: Setting Up Yum Repositories in RedHat/CentOS Linux
---
YUM Repositories are warehouses of Linux software (RPM package files).
RPM package file is a Red Hat Package Manager file and enables quick and easy software installation on Red Hat/CentOS Linux.
## Setting Up Yum Repositories in RedHat CentOS Linux
Step 1: Check if there are existing repositories or not.
```sh
#yum repolist
```
You will find there is no repositories.
Step 2: Change Directory to
```sh
#cd /etc/yum.repos.d
```
Step 3: Create new file
```sh
#vim myrepo.repo
```
Step 4: Type following lines in file
```sh
[file-name]
name=filename
baseurl="location of yum repositories"
gpgcheck=0
```
Step 5: Save and Exit
Step 6: Repeat Step 1
```sh
You Will find repositories
```

View File

@@ -0,0 +1,39 @@
---
title: Shell scripting
---
# Shell scripting
In the command line, a shell script is an executable file that contains a set
of instructions that the shell will execute. It's main purpose its to reduce
a set of instructions (or commands) in just one file. Also it can handle
some logic because it's a programming language.
## How to create it
1) Create the file:
```bash
$ touch myscript.sh
```
2) Add a [shebang](https://en.wikipedia.org/wiki/Shebang_(Unix)) at the start of the file. The Shebang line is responsible for letting the command interpreter know which interpreter the shell script will be run with:
```bash
$ echo "#!/bin/bash" > myscript.sh
# or
$ your-desired-editor myscript.sh
# write at the first line #!/bin/bash
```
3) Add some comands:
```bash
$ echo "echo Hello World!" >> myscript.sh
```
4) Give the file _execution_ mode:
```bash
$ chmod +x myscript.sh
```
5) Execute it!
```bash
$ ./myscript.sh
Hello World!
```
More info about shell-scripting can be found [here](https://www.shellscript.sh/)

View File

@@ -0,0 +1,201 @@
---
title: Automating Tasks
---
### Automating Tasks or Task Scheduling
There is a feature of Linux that is exclusively leveraged in a web server,known as CRON
As we know that one of the most compelling features about any web server is that it's always
powered on and always connected to the internet. This means that we can instruct
our server to perform tasks automatically, without us needing to enter a command
into a shell. One of the most commonly used programs for executing *other programs*
with a regular frequency is called `cron`. Let's take a look at how to use
`cron` to schedule a program to be run.
The `cron` program is part of a family of programs called **daemons**. A daemon
is a program that is always running in the background of our computer. First,
let's see if `cron` is running. We can get a list of all running programs
with the `ps` command while using the `-A` flag:
```{r, engine='bash', eval=FALSE}
ps -A
```
```
## PID TTY TIME CMD
## 1 ? 00:00:13 systemd
## 2 ? 00:00:00 kthreadd
## 3 ? 00:00:03 ksoftirqd/0
## 5 ? 00:00:00 kworker/0:0H
## 7 ? 00:00:11 rcu_sched
## 8 ? 00:00:00 rcu_bh
## 9 ? 00:00:00 migration/0
## ...
```
You probably have a huge list of programs in your terminal now! Instead of
shifting through this listing line-by-line, let's pipe the output of this command
to `grep` and we'll look for `cron`:
```{r, engine='bash', eval=FALSE}
ps -A | grep "cron"
```
```
## 1273 ? 00:00:01 cron
```
# You might or might not get a `cron` running .
Looks like the `cron` daemon is running! In order to assign programs to be
executed with `cron` we need to edit a special text file called the `cron`
table. Before we edit the `cron` table we need to select the default text
editor. If you like using `nano` (the text editor we've been using throughout
this book) then enter `select-editor` into the console, type in the number
that corresponds to `nano` (usually `2`) and then press enter:
```{r, engine='bash', eval=FALSE}
select-editor
```
```
## Select an editor. To change later, run 'select-editor'.
## 1. /bin/ed
## 2. /bin/nano <---- easiest
## 3. /usr/bin/vim.basic
## 4. /usr/bin/vim.tiny
##
## Choose 1-4 [2]:
```
Now that we've chosen a text editor we can edit the `cron` table using the
command `crontab -e` (**`cron`** **tab**le **e**dit) which will automatically
open `nano` with the appropriate file.
```{r, engine='bash', eval=FALSE}
crontab -e
```
```
# Edit this file to introduce tasks to be run by cron.
#
# m h dom mon dow command
```
Let's go over the layout of the `cron` table. First you should notice that any
text after a pound sign (`#`) is a comment, so it's not seen by `cron` (just
like bash comments). The `cron` table has six columns:
1. Minute (`m`)
2. Hour (`h`)
3. Day of Month (`dom`)
4. Month (`mon`)
5. Day of Week (`dow`)
6. Command to be run (`command`)
Each column is separated by a single space in the table. The first five columns
allow you to specify when you want a particular command to be run. Only certain
values are valid in each column:
1. Minute: `00 - 59` (A particular minute in an hour)
2. Hour: `00 - 23` (0 is the midnight hour)
3. Day of Month: `01 - 31` (1 is the first day of the month)
4. Month: `01 - 12` (1 is January)
5. Day of Week `0 - 6` (0 is Sunday)
There are also a few other characters that are valid in the `cron` table. The
most commonly used character is a star (`*`) which represents *all* of the
possible values in a column. So a star in the Minute column means "run every
minute," and a star in the Hour column means "run during every hour."
Knowing this let's make our first entry in the `cron` table. If we want a
command to be executed every minute, during every hour, on every day of the
month, during every month, on every day of the week, then we can put stars in
all of the first five
columns, followed by the command that we want to run. In this case the command
that `cron` will run every minute will be `date >> ~/date-file.txt`, which will
append the date and time when the command is executed to a file in our home
directory called `date-file.txt`. This is what your `cron` table should look
like before you save and exit from `nano`:
```
# Edit this file to introduce tasks to be run by cron.
#
# m h dom mon dow command
* * * * * date >> ~/date-file.txt
```
Save and exit `nano` just like you would for a regular text file and then wait
a little bit! After a minute has gone by use `cat` to look at `~/date-file.txt`:
```{r, engine='bash', eval=FALSE}
cd
cat date-file.txt
```
```
## Thu Jun 8 18:50:01 UTC 2017
```
Look like our entry in the `cron` table is working! Wait another minute and then
look at the file again:
```{r, engine='bash', eval=FALSE}
cat date-file.txt
```
```
## Thu Jun 8 18:50:01 UTC 2017
## Thu Jun 8 18:51:01 UTC 2017
```
Unless we delete the line that we entered in the `cron` table, the output from
`date` will be appended to `date-file.txt` every minute.
The single line of bash `date >> ~/date-file.txt` is a much simpler program than
we would probably use in a `cron` table, though it's good for illustrating how
a `cron` table works. If you want to do more complex tasks with `cron` it's
better for `cron` to execute a bash script that you've written in advance. That
way you can just specify `bash /path/to/script.sh` in the last column of the
table.
Using stars in all columns is the simplest line of a `cron` table, so let's
look at some examples of more complex table entries:
```
# m h dom mon dow command
00 * * * * bash /path/to/script.sh # Runs every hour at the start of the hour
00 12 * * * bash /path/to/script.sh # Runs every day at noon
* 12 * * * bash /path/to/script.sh # Runs every minute between 12pm and 12:59pm
00 00 05 * * bash /path/to/script.sh # Runs the 5th day of every month at midnight
00 00 * 07 * bash /path/to/script.sh # Runs every day in the month of July at midnight
00 00 * * 2 bash /path/to/script.sh # Runs every Tuesday at midnight
```
Besides numbers and the star there are a few other characters that you can use
in `cron` table columns including a hyphen (`-`) for specifying ranges and a
comma (`,`) for specifying lists of items. For example `00-29` in the Minutes
column would specify the first thirty minutes of an hour, while `1,5` in the
Day of Week column would specify Monday and Friday.
Let's take a look at another example of a `cron` table that uses hyphens and
ranges so you can get a sense of how each character works.
```
# m h dom mon dow command
00-04 * * * * bash /path/to/script.sh # Runs every minute for the first five minutes of every hour
00 00 * * 0,6 bash /path/to/script.sh # Runs at midnight every Saturday and Sunday
00 03 01-15 * * bash /path/to/script.sh # Runs at 3am for the first fifteen days of every month
00,30 * * * * bash /path/to/script.sh # Runs at the start and middle of every hour
00 00,12 * * * bash /path/to/script.sh # Runs every day at midnight and noon
00 * 01-07 01,06 * bash /path/to/script.sh # Runs at the start of every hour for the first seven days of the months of January and June
```
A program that is being run by `cron` is only as powerful as your imagination
can stretch! If you're familiar with the social network
[Twitter](https://twitter.com/) then you might have come across some Twitter
accounts which create posts automatically like
[Emoji Aquarium](https://twitter.com/emojiaquarium),
[Old Fruit Pictures](https://twitter.com/pomological), or
[Endless Screaming](https://twitter.com/infinite_scream). Many of these "bot"
accounts are powered by `cron`, which uses Twitter's HTTP API to post tweets
regularly.

View File

@@ -0,0 +1,18 @@
---
title: Some Usages for Linux
---
* Linux now operates on the majority of smartphones and tablets around the world via the <a href='https://en.wikipedia.org/wiki/Android_(operating_system' target='_blank' rel='nofollow'>Android</a>) OS (based off the Linux kernel). As of March 2016 Android holds <a href='https://www.netmarketshare.com/operating-system-market-share.aspx?qprid=8&qpcustomd=1' target='_blank' rel='nofollow'>60.99%</a> of the market share on mobile devices (tablets and smartphones). It also holds <a href='http://www.idc.com/prodserv/smartphone-os-market-share.jsp' target='_blank' rel='nofollow'>82.8%</a> for smartphones alone (per 2015 Q2 numbers).
* As of March 2016, Alexa reported that <a href='http://www.w3cook.com/os/summary/' target='_blank' rel='nofollow'>96.55%</a> of the top 1 million Internet domains in the world are powered by servers running Linux.
* The <a href='https://en.wikipedia.org/wiki/New_York_Stock_Exchange' target='_blank' rel='nofollow'>New York Stock Exchange (NYSE)</a>, the largest stock exchange in the world which trades securities worth billions of dollars daily are executed by servers that run on Linux after moving away from UNIX.
* The White House powers their web servers using <a href='https://en.wikipedia.org/wiki/Red_Hat' target='_blank' rel='nofollow'>Red Hat Linux</a> and <a href='https://en.wikipedia.org/wiki/Apache_HTTP_Server' target='_blank' rel='nofollow'>Apache</a>.
* The US Department of Defense (DoD) uses Linux to run their nuclear submarine fleet.
* You can automate everything in your home with just a Raspberry PI.
* The US Navy uses Linux for ground control software.
* Linux is used to host websites or apps. Linux-based web hosts like 'Dreamhost' are used to host your personal RSS reader with Tiny Tiny RSS, or personal Dropbox clone with OwnCloud.
* Home automation can be made possible with Linux along with a small computer like a Raspberry Pi. It can be used to control home with Siri, mount a Google Calendar tablet on wall, set up a home surveillance system, control blinds and air conditioner, stream music , build a digital photo frame, build a sunrise alarm clock amd many more.
* Pakistan is using Linux in many of its public schools and colleges and plans to ultimately run it on all of its government computer systems
* The Sony Playstation 3 gaming console had previously made it possible to run Linux on a seperate hard drive partion. Scientific entities networked together consoles for powerful clusters. <a href='https://en.wikipedia.org/wiki/PlayStation_3_cluster' target='_blank' rel='nofollow'>The United States Air Force Research Laboratory</a> assembled a super computer by cluster 1760 Playstation 3 Consoles.
* Linux is in space. Ubuntu is used at the International Space Station. <a href='https://news.softpedia.com/news/Ubuntu-Used-on-the-International-Space-Station-to-Control-Rover-Back-on-Earth-454101.shtml' target='_blank' rel='nofollow'> Read more </a>
Other adoptions of Linux from around the world can be viewed <a href='https://en.wikipedia.org/wiki/List_of_Linux_adopters' target='_blank' rel='nofollow'>here</a> and <a href='http://www.comparebusinessproducts.com/fyi/50-places-linux-running-you-might-not-expect' target='_blank' rel='nofollow'>here</a>

View File

@@ -0,0 +1,39 @@
---
title: The Anatomy of the Linux Command Line
---
# The Anatomy of the Linux Command Line
In this highly Graphic-User-Interfaced (GUI) tech world the command, many computer users find the idea of entering text commands (on a command prompt or terminal) to carry out basic functions as repulsive - and should best be left for programmers or developers (in fact geeks).
Fortunately, the command-line interface (CLI) is king in the world of Linux. Though many flavours of linux come with well polished and intuitive GUIs, for an optimum Linux experience, one still needs a familiarity with the Linux CLI (the terminal or shell) to be able to carry out essential computer operations in a fast and clean manner.
The command line still plays very important roles in the life of the Linux user and yours too if you choose to use it.
In Linux, commands are given (typed) in the terminal. Though the terminal application can have varied names across different linux distributions (distros) - but most times it is simply called “terminal” or a closely related term.
To get started using open the terminal (for Ubuntu simply hold the Ctrl + Alt + T) and you're welcomed by a series of characters arranged in this format;
```linux
user_name@machine_name:~$
```
You can see a command line ending with a blinking shell prompt, signifying the shell is ready to receive commands from the user.
* The <strong><em>“user_name”</em></strong> represnts the login name.
* The <strong><em>“machine_name”</em></strong> (also known as the domain name) is the name assigned to the computer(or server) and it is usually set during installation. Sometimes it could also be represented by an IP address.
* The tilde sign <strong><em>“~”</em></strong> shows that the current directory of the user is his "home" ```(/home/user_name)```.
* Note that every user in a Linux system has a HOME directory created for them and this home directory always is the same name with the user's login name (or username). That is if the login name is “john” then his home directory would be /home/john. At login, every user is taken directly to his/her home directory.
From the command terminal you can start giving command to the shell. Multiple commands can be given on a single command line using a semi-colon to separate them. Something like this;
```user_name@machine_name:~$ who; free; df```
But most times to ensure a clean output it is advisable to enter commands one at time so as not to cluster the screen.

View File

@@ -0,0 +1,296 @@
---
title: The Command Prompt
---
## The Command Prompt
As one of the oldest User Interfaces (UI), the *command prompt* (a.k.a. *shell*, *terminal*, *console*, *tty*) has been implemented in many ways.
This has led to a few words being used interchangeably in modern conversation that actually have slightly different meanings.
---
> Table of Contents
<!-- TOC depthFrom:3 -->
- [A Very, Very Short History](#a-very-very-short-history)
- [Today](#today)
- [The Shell](#the-shell)
- [BASH](#bash)
- [Getting Help](#getting-help)
- [The Prompt](#the-prompt)
- [Getting Root](#getting-root)
- [login](#login)
- [sudo](#sudo)
- [su](#su)
- [Relative and Absolute Paths](#relative-and-absolute-paths)
- [Relative](#relative)
- [Absolute](#absolute)
- [Command Options](#command-options)
- [Chaining Commands](#chaining-commands)
- [Background Jobs](#background-jobs)
<!-- /TOC -->
---
### A Very, Very Short History
In the 19th century was the <a href='https://en.wikipedia.org/wiki/Electrical_telegraph' target='_blank' rel='nofollow'>telegraph</a>. This allowed two people to exchange encoded messages over long distances. Later technological advancements led to the <a href='https://en.wikipedia.org/wiki/Teleprinter' target='_blank' rel='nofollow'>teletype machine</a> (tty), where the person required to receive the message was replaced by a kind of printer.
At the same time, early computers like ENIAC, were programmed with some kind of hardware, like switches, dials, or patch cables. As the computers advanced, better Input/Output (IO) was needed, and so the commonly available teletype machines were converted for use.
Because the tty's were large pieces of furniture on their own, and earned the name **console** for their similarities to other floor-standing furniture such as console televisions. As an electronic end-point for a mainframe, these devices were also called **terminals**.
TTY printers were eventually replaced by Cathode Ray Tube (CRT) screens, which were also used in televisions before LCD and plasma was available. Interestingly, modern Linux computers can still be controlled using a tty machine!
> Click the image below to go to a short Youtube video.
<a href='https://youtu.be/-Ul-f3hPJQM' target='_blank' rel='nofollow'><img src='https://i.ytimg.com/vi/-Ul-f3hPJQM/hqdefault.jpg'></a>
---
### Today
Today, Linux and Unix users still use the same terms, but with slight differences. Real and virtual terminals are available, and virtual terminals can be accessed using <kbd>Alt + Ctrl + [F1-F12]</kbd>.
In Graphical User Environments (GUI), users can access the command prompt using a **terminal emulator**, which provides the features of a tty, but within a window. There are many terminal emulators available to Linux users, such as **xterm**, **kterm**, and **rxvt**.
The ones available will depend on which Linux distribution (distro, for short) you are using, and its defaults. Check your package manager to install others. Windows users can use **PuTTY** or other utilities to connect to a Linux system.
### The Shell
*Shell*s are programs that interpret commands.
There are a number of them, such as <a href='https://www.gnu.org/software/bash/' target='_blank' rel='nofollow'>**B**ourne **A**gain **SH**ell</a> (BASH), <a href='https://docs.freebsd.org/44doc/usd/04.csh/paper.html' target='_blank' rel='nofollow'>C Shell</a> (csh/tcsh), and <a href='http://zsh.sourceforge.net/' target='_blank' rel='nofollow'>Z SHell</a> (zsh).
#### BASH
The most common default shell in Linux is BASH, but each user can switch temporarily or permanently to any other available shell. The shell is fully scriptable, meaning that programming concepts can be combined with shell and system utilities in order to create more complicated functions.
Commands entered at a command prompt may be built in to the shell, such as **cd**, **exit**, or **export**.
They can also come from external programs, and in the case of most Linux distributions, is provided by the <a href='https://www.gnu.org/software/coreutils/coreutils.html' target='_blank' rel='nofollow'>Gnu tools</a>.
See below for the most common commands.
| Command | Usage |
| -------- | ----------------------------------------- |
| `cd` | change current directory |
| `ls` | list files in current directory |
| `mv` | move files and directories |
| `man` | open command documentation |
| `mkdir` | make a directory |
| `rmdir` | delete a director |
| `touch` | create an empty file |
| `rm` | remove files |
| `ln` | create links to files and directories |
| `chown` | change ownership of files and directories |
| `chmod` | change permissions |
| `find` | locate files |
| `cat` | writes files to standard output |
| `less` | allows scrolling of standard input |
| `grep` | search for matches in plain text |
| `diff` | show differences between files |
| `passwd` | change your password |
#### Getting Help
Immediate help is available for commands in one or more places.
Add `--help` after the command.
This prints usage information for the command.
Its output is similar to the `man` command, but `man` is used before the command that you want the manual for.
The `info` command is the third help option, and is used just like `man`.
```bash
ls --help
man ls
info ls
```
### The Prompt
The prompt, which is the bit of text in the shell to the left of the cursor, can change to show your current status, such as which directory you are currently in, which user you are logged in as, your computer's name, and *what privileges you have*.
That last one is important to recognize. Usually the last character in the prompt, you will see a `$`, which indicates normal user privileges.
If you have **root** privileges, which belong to the system administrator, you will usually see a `#` as the last character. When browsing forums and getting help online, the commands that you must type will often be shown with this character.
**You don't have to type it!**
For example:
```bash
$ ls -l
```
means you type `ls -l` at a normal prompt.
```bash
# apt-get install node
```
means that you type `apt-get install node` using administrator privileges. How you elevate your privileges depends on your Linux distribution.
### Getting Root
#### login
Logging in as root is a *very bad idea*. This is why some versions of Linux disable users' ability to log this way. Those users are encouraged to use the next method, `sudo` from within their own user account.
If you do have to use a root console, be aware of its power. You will not be warned, or asked to confirm for most tasks, even if a simple typo means deleting something important.
#### sudo
Add "sudo" before a command in order to switch to **S**uper **U**ser and **DO** (SUDO). This is how Ubuntu and its derivatives are configured to allow administrator access, and is given on a per-command basis.
You are not given a root shell, and the next command you type will not have elevated privileges, unless you use `sudo` again.
```bash
sudo apt-get update
```
Except for the first created user on certain distros, users have to be added to a special list (found in `/etc/sudoers`) in order to use sudo.
This is done with the `visudo` command.
You should never edit the `sudoers` file with a regular text editor!
`visudo` will make sure that you don't lock yourself out of your own system.
#### su
`su`, like `sudo`, allows you to change to another user, except that by default, you will get another prompt as the user you switched to.
On it's own, `su` will switch you to a root prompt, but with the current user's environment variables, such as `$HOME` for your home folder, and `$PATH` for the system path.
This can lead to unexpected results, and if you want to use `su` to switch to another user, add a hyphen after the command:
```bash
su -
```
This will switch you fully to a root prompt.
A username can be added to the command to switch to that user, but will require that user's password.
`sudo` can be used in combination with `su` to allow an administrator to switch to any user.
```bash
myUser@linux $ su - otherUsername
Password: (typed my password)
su: Authentication failure
myUser@linux $ sudo su - otherUsername
Password: (typed my password)
otherUsername@Linux $
```
### Relative and Absolute Paths
When using a command on a file, such as copying or deleting, you can refer to the file in one of two ways.
#### Relative
File location in relation to the current directory.
There are two relative path operators in the shell, `.` and `..`.
The first, `.` means the current directory, so `cat file.txt` and `cat ./file.txt` are the same thing if file.txt is in the current directory.
The other is `..`, and means one directory up in the tree.
So if you are in `/home/user/projects/project-a` and issue the command `cd ..` you will change to `/home/user/projects`.
If the projects directory has sub-directories named `project-a`, `project-b`, `project-c`, and you were in the `project-a` directory, you could switch to `project-b` using `cd ../project-b`.
There is also an `environment variable` in the shell called `$HOME` which points to your home directory.
You can use this in BASH using a tilde character `~`.
The shell replaces the tilde for you when you hit enter, so as an example, you can change to your own home folder using `cd ~`.
#### Absolute
File locations are the full path from the root of the filesystem, and always have a leading slash.
For example, `cd /home/quincy/Desktop` will go to Quincy's desktop directory, regardless of current path or logged in user.
### Command Options
Most shell commands follow the same syntax, which is **command options files**.
```bash
ls -l *.txt
```
where
- `ls` gives a list of files and directories,
- `-l` changes the output of `ls` to a long listing,
- and `*.txt` restricts the list to files ending with `.txt`.
Each command has different options, and multiple options can be listed together, as in the tar example `tar -cvf` in the next section.
Individual commands can be connected together in a chain, where the output of one command becomes the input to another command.
This is done with the `|` character, often called **pipe** or **bar**. This is not a capital <kbd>i</kbd> or lowercase <kbd>L</kbd>, nor is it the number <kbd>1</kbd>. On US keyboards, it's found on one of the keys near <kbd>Enter</kbd>.
In the following example, I will use 2 commands.
The first, `cat`, is short for concatenate, and can be use to put the contents of one file at the end of another (concatenation!). When using it with one file only, it writes the contents to the terminal.
The second command, `grep` is a program that outputs text found based on some input, and a search pattern. The search pattern can be simple text, or a Regular Expression (regex) for more advanced searches.
```bash
cat index.html | grep img
```
There are many ways to do this, but this will output every line in index.html that contains `img` to the terminal. This example only uses one `|`, but you are not limited to that.
### Chaining Commands
While the single ampersand operator `&` is a job control operator in BASH (next section), the double ampersand has another meaning. It is logical **AND**, and you use it between two commands so that the second command only runs if the first exits successfully (without error).
The following example is how many Debian & Ubuntu users update their list of software, and then run a system upgrade.
```bash
sudo apt-get update && sudo apt-get dist-upgrade
```
Another option is the double-pipe `||`, which means logical **OR**. You would use it when you want to run a command only when the first exits with an error.
The following will create an archive called `project.tar` on the user's desktop from the files in a project directory, and if that fails, echo a message.
```bash
tar -cvf /home/user/Desktop/project.tar /home/user/project/* || echo "archive failed"
```
### Background Jobs
When you run a command in a terminal, the terminal is busy until the command is finished, and no other commands can be run. There is a job control system in Linux that allows you to suspend running commands, resume suspended commands in the background, and resume suspended commands in the foreground.
This is useful for long-running scripts, or when you need to push something in to the background so that the terminal can be used for other things.
o suspend a program that is running in the terminal use the key combination <kbd>Ctrl + Z</kbd>.
You will get back to your normal prompt, and the command appears to have quit. It hasn't, but has only been suspended. It's still visible in the jobs list by using `jobs` command to list all currently tracked jobs. I did `man ls` to get a manual page, and then suspended it.
When I type `jobs` I get the following output:
```bash
$ jobs
[1] + suspended man ls
```
From here, I can let it resume in the background by typing `bg %1` where the `1` is the job number found in the square brackets.
I can bring it back to the foreground by typing `fg %1`.

View File

@@ -0,0 +1,80 @@
---
title: User management on Linux
---
#### Note: To run a command as `sudo` you must have sudo user account (Administrator)
## How to Create a User
#### Use the `adduser` or `useradd` command to add a new user to your system.
```
$ sudo adduser username
```
Be sure to replace `username` with the user that you want to create.
#### Use the `passwd` command to update the new user's password.
```
$ sudo passwd username
```
A strong password is highly recommended!
## How to Create a Sudo User
To create a `sudo` user, you need to create a regular user first using the command above, then add this user to the group of `sudoers` using the `usermod` command.
##### On Debian systems (Ubuntu/LinuxMint/ElementryOS), members of the `sudo` group have sudo privileges.
```
$ sudo usermod -aG sudo username
```
##### On RHEL based syatems (Fedora/CentOs), members of the `wheel` group have sudo privilages.
```
$ sudo usermod -aG wheel username
```
## How to Delete a User
##### For Debian (Ubuntu)
```
$ sudo deluser username
```
##### For RHEL (Fedora/CentOS)
```
$ sudo userdel username
```
##### Creating groups and adding users
```
$ sudo groupadd editorial
$ sudo usermod -a -G editorial username
```
#### Note: All above commands can be executed without sudo in `root` mode
To switch to root on ubuntu, run `su -i` command followed by the password of the user logged in. Prompt changes to `#` insted of `$`
##### On Debian systems (Ubuntu/LinuxMint/ElementryOS), members of the `sudo` group have sudo privileges.
```
$ sudo usermod -aG sudo username
```
## How to Create a Group
To create a group, use the command `groupadd`
```
$ sudo groupadd groupname
```
## How to delete group
To delete a group, use the command 'groupdel'
```
$ sudo groupdel grouname
``
#### References
<a href='https://www.digitalocean.com/community/tutorials/how-to-add-and-delete-users-on-ubuntu-16-04' target='_blank' rel='nofollow'>Debian(Ubuntu)</a>
<a href='https://www.digitalocean.com/community/tutorials/how-to-add-and-delete-users-on-a-centos-7-server' target='_blank' rel='nofollow'>RHEL (CentOS/Fedora)</a>

View File

@@ -0,0 +1,29 @@
---
title: Using the Find Command
---
# Using the Find Command
The Linux find command is a powerful tool to help you locate files and directories on your server. With a little practice, you can easily track things down based on name, type, size, or date (when they were created or last updated).
Think of find as your eager helper:
You: "I'm looking for something on my server."
Find: "I can help! What can you tell me about it?"
You: "It was a file, bigger than 2GB, somewhere under my home directory, updated in the last 48 hours."
Find: "Tada!"
Find is a program, so really you'd have to tell it `find ~ -type f -size +2G`.
Here are some sample commands using find:
* `find ~ -type d # Show me all the subdirectories inside my home directory`
* `find / -type f -name 'todo.txt' # Show me files named 'todo.txt' anywhere under the root directory (i.e. anywhere)`
The first parameter always names the directory in which we'll look. In our examples above, these are ~ (home directory of the current user) and / (root directory of the filesystem).
Other parameters are optional and can be combined in any ways you find useful:
* The type parameter allows you constrain the search for files only (f), directories only (d) or symbolic links (l). If you omit the type parameter, you'll be searching for all of these types.
* The name parameter lets you specify what you want to find by name, either with a literal string ('filename.txt') or using wildcards ('file?.*').
`man find` will show you many more parameters, and is worth reviewing. Find can locate files by name, user, creation date, size and much more. Next time you're looking for something, find it!

View File

@@ -0,0 +1,100 @@
---
title: Writing a Bash Script
---
# Writing a Bash Script
By typing commands on the Linux command line, you can give the server instructions to get some simple tasks done. A shell
script is a way to put together a series of instructions to make this easier. Shell scripts become even more powerful when
you add logic like `if` and `while` to automatically control how they behave as circumstances change.
## Whats Bash?
Bash is the name of a command line interpreter, a program that makes sense of the Linux commands you enter at the command
prompt, or in your script.
## Whats in a Script?
A script is just a file. A basic script is made up of an introductory line that tells the server what to make of it, and one
or more instructions to execute. Heres an example:
```
#!/bin/bash
echo "Hi. Im your new favorite bash script."
```
The first line has special meaning, which we'll discuss below. The second line is just a Linux command, one you could type
out on the command line.
## Whats a Comment?
Comments are text you add to your script that you intend bash to ignore. Comments start with a pound sign, and are useful for
annotating your code so you and other users can understand it. To add a comment, type the `#` character, followed by any text
that's helpful you. Bash will ignore the `#` and everything after it.
**Note:** the first line of the script is not a comment. This line is always first, always starts with `#!` and has special
meaning to bash.
Heres the script from before, commented:
```
#!/bin/bash # Designates the path to the bash program. Must start with '#!' (but isn't a comment).
echo "Hi. Im your new favorite bash script." # 'echo' is a program that sends a string to the screen.
```
## Executing a Script
You can open a text editor, paste that example code and save the file, and youve got a script. Scripts are conventionally
named ending in '.sh,' so you might save that code as myscript.sh.
The script wont execute until we do 2 things:
**First, make it executable.** (Well only have to do this once.)
Linux relies extensively on file permissions. They determine a lot about how your server behaves. There's a lot to know about
permissions, but for now we only need to know this: you can't run your script until you give yourself execute permissions. To
do that, type:
`chmod +x my script.sh`
**Second, run it.** We execute the script from the command line just like any other command like `ls` or `date`. The script
name is the command, and you need to precede it with a './' when you call it:
`./myscript.sh # Outputs "Hi. I'm your new favorite bash script." (This part is a comment!)`
## Conditionals
Sometimes you want your script to do something only if something else is true. For example, print a message only if a value is
below a certain limit. Here's an example of using `if` to do that:
```
#!/bin/bash
count=1 # Create a variable named count and set it to 1
if [[ $count -lt 11 ]]; then # This is an if block (or conditional). Test to see if $count is 10 or less. If it is, execute the instructions inside the block.
echo "$count is 10 or less" # This will print, because count = 1.
fi # Every if ends with fi
```
Similarly, we can arrange the script so it executes an instruction only while something is true. We'll change the code so that
the value of the count variable changes:
```
#!/bin/bash
count=1 # Create a variable named count and set it to 1
while [[ $count -lt 11 ]]; do # This is an if block (or conditional). Test to see if $count is 10 or less. If it is, execute the instructions inside the block.
echo "$count is 10 or less" # This will print as long as count <= 10.
count=$((count+1)) # Increment count
done # Every while ends with done
```
The output of this version of myscript.sh will look like this:
```
"1 is 10 or less"
"2 is 10 or less"
"3 is 10 or less"
"4 is 10 or less"
"5 is 10 or less"
"6 is 10 or less"
"7 is 10 or less"
"8 is 10 or less"
"9 is 10 or less"
"10 is 10 or less"
```
## Real World Scripts
These examples aren't terribly useful, but the principles are. Using `while`, `if`, and any command you might otherwise type
manually, you can create scripts that do valuable work.