DAY 1
CONTINUATION OF LEARNING BASIC LINUX COMMAND
NOTE:
<strong>/</strong> is known as root directory
<strong>~/</strong> is known as home directory
lets create a directory name 'cohort_3' in the ~/ directory

lets create another directory in our cohort_3/ name 'web2'

Okay lets quickly sharpen our knowledge a little with what we've learn.
TASK 1
1. Create a directory name 'tasks' in the web2/

2. Create the following text files in the tasks/ directory
a. notes
b. ideas
c. todos

3. Append a text to each of the listed files above.
e.g welcome to my note file

to view each of the files to be sure the text where appended

4. Lets copy all the files in tasks/ to web2/

NOTE: <strong>cp</strong> means <em>copy</em>, then followed by the name of the file(s), then the destination of the directory. In this case, the directory web2/ is one step backward hence the use of <strong>../</strong>
To confirm the files where copied successfully, lets list(ls) all the files and folders in web2/

NOTE: the command <strong>ls ../</strong> will take you one step backward to where the web2/ folder is.
5. Rename the files in the web2/ folder and append <strong>_backup</strong>

NOTE: <strong>mv</strong> stands for move (which is use to rename a file and can also be use to move files or directory from one directory to another) then followed by the name of the file, then the new name.
e.g <strong>mv ideas.txt idea_backup</strong>
6. Lets copy contents of notes and ideas into todos.
First, lets check the contents of todos
using the command <strong>cat todos.txt</strong>

Now its done using the command <strong>cat ideas.txt notes.txt >> todos.txt </strong>

Alright, now we've learn some new things. Lets go further to do more greater things with the terminal.
TASK 1
1. Create a <strong>trial/</strong> in the <strong>~/ </strong>
This is simply saying we should create a directory name <strong>trial/</strong> in the <strong>home</strong> directory.

2. Lets copy the entire <strong>tasks/</strong> into <strong>trial/</strong>

NOTE: <strong>r</strong> means <strong>recursive</strong>
3. Lets copy the entire <strong>web2/</strong> into <strong>trial/</strong> with <strong>trial/</strong> as our <strong>pwd (present working directory)</strong>

NOTE: The <strong>period (.)</strong> means the present working directory, which is saying the folder is been copied to the present working directory.
4. Lets <strong>cd (change directory)</strong> into <strong>tasks/</strong> and create a folder in <strong>~/</strong> name <strong>test/</strong>

5. Lets move the text files in <strong>web2/</strong> into the newly created directory <strong>test/</strong> with <strong>tasks/</strong> as our <strong>pwd (print working directory)</strong>
This can be achieved by two(2) methods
Method 1 is by moving the text files one after the other.

Method 2 is by the use of a <strong>wildcards (*)</strong> followed by the unique name or file format they all contain. In this case, <strong>_backup</strong> is the same format the files contain.

6. Lets create a hidden folder name <strong>hidden</strong>

NOTE: The folder <strong>.hidden</strong> was created but its not listed among the directories that are contained in the <strong>~/</strong> directory, why? because <strong>.hidden</strong> is a hidden directory which was created using the <strong>period (.)</strong>.
How to view or list hidden file or directory using the command <strong>ls -a</strong>

How to delete or remove hidden file or directory using the command <strong>rm -rf 'name of directory'</strong> where <strong>rm</strong> means remove, while <strong>rf</strong> means recursive force.

NOTE: All the files or directories with the <strong>period(.)</strong> sign are regarded as hidden files or directories.
DAY 2
GREP COMMAND
Is a command that is use to search for matching patterns in a file. Grep stands for "Global Regular Expression Print". Regular expressions are sequence of character pattern.

NOTE: In the picture above, we're trying to find the matching pattern of 'to' in the todos.txt file.
Grep is also case sensitive but to ignore that, we use <strong>-i</strong>.

CHMOD COMMAND (change mode)
Is a command that allows you change the permissions of a file or directory to all types.
SYNTAX: chmod <Operations> <File/Directory Name>
These operations are categorised into;
<strong>USER LEVEL PERMISSIONS</strong>
It control permissions on the user level. Here's the commands you can use:
u – Grant permission to a user
g – Grant permission to a group (A Group of users)
o – Grant permission to others (who do not come under either of the above).
<strong>FILE LEVEL PERMISSIONS</strong>
It control permissions on the file level.
r – Grants read permission
w – Grant write permission
x – Grant execute permission
These operations need to be preceded with a '+' or '-' operator.
'+' indicates adding a new permission, example <strong>chmod +r sample.txt</strong>
'-' indicates removing an existing permission, example <strong>chmod -r sample.txt</strong>
Now lets change some permisions on our txt file.

THE USE OF RECURSIVE FLAG <strong>(-R)</strong> TO ADD OR REVOKE PERMISSIONS FOR A PARENT DIRECTORY DOWN TO THE LAST CHILD OF THE DIRECTORY
Linux manages a very granular level of file permissions.
If you want to apply the permissions to the parent directory and all its child directories, you need to pass an exclusive flag with the chmod command.
That flag is <strong>-R</strong>. It basically means applying the same permissions recursively to all sub-directories (child directories). So this permission will apply to the end child of a file/directory.
Here's the syntax for that:
<strong>sudo chmod -R <permission> <filename></strong>
Remember that running the command to do a recursive operation needs root permission. So you need to add sudo at the beginning of this command. Here's what it looks like:
<strong>sudo chmod -R -r locked_directory</strong>
OCTAL REPRESENTATION
Octal representation is another way to control file permissions.
Let's see the syntax for using octal mode:
<strong>chmod <user><group><others> install.sh</strong>
Here's an example of octal mode:
<strong>chmod 777 install.sh</strong>
NOTE: The syntax above is granting read, write and execute permisions to <strong><user><group><others></strong>
where;
read, r = 4
write, w = 2
execute, x = 1
TOTAL = 7
DAY 3
SHELL SCRIPTING
Shell is a program that allows you to interact with the OS via command line.
Shell scripting on the other hand is a file containing a sequence of commands that are executed by the shell program line by line.
The terminal is a shell.
TYPES OF SHELL
1. Bash shell (Bourn-Again): The default prompt is represented by a dollar sign <strong>$</strong>
2. C - shell: The default prompt is represented by a percentage sign <strong>%</strong>
SOME KEY TERMINOLOGIES USED IN WRITING A SHELL FILE INCLUDE
<strong>i</strong> (insert): allows you to insert the commands
<strong>Esc</strong> (escape key): on the keyboard allows you to exit the insert mode.
<strong>w</strong> (write): this mode allows a user to save all the changs made in the file.
<strong>q</strong> (exit): to exit the text editor
<strong>vim</strong>: text editor
Lets create a shell file by name <strong>practise.sh</strong> and store some commands to do the following;
1. create a directory name demo/
2. create a shell file name sample.sh in the demo/
3. echo Hello world into the sample.sh
4. cd to demo/
5. then ls
SOLUTION
creating a shell file name practise.sh

open with vim using the command <strong>vim practise.sh</strong>
It will then open the vim editor as seen below.

Lets press i to activate the insert mode which allows the user to type in the editor.

lets press Esc to exit the insert mode

To save our changes, we use <strong>:w</strong> and press enter as seen in the down left-corner of the picture below

After is has been saved, it will print some captions below as seen in the picture.

To quit the vim editor, type <strong>:q</strong> and press enter.

After exiting, it will navigate us back to the terminal to execute the file.

To execute the file, lets use the command <strong>./practise.sh</strong> but this will throw an error requiring a user permission to execute the file.

If we <strong>ls -l practise.sh</strong>, you'd see that the user has no executable permissions to execute the file.

To grant the user executable permission, lets use the command <strong>chmod u+x practise.sh</strong>

Now we can execute our file using the command <strong>./practise.sh</strong>

If we ls to home/, we should see our demo/ followed by the shell file we created in the demo/ then the Hello world! we echo into the file.

CONCLUSION
This week has been an awesome and mind blowing week. From learning basic linux commands to writing shell scripting files, isn't that pretty awesome? Indeed i'm learning a lot. Looking forward to what will be achieved neext week.
Stay with me in my journey to becoming the best version of myself. Cheers!