Shell Scripting? Interview Questions
What is shell scripting?
Shell Script is series of command written in plain text file. Shell script is just like batch file in MS-DOS but have more power than the MS-DOS batch file.
It means shell accept command from you (via keyboard) and execute them. But if you use command one by one (sequence of ‘n’ number of commands), then you can store this sequence of command to text file and tell the shell to execute this text file instead of entering the commands.
Why Shell Scripting?
Shell scripts can take input from a user or file and output them to the screen.
Whenever you find yourself doing the same task over and over again you should use shell scripting i.e. repetitive task automation
* Creating your own power tools/utilities.
* Automating command input or entry.
* Customizing administrative task.
* Creating simple applications.
Since scripts are well tested, the chances of errors are reduced while configuring services or system administration task such as adding new users.
Practical examples where shell scripting actively use
System Administration / Database Administration/ Testing/ Automation /Data centers (SAN) etc.
* Monitoring your Linux system.
* Data backup and creating snapshots.
* Creating email based alert system.
* Find out what processes are eating up your system resources.
* Find out available and free memory.
* Find out all logged in users and what they are doing.
* User administration as per your own security policies.
* Find out the name of the MP3 file you are listening to.
* Monitor your domain expiry date every day.
What is Shell?
SHELL is a command line Interpreter, Interface between User and Kernel.
#? Admin prompt
What is a command used to monitor the tasks running?
What is the command to know the current shell?
# echo $SHELL
$ echo $SHELL
What are the commands to see the content of zipped files?
#/$zcat File.gz— to see the contents of File.gz
#/$cat sample—to see the contents of file sample
Command to know the type of files?
#/$file * ->Displays all files and its types
#/$file filename -> Displays specified file name