Following are different Unix Scripting Interview Questions with Answers
Following are different Unix Scripting Interview Questions with Answers
Answers:
1. What do you know about UNIX operating system? (100% asked Unix Scripting Interview
Questions)
Answer:
nix operating system is one of the most used and secure operating system which is using in
development and deployment of lot of applications.Because of the Security of the UNIX operating
system this is used in 90 percent of applications as a server operating system.Unix is Multi-user and
Multitasking operating system which is used mainly as server in most of the applications.
“Unix is simple, stable, multi-user, multitasking operating system which is used for Servers,
Desktops and laptops...”
2. What is mean by Shell in Unix Operating System? (100% asked Unix Scripting Interview
Questions)
Answer:
Shell is an interface between the user and the kernel. Even though there can be only one kernel; a
system can have many shell running simultaneously. So, whenever a user enters a command
through the keyboard, the shell communicates with the kernel to execute it and then display the
output to the user.
3. Which are Different Shells in UNIX? (100% asked Unix Scripting Interview Questions)
Answer:
There are following different Shells in unix operating system:
Example:
$Whoami
Output: Amit
5. Which command is useful to show present working directory?
Answer:
PWD:
PWD is most commonly used command which is used to show the present working directory of the
user.
Example:
$PWD
Output: \home\Amit
6. What is the difference between soft and hard links?
Answer:
Soft links are link to the file name and can reside on different filesytem as well; however hard links
are link to the inode of the file and have to be on the same filesytem as that of the file. Deleting the
original file makes the soft link inactive (broken link) but does not affect the hard link (Hard link will
still access a copy of the file).
Cal:
Cal command displays the current month calendar.
Cal 2000:
Displays year 2000 calendar.
Cal 01 2000:
8. How to switch from one user account to other user account in Unix?
Answer:
The SU (Super user command) is used to switch from one user account to another user account.
Example :
$SU Rohit
the above command switches account named “Amit” to account named “Rohit”.
9. What UNIX operating system command would you use to display the shell’s environment
variables?
Answer:
Running the “env” command will display the shell environment variables.
Details:
Sample env command output:
$ env
HISTFILE=/home/lfl/.history
PATH=/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin
SHELL=/bin/ksh
HOSTNAME=livefirelabs.com
USER=lfl
MAIL=/var/spool/mail/lfl
HOME=/home/lfl
HISTSIZE=1000
It would also be good to understand the purpose of the common shell environment variables that
are listed in the env command output.
11. What are different ways to create a file in UNIX? (100% asked Unix Scripting Interview
Questions)
Answer:
There are following ways to create file in Unix:
Details:
This chmod command makes the shell script file “example1” executable for the user (owner) only:
$ Chmod u+x example1
this syntax makes it executable for all (everyone):
$ chmod a+x example1
You can optionally use octal notation to set UNIX permissions using the chmod command (e.g., $
chmod 755 example1). This topic is beyond the scope of this article, but you can find more
information by entering “Unix file permissions chmod numeric notation” in your favorite search
engine.
14. What are the main features of UNIX? (100% asked Unix Scripting Interview Questions)
Answer:
Machine independent
Portability
Multi-user operations
Unix Shells
Hierarchical file system
Pipes and filters
Background processors
Utilities
Development tools.
15. What are the responsibilities of a shell?
Answer:
Program Execution
Input/output redirection
Filename and variable substitution
Pipeline hookup
Environment control
Integrated programming language
16. Explain how to create file using CAT command in UNIX?
Answer:
User can create a new file using ‘Cat’ command in UNIX. Using shell prompt directly user can create
a file.Using ‘Cat’ command user will able to open a specific file also.If user wants to process
the file and append data to the specific file use ‘Cat’ command.
To create new file:
Syntax:
$ Cat >File_Name
Example:
$ Cat >Amit_new.txt
Press: CTRL+D
After Completion of your text you need to press Control + d which is used to save the file and come
out of the prompt.The above statement will create a file named ‘Amit_new.txt’.
$ touch File_Name
To create multiple zero byte files:
$ touch Yodhini.txt
To create multiple zero byte files:
$ touch Yodhini.txt,Amit.txt
The above command will create 2 zero byte files named Yodhini and Amit.
18. How to Delete files in Unix Operating System?( 90% asked Unix Scripting Interview Questions )
Answer:
rm Command is used to delete file in Unix.
Example:
E.g: $ rm –I file_name
$ rm –f :- It deletes a file forcefully
E.g:- $ rm –f File_Name.
19. Can we delete multiple files at a same time in UNIX? How? (80% asked Unix Scripting Interview
Questions)
Answer:
rm command is used to delete multiple files at a same time.
Example:
$ rm file1 file2 ……File_N
E.g: rm Amit_Emptyfile
Syntax:
echo ………lines of file.[\n]…. > nameoffile.txt
This may not seem very useful at first, but using (.) as the name of the current directory will save a
lot of typing.
(..) Means the parent of the current directory, so typing cd .. Will take you one directory up the
hierarchy (back to your home directory).
Example:
The following test command expression would be used to verify the existence of a specified
directory, which is stored in the variable $mydir:
if [ -d $mydir ]
then
command(s)
fi
If the value stored in the variable mydir exists and is a directory file, the command(s) located
between then and fi will be executed.
You can consult the test command’s man page (“$ man test”) to see what test command options are
available for use.
2. “s” bit on a file causes the process to have the privileges of the owner of the file during the
instance of the program.
For example,
Executing “passwd” command to change current password causes the user to writes its new
password to shadow file even though it has “root” as its owner.
27. How will you find the 99th line of a file using only tail and head command? (80% asked Unix
Scripting Interview Questions)
Answer:
Tail +99 file1|head -1
28. What are zombie processes?
Answer:
These are the processes which have died but whose exit status is still not picked by the parent
process. These processes even if not functional still have its process id entry in the process table.
29. How to create directory in Unix Operating Systems? Explain with example.( 100% asked Unix
Scripting Interview Questions )
Answer:
User can create the directory using Mkdir command in unix.
Syntax :
$Mkdir Directory_name
Example:
$Mkdir Amit
Mkdir command is used to create Unix Directory in present working directory.If user wants to create
directory on the specific path then just use following syntax:
Syntax :
$Mkdir path/Directory_name
Example:
$Mkdir usr/bin/Amit
The above statement will create directory in usr/bin folder.Mkdir command produces no output
if successfully created directory.
30. How to create Parent Directory in UNIX?
Answer:
Sometimes user wants to create a directory where the specified directory is not exist.Means user is
trying to create parent directory.
$mkdir /tmp/Pradnya/Unix
Example :
$mkdir -p /tmp/Pradnya/Unix
$
The above statement will create the directory named ‘Pradnya’ in tmp folder and ‘Unix’ in ‘Pradnya’
folder.
31. How to remove directory in Unix?
Answer:
To remove directory user will have use rmdir command which stands for ‘Removing
Directory’.Before removing directory user needs to check that the specified directory is empty or
there is no any file or subdirectory inside that directory.
Syntax:
$rmdir directory_name
Example:
$rmdir Amit
$
The above statement will remove the directory named ‘Amit’.
Syntax:
$cd directory-path
$
Directory path is path of directory which you want to change.
Example:
$cd usr/amit/bin
$
The above statement will go to the bin directory and user will able to work in ‘Bin’ Directory.
33. I want to connect to a remote server and execute some commands, how can I achieve this?(
80% asked Unix Scripting Interview Questions )
Answer:
Example
ssh root@122.52.251.171 -p 22
Once above command is executed, you will be asked to enter the password.
34. If there are 2 files. How to print the records which are common to both?
Answer:
We can use “comm” command as follows:
comm -12 file1 file2 … 12 will suppress the content which are
Syntax :
$mv Old_directory New_directory
Example :
$mv Amit pradnya
The above mv statement is used to rename the directory named ‘Amit’ to ‘Pradnya’.
Owner Permissions:
Owner Permissions are Unix File Permissions given to the specific owner to open,read,write or
execute the file
Group Permissions:
Group permissions are Unix File Permissions to specific group of users to open,read,write and
execute the file.
World Permissions:
These are Unix File Permissions to other user to perform open,read,write, execute file permission.
39. If user wants to give all permissions to file which command is useful?
Answer:
Chmod 477 Permission_File
It gives Read Permission to User, Read/Write/Execute Permissions to Group & Others.
2) chmod700Permission_File
It gives Read/Write/Execute Permission to User and No Permissions to Group & Others
3) chmod777Permission_File
It gives Read/Write/Execute Permission to User, Group & Others
Output :
The Website is named as complexsql Technologies
Output :
Planning for coaching classes with Complexsql
e) $grep Complex*
It searches the Complex string in current directory all files.
43. Which option is used for case insensitive search in Grep Command?
Answer:
The Grep also used to search the string which is used for case insensitive search. We need to use the
option named -i for case insensitive search.
Syntax :
$grep -i Search String Filename
Example :
$grep -i “complexsql” Filename
The above statement is used to fetch the lines which has complex word whether it is capital letters
or in small letters.
Output :
The Website is named as complexsql Technologies
Complexsql
Syntax :
$grep -c Search String Filename
Example :
$grep -c “complexsql” Filename
Output :
3
45. How to print lines with line number in Unix?
Answer:
grep command is used to print the line with line number using -n option of Grep command.
Syntax :
$grep -n Search String Filename
Example :
$grep -n “complexsql” Filename
Output :
The Website is named as complexsql Technologies 2
46. How to search file which contains specific string name?
Answer:
Grep command is also used to search the filename which contains the specific keyword.The option -l
is used to search the filenames which contains that specific string.
Syntax :
$grep -v Search String Filename
Example :
$grep -v “complexsql” Filename
Output :
grep_file
47. Give the Grep command examples with specific character pattern search?
Answer:
a) $ grep “Complexsql*” Grep_File:
Output :
Planning for coaching classes with Complexsql
Complexsqltechnologies
Complexsqltechnologies
Complexsql
b) $ grep “I[tud]” Grep_File
Output :
This institute is at Hadapsar Pune 411001
c) $ grep “N..e” Grep_File
48. How to delete empty lines from the File? (80% asked Unix Scripting Interview Questions)
Answer:
To Remove empty lines from the file following commands are used:
$ mv Test Grep_File
OR
$ grep -v “^$” Grep_File>Test | mv Test Grep_File
Oracle
dba’’ Student
$ fgrep “Hari
Oracle
103” Student