Linux Shell Scripting What and Why?

Microsoft Windows 1.0 Six-Page Advertising Ins...
Image by myoldpostcards via Flickr

If you have known any power users of Linux or some of the developers, you would have probably heard them talk about shell scripting or shell scripts. You might even have wondered what these Linux shell scripts are, and why they are used. There is also a myth about the difficulty of using Linux shell scripts among many Linux newbies. However, the reality is, it takes just a clear understanding of Linux shell and knowledge of scripting to be able to successfully utilize the immense power of Linux shell scripts.

A Linux shell is software that allows the users of Linux to issue English-like instructions to your computer. These instructions are known as Linux commands and are passed to the Linux kernel via the Linux shell. In other words, Linux shell provides users an environment for interacting with the operating system without using a graphical user interface (GUI). There are various kinds of Linux shells available, such as BASH (Bourne-Again SHell), CSH (C SHell), KSH (Korn Shell), and TCSH. You can write shell scripts as per the Linux shell of your choice.

A shell script is a set of commands written in a way that they can be executed sequentially without any manual intervention. These scripts are stored in textual files with a .sh extension. Generally, shells are used for manually entering the commands as inputs, whereas with the use of shell scripts you can define the exact sequence of commands, manipulate their parameters and switches, and expect a composite output as a result of running the script.

With shell scripts, you can store output to files, send as e-mails, or show them on screen without typing commands on the Linux shell each time. Repetition of defined sets of tasks becomes much easier than otherwise with the shell scripts. You can utilize shell scripts to automate scheduled tasks or even facilitate system or network administration. Many MS-DOS users think of shell scripts as Linux equivalents of MS-DOS based batch files, but shell scripts are much more powerful than the batch files in MS-DOS operating system.

Enhanced by Zemanta

Know About the Running Processes with the PS Command

Graph of typical Operating System placement on...
Image via Wikipedia

The Linux operating system has many important concepts that help developers and administrators ensure a smooth functioning of the applications developed for Linux. One of such important concepts of operating systems is concept of processes. A process in Linux represents an instance of a running program. The Linux operating system assigns a unique identifier, process id, to each running process. In order to know the details related to the processes running under Linux, you can use the ps command.

The ps command has the following basic syntax:
ps [options]

When you run the ps command on the command prompt, it displays the information about at least two processes, shell and ps. Shell is the process that runs in order to provide users an environment to interact with the operating system. The ps process is displayed as a result of executing the ps command, which terminates immediately after running the ps command.

The ps command displays four pieces of information related to the running processes by default. These pieces of information are PID, TTY, TIME and CMD. PID is the process id of the process, TTY indicates the name of logged in terminal (console), TIME is an indicative of the processing time the CPU has spent executing the process, and CMD is the name of command result in the process execution.
There are various common usages of ps command with varying values of the options used while running the ps command. For example, in order to get a list of processes containing the word, app, you can issue the ps command with the grep command as follows:
ps -ef| grep app
Similarly, the ps command can issue the list of processes based on various criteria specified by various options, such as aux, -u, -ef, -x, etc. These options can be used for various purposes, such as killing a non-responsive process. You can easily find the process id of a particular process and issue the kill command with the process id thus found.