“Every Mountain top is within reach if you keep climbing.”
Good Evening all!! It’s been a long time I wrote a blog. I don’t know what exactly the reason is, whether I didn’t have any interesting topic to talk about or I was just too lazy:-}
Can’t say but I guess second reason would be more appropriate: -p
Ever imagined a day your PC’s mouse stopped working and only keyboard is working and you are supposed to do some urgent tasks related to finding some files and editing them. What would you do in that situation??I have an idea that can come handy in such situations, and that is having knowledge of how to operate command line.
Recently I was given a task of learning about the Unix shell through a website named Software Carpentry (https://software-carpentry.org/) by my sir(). This was a time oriented task as the unit Unix shell was further distributed into 7 different lessons each given with a teaching time.
So beginning with the introduction of Unix shell, it went on with how to navigate files and directories, following with how to create, copy and delete files. On further it taught how to work with loops and locate files. It ended with how to find files, how to merge files and how to overwrite some files.
As it was a time based task I began with the introduction which had 5 minutes of teaching time and I took around 9 minutes. In this it taught me about basics that what is a shell, how the command line looks like. It taught me the principle of command line i.e. REPL(read evaluate print loop) which means firstly the computer reads it, then executes it, and later on prints its output.
Then I moved to the next lesson. It was about how to move from one directory to another, how to move from one file to another. It also taught me some basic commands we frequently use in command line like ls, cd, pwd and so on. It further on taught me how different alphabets have a role in the commands like for eg. –a means ignore entries/files starting with ‘.’, -r means reverse order while sorting, and so on. It also taught me how using ‘..’ we can move up one directory, how directory name are separated using ‘/’. It’s teaching time was about 30 min and it took me around 50 min.
On further moving I moved to next lesson that was about how to copy files from one directory to another directory using cp command, how to make new directory using mkdir command, how to use mv(move), rm(remove) commands. It’s teaching time was around 25 min and I took 32 min.
The next lesson was named as pipes and filters. It’s teaching time was 30 min and it took me around 29 min to read through this lesson. In this it talked about the 2 wildcards i.e. ‘*’ and ‘?’. The first is useful in matching zero or more characters whereas second is useful in matching a specific character. On further reading it taught how we can overwrite/direct the output of a file to another file using ‘>’ character. It also taught about what actually happens behind the scenes when we create a pipe. When a program is executed — any program — it holds the program’s software and its current state in memory. Every process has an input called standard input. Every process also has a output channel called standard output. A second output channel called standard error also exists. This channel is used for error or diagnostic messages, and it allows a user to pipe the output of one program into another while still receiving error messages in the terminal. Other commands that can be handy were head, tail, sort, and so. Head is used to display first few lines whereas tail is used to display last few lines of input and sort as name suggests is used to sort it’s inputs.
The third last lesson was loops. This lesson took the least time to complete. The teaching time was 40 min and I took around 19 min. Loops are the key to productive automation. It’s because of loops we are able to execute commands time and again without any error. While using loops ‘$’ sign changes to ‘>’ as it knows more commands are to be entered and when done is entered it again changes to ‘$’. Along with how to use for loops it also taught shortcut to move at the beginning of a line or the end of a line. By using ctrl-a we can move at start of a line and ctrl-e at end of line. Alongside this Ctrl-R and history command can be used to search through previously used commands.
Shell Script is a file in which commands we repeat frequently use are saved so that we can re-run all those operations again later by typing a single command. These are actually small programs. We can write a comment using ‘#’ tag to provide details to user about the program. Also sort of known as pretty typing. To run commands saved in a file we can use bash filename and this would do our task. The teaching time of this lesson was around 30 min and I took around 18 min.
The last lesson was named as Finding Things. The teaching time was around 25 min and I took around 21 minutes to complete this unit. In this unit I learnt about the keyword ‘grep’ it’s somewhat similar to ‘Google’. As we use google to find certain things in much similar way we use ‘grep’ to locate lines in files. Grep stands for global/regular expression/print. Syntax for using it is first type grep then the keyword we are looking for and at last the file name, like for eg. grep hello file.txt will look for word hello in file.txt.
At last I would like to conclude by saying the Unix shell is a lot older and it has survived because it is one of the most productive programming environments ever created. Working on command line not only makes the job easier and simpler but also gives the person an intense feeling of a huge programmer/coder.