Unix

UNIX Scripting and Commands Interview Questions and Answer

Q. How to remove empty lines or those beginning with # or #'s not at the beginning of some lines, from the a file using sed command?

A.

# sed '/^#|^$| *#/d' file1.txt

The caret sign followed by the number sign ^# indicates the beginning of a line, whereas ^$ represents blank lines. The vertical bars indicate boolean operations, whereas the backward slash is used to escape the vertical bars.

Q. How to replace multiple blank spaces with a single space?

A.

Using sed command.

sed 's/  */ /g'

Q. Specify the difference between absolute path and related path?

A.

Absolute path refers to the exact path as defined from the root directory. Related path refers to the path related to the current locations.

Q. What is the UNIX command to list files/folders in alphabetical order?

A.

The 'ls -l' command is used to list down files and folders in alphabetical order. When you use 'ls -lt' is list down files /folders sorted with modified time.

Q. Describe the zip/unzip command using gzip?

A.

gzip command creates a zip file using given the filename in the same directory.

gunzip command unzip the file.

Q. How to display the last line of a file?

A.

This can perform using either "tail" or "sed" commands. The easiest way is to use "tail" command.

Q. How to Kill a process in UNIX?

A.

The Kill command accepts process ID (PID) as an in a parameter. This is applicable only for the processes own by the command executor.

Syntax - kill PID

Q. Explain the advantage of executing processes in the background?

A.

The general advantage is to execute processes in the background is to get the possibility to execute some other process without waiting for the previous process to get completed. The symbol "&" at the end of the process tells to the shell to execute given a command in the background.

Q. What is the command to find maximum memory taking process on the server?

A.

The command "top" displays the CPU usage, process id, and other details.

Q. What is the command to find hidden files in the current directory?

A.

'ls -lrta' is to display hidden files in current directory

Q. What is the command to find the currently running process in Unix Server?

A.

"ps -ef" command is used to find current running process. Also "grep" with a pipe can use to find specific process.

Q. What is the command to find remaining disk space in UNIX server?

A.

The command "df -kl" use to get a detail description on disk space usage.

Q. What is the UNIX command to make a new directory?

A.

"mkdir directory_name" is used to create a new directory.

Q. What is the UNIX command to confirm a remote host is alive or not?

A.

Either "ping" or "telnet" command can use to confirm a remote host alive or not.

Q. What is the method to see command line history?

A.

The "history" command display all the command used previously within the session.

Q. What is the command to find weather system is 32 bit or 64 bit?

A.

"arch" or "uname -a" can use for this process.

Q. What is the UNIX command to find how many days the server is up?

A.

"uptime" command returns the number of dates that the server is up.

Q. What is the method to edit a large file without opening it in UNIX?

A.

The "sed" command is available for this process '.sed' stands for a team editor.

Q. What is the process to count the number of characters and line in a file?

A.

"wc -c filename" command can use to retrieve the number of characters in a file and "wc -l filename" command can use to retrieve the number of lines in a file.

Q. Write a command to erase all files in the current directory including all its sub directories.

A.

"rm -r*" is the command used to erase all files in the current directory including all its sub directories

  • rm: this command is used for deleting files.
  • -r : this option will erase all files in directories and sub-directories.
  • '*': this represents all entries.

Q. How is cmp command different from diff command?

A.

'cmp' command is basically used for byte by byte comparison of two files to determine the first mismatch byte. This command does not use the directory name and displays the first encountered mismatched byte.

Whereas, 'diff' command’ determines the changes that are to be performed on the files in order to make the two files identical. In this case, directory names can be used.

Q. Define piping.

A.

When two or more commands are required to be used at the same time as well as run them consecutively, 'piping' process is used. Here two commands are connected so that, the output of one program serves as the input for another program. It is denoted by the symbol '|'.

Enlisted below are few commands where piping is used:

  • grep command: searches files for certain matching pattern.
  • sort command: arranges lines of text alphabetically or numerically

Q. Enlist some filename manipulation commands in UNIX.

A.

Some Filename manipulation commands along with their description is enlisted below in table:

CommandDescription
cat filenameDisplays contents of the file
cp source destinationUsed to copy source file into the destination
mv old name new nameMove/rename and old name to the new name
rm filenameRemove/delete filename
Touch filenameChanging modification time
In [-s] old name new nameCreates soft link on old name
Is -FDisplays information about file type

Q. Explain links and symbolic links.

A.

Links are defined as a second name which is used to assign more than one name to a file. Although links are referred to as a pointer to another file it cannot be used to link filenames on different computers.

A Symbolic link is also known as the soft link is defined as a special type of file that contains links or references to another file or directory in the form of absolute or relative path. It does not contain the data actually in the target file but the pointer to another entry in the file system. Symbolic links can also be used to create a file system.

Q. Explain pid.

A.

A pid is used to denote unique process id. It basically identifies all the processes that run on the Unix system. It does not matter whether the processes are running in the foreground or in the background.

Q. What do know about tee command and its usage?

A.

'tee' command is basically used in connection with pipes and filters.

This command basically performs two tasks:

a) Get data from standard input and send it to the standard output.

b) Redirects a copy of the input data to the specified file.

Q. What is "chmod" command?

A.

Chmod command is used to change file or directory access permission and is the most frequently used command in Unix. According to mode, chmod command changes the permission of each given file.

The syntax of chmod command is:

Chmod [options] mode filename.

Here in the above format, options could be:

  • -R: recursively change the permission of file or directory.
  • -v: verbose, i.e. output a diagnostic for every file processed.
  • -c: report only when the change is made. Etc.

Q. What is the description for Kernel?

A.

Kernel is the master program with UNIX operating system that controls the resources of the computer. The resources allocation to different users and tasks handle by this section. Kernel do not have direct communication with the user and it starts separate interactive program call shell to each user when login to the system.



Python if , elif and else

Python Conditions and If statements

  • 0
Python for beginners

Learning Python Part 1

  • 3
Struct Alignment and Padding

Struct Alignment and Padding in C++ And C

  • 0
Friend function

Friend function C++

  • 0
The diamond problem Solution C++

Solving the Diamond Problem with Virtual Inheritance

  • 0
Pointers

C++ Pointers

  • 0
Structures

C++ Structures

  • 0
Types of Inheritance in C++

Inheritance and access specifiers C++

  • 0
Java date pattern

Java Date Pattern Syntax

  • 0
Java Date and Calendar

Java Date formats

  • 0
JAVA Data Type

Data types in Java

  • 0
Java unreachable code

Unreachable Code Error in Java

  • 0
INTERVIEW EXPERIENCES

Articles

09

FEB

×

Forgot Password

Please enter your email address below and we will send you information to change your password.