" The Unix Programming Environment " By Brain W. Kernighan and Rob Pike. This is one of those kind of books I never liked even to look at during my engineering days. That being said I can’t believe I almost completed 4 chapters of it. Unix, Shell scripting, all these are "alien" to me, we would love to know all about them, but they are scary. All credits goes to The Lyceaum mentoring course by Noufal Sir. He introduced the book to us and asked us to read the first 5 chapters. I was like, " It’s impossible. I am not gonna do this.". But after his introductory class I was really eager to conquer this book. After this I really understand the concept of programming- the concept we study in our olden days, that
"Program tells the computer (or machine) what to do.".

Before this course I didn't have any basics on UNIX programming. For this course I installed Linux Ubuntu in my system. That was our first step. I am not gonna explain everything I studied but would love to point out some points that struck chord with me.

Some basic commands in UNIX :

date: Shows the date

ls: Lists the files and directories in the current directory

cat: Prints the content of the specified file

echo: Print's the argument to the terminal.

touch: Creates a file.

rm: Removes the file.

mkdir: Makes a directory.

mv: Move or rename a file.

What is a Shell

We all studied 'Kernel' is the core of a computer or any OS we installed in our computer. Shell is what stands between the OS Kernel and us. When we type a command on the prompt " $ " with corresponding arguments and options; the shell takes it to the kernel and brings back the output for you.
Input-output redirection: We can use a pipe to take the output of a command to input of another command thus forming a chain of commands can do a lot of things.
Personalizing the environment: We can actually personalize a UNIX system. We can even change the conventional ways we use a system and even change the prompt symbol. There is a file named '.profile' in the login directory. Whenever we login to the system, the system will run that script before anything else.

Everything in UNIX system is a file

A file is sequence of bytes. No structure is imposed on a file by the system, and no meaning is attached to its contents; the meaning of the bytes depends on the programs that interpret the file. OK, that's all in the book. What I understood is that, in UNIX file system, a file named 'sample' and 'sample.txt' are the same. If we rename a file named 'sample.txt' as 'sample', UNIX is not going to ask you for the extensions. Whatever we do with the name nothing changes in the way UNIX interprets the file. If we want to know what type of file is that there is a command named file. Here is an example:

$ file filename

'Everything in UNIX is a file '-what I mean by that is every command we use is also a file. A file which is executable.

You can man man

As the book said 'Once you receive the prompt, you can type Commands.'
Normally a command looks like this:

command   optional-arguments   optional-filename

There are so many commands in the UNIX. We probably can't remember all the commands. We have a commands for that too. The command man. 'man' means manual. This command shows the manual page of the command we gave in the argument part. Manul page of command 'ls' looks like this.

So by default we can man man

All these are some of the basics I learned. There are so many commands more, but I here explain one command that I got to take a presentation on last week. That is the 'comm'. All we need to do is man that command

$ man comm

comm:compare two sorted files line by line

syntax :

$comm [OPTION]... FILE1 FILE2

When no options is given comm produces three-column output where first column contains lines  unique to FILE1 ,second column contains lines unique to FILE2 and third  and last column contains lines common to both the files. Here its important that the files must be sorted. The manual page describes everything.

Here is an example,

Here Chandigarh and Delhi are common in both files.It is listed on third column. Also we can try the command with all the options seen in the manual.

For example

$ comm -1 cities states

This suppresses the first column.

Next we can get only the common lines like this:

$ comm -12 cities states

Thank you for reading my blog...