Sunday, November 29, 2015

UNIX interview Questions For Experience Part - 3 | Linux Basic Questions | Basic Unix Commands

LINUX Interview Questions- Part-3

Q. 61 How will you copy file from one machine to other?

Ans.  We can use utilities like “ftp” ,”scp” or “rsync” to copy file from one machine to other.

Eg: Using ftp:

ftp hostname

>put file1


Above copies file file1 from local system to destination system whose hostname is specified.

Q. 62  I want to monitor a continuously updating log file, what command can be used to most efficiently achieve this?

Ans.   We can use tail –f filename     . This will cause only the default last 10 lines to be displayed on std o/p which continuously shows  the updating part of the file.

Q. 63   I want to connect to a remote server and execute some commands, how can I achieve this?

Ans.  We can use telnet to do this:

telnet hostname –l user

>Enter password

>Write the command to execute


Q. 64  I have 2 files and I want to print the records which are common to both.

Ans.   We can use “comm” command as follows:

comm -12 file1 file2               … 12 will suppress the content which are

unique to 1st and 2nd  file respectively.

Q. 65  Write a script to print the first 10 elemenst of Fibonacci series.

Ans.  Make one file in Vi editor




echo $a

echo $b

for I in 1 2 3 4 5 6 7 8





echo $b


Q. 66  What are the 3 standard streams in Linux?

0 – Standard Input
1 – Standard Output
2 – Standard Error

Q. 68  I want to read all input to the command from file1 direct all output to file2 and error to file 3, how can I achieve this?

command <file1 1>file2 2>file3

Q. 69  Given a file find the count of lines containing word “ABC”.

grep –c  “ABC” file1

Q. 70  What is the difference between grep and egrep?

Ans.  egrep is Extended grep that supports added grep features like “+” (1 or more occurrence of previous character),”?”(0 or 1 occurrence of previous character) and “|” (alternate matching)

Q. 71  How will you find the total disk space used by a specific user?

Ans.    $    du  -s /home/user1             ….where user1 is the user for whom the total disk

space needs to be found.

Q. 72  How will I insert a line “ABCDEF” at every 100th line of a file?

Ans .
$       sed ‘100i\ABCDEF’ file1

Q. 73  Write a command sequence to find all the files modified in less than 2 days and print the record count of each.

find . –mtime -2 –exec wc –l {} \;

Q. 74  How can I set the default rwx permission to all users on  every file which is created in the current shell?

Ans :
We can use:   umask 777
This will set default rwx permission for every file which is created to every user.

Q. 75  How can we find the process name from its process id?

Ans.    We can use “ps –p ProcessId”

Q. 76  How can I send a mail with a compressed file as an attachment?

Ans.               zip file1|mailx –s “subject” Recepients email id

 Email content


Q. 77  How do we create command aliases in shell?

Ans.              alias Aliasname=”Command whose alias is to be created”

Ex :-    alias  server_path=/home/tom/apache

Q. 78  Which is the standard command used to uncompress gzip files?

Ans.  The standard command used to uncompress gzip files is gunzip.

Q. 79  What is the command used to install an RPM package named demofilename2.2-2.i386.rpm?

Ans.   The most common command used to install an RPM package is rpm -ivh. Following command will install the given package

#rpm -ivh demofilename2.2-2.i386.rpm

Q. 80   When attempting to connect to you got unknown host message. Which service is most likely not functioning properly?

Ans.    DNS  - Domain Name Service

Q. 81  Name one of the most secure method of remote access.

Ans.    SSH is the most secure method of remote access

Q.  82  What command is used to exit the edit mode of VI editor?

Ans.  The [esc] key is used to exit from the edit mode of VI editor.

Q.  83  What key combination will exit from VI editor and not save the changes made?

Ans.     Esc + q +! Key combination will exit VI without saving the changes.

Q. 84  Where is the file . bashrc located?

Ans.    The . bashrc file is usually located in the /home/username directory.

Q. 85  What function does the .bash_profile file perform?

Ans.  The function of the .bash_profile file is to provide login initialization commands.

Q. 86  What function does the .bash_logout file perform?

Ans.    The function of the .bash_logout is to provide logout functions

Q. 87  What function does the .bashrc file perform?

Ans.  The function of the .bashrc file is to provide shell configuration commands.

Q: 88 What are the default ports used for SMTP,DNS,FTP,DHCP,SSH and squid ?

Service      Port
SMTP          25
DNS            53
FTP             20 (data transfer) , 21 ( Connection established)
DHCP         67/UDP(dhcp server) , 68/UDP(dhcp client)
SSH            22
Squid         3128

Q. 89  How to check which ports are listening in my Linux Server ?

Ans:  Use the Command ‘netstat –listen’ and ‘lsof -i’

Q. 90 How to check file system and space available on it.


[root@linux-world ~]# df -k

Filesystem            1K-blocks   Used Available Use% Mounted on
/dev/mapper/vg00-root  17003304 804668  15311852   5% /
devtmpfs                 771876      0    771876   0% /dev
tmpfs                    777928      0    777928   0% /dev/shm
tmpfs                    777928   8532    769396   2% /run
tmpfs                    777928      0    777928   0% /sys/fs/cgroup
/dev/mapper/vg00-home  14987616  41000  14162232   1% /home
/dev/sda1                487652  62593    395363  14% /boot
/dev/mapper/vg00-var    9948012  48696   9370932   1% /var
/dev/mapper/vg00-sap   14987656  37636  14165636   1% /sap

Q: 91 – Tell me the steps to remove the swap file?

Ans .  Firstly disable the swap file by “swapoff” command.
Remove Swap file entry from /etc/fstab file.
Now remove the swap file by “rm” command.