Saturday, May 7, 2022

Interview Questions: - (UNIX - 0)

UNIX: -

 

Q) How to get inode number of a file/directory?

Ans – $ ls –i <File/Directory_Name>

 

Q) What is inode?

Ans – inode number is unique identifier given to a file or directory inside a file system.

 

Q) What happens to inode when file is deleted?

Ans - When a file or directory is "deleted" its inode number is removed from the directory which contains the file.

 

Q) What action you will take if inode get filled?

Ans – If all inodes in a file system are completely filled, the unix system cannot create new files even when there is available space on the disk.

inode is full that means unix system have so many files which might be unnecessary. So just we have to find out those unnecessary files and delete them or  we have to find out hard links and removed it.

 

Q) How to find which Unix Operating system you are using?

Ans –$ uname –a

 

Q)  How to change group name of file/directory in unix?

Ans –  $ chgrp <group_name> <file/directory_name>

 

Q) How to change owner name of file or directory in unix?

Ans –  $ chown <owner_name> <file/directory_name>

 

Q) What is link and types of links and explain?

Ans –

 link is a pointer to an original file. It is of two types.

1.       Soft Link (Symbolic Link)

2.       Hard Link

SOFT LINK -

 It has below characteristics.

1.       It creates copy of original file.

2.       Both link file and original file have different inode number.

3.       Once original file is deleted, its corresponding soft link file is unusable.

4.       We can create soft link throughout the file system for the original file.

5.       You can create soft link to a directory.

Syntax: -

$ ln –s <Original File Name> <Soft Link File Name>

Example –

$ ln –s Sample.txt Sample.link

HARD LINK –

 It has below characteristics.

1.       It points to the inode number of the original file.

2.       Both link file and original file have same inode number.

3.       We can access the content of the link file as same as original file, once original file is deleted i.e. it is the backup of the original file.

4.       We can create hard link only within the file system, where original file is present.

5.       You cannot create hard link to a directory.

Syntax: -

$ ln <Original File Name> <Hard Link File Name>

Example –

$ ln Sample.txt Sample.link

Interview Questions: - (UNIX - 1)

UNIX: -

 

Q) Which command will show the output in screen and also saves the output in a file?

Ans – tee command

Example –

$ ls –lrt | tee f1<Enter – Key>

This Command will show the output of ls –lrt in the screen and saves the output in a file f1.

 

Q) What is zombie process?

Ans - When we send any request to shell, the shell calls a fork system call to create a child shell and assign that request to him. It is the responsibility of the child shell to complete the request and sends response back to parent shell. While sending back the response, if parent shell is not available to receive it, then it will keep the response in the result queue and die. Once the parent shell is available, it will search the result queue, take the response or result and display it. The time taken the child dies and parent shell gets the response, then the process will be in zombie state.

 

Q) What is orphan process?

Ans – If parent dies before child finishes it tasks, then the process is called as orphan process.

Here init is the parent process whose PID = 1.

 

Q) How much time unix system is up and running?

Ans - $ uptime

 

Q) What is 9 in kill command?

Ans - 9 is signal number in which kill command sends a signal with signal number 9 to kill the process.

  

Q) How to kill a process?

Ans –

$ ps –ef | grep <command_related_to_process>

Here you will get the process id i.e. 2nd column value.

$ kill -9 <PID_receive_from_1st_command>

 

Q) How you will see how much memory you directory and its sub directory are taking?

Ans - $ du –ch

 

Q) What are commands you are using in your project?

Ans –

ls –lrt

cat

touch

mv

cp

ps –ef

vi

sed

kill

sort

zip

gunzip

 

Q) How to create zero byte file in Unix?

Ans - $ touch <file_name>

Interview Questions: - (UNIX - 2)

UNIX: -

 

Q) Different methods to create a file?

Ans – vi

cat

touch

 

Q) What command will connect and transfer files in single line command?

Ans – scp command

scp source destination

Example –

scp /land01/path02/inbound/file34.dat username/password@servername:path

 

Q) How you know a server www.abc.com is up and running fine?

Ans - $ ping www.abc.com

If you will get output continuously, then it’s up and working fine otherwise not.

 

Q) How to create a tar file?

Ans - $ tar –cvf file.tar f1.txt f45.csv f2.dat<Enter – Key>

Where c – create

V – verbose mode

f - forcefull

 

Q) How to extract files from tar file or unzipped the tar file?

Ans - $ tar –xvf file.tar<Enter – Key>

Where x – extracts

V – verbose mode

f – forcefully

 

Q) How to delete a file from tar file?

Ans -  $ tar - - delete –f file.tar f1.txt<Enter – Key>

 

Q) How to append a file into tar file?

Ans - $ tar –rf file.tar f3.dat<Enter – Key>

Where r – append

 

Q) What is the use of tar ball ?

Ans – It helps in moving the files from one environment i.e. development or testing to another i.e. testing or production.

 

Q) How to zip a file and unzip a file?

Ans - $ zip file.zip f1.txt<Enter – Key>

Or

$ zip file23.zip f67.txt f45.dat fnv.png<Enter – Key>

$ unzip file.zip<Enter – Key>

 

Q) How to zip a file in its original location?

Ans - gzip f1.txt f2.csv f3.dat<Enter – Key>

$ gunzip f1.txt.gz f2.csv.gz f3.dat.gz<Enter – Key>

Interview Questions: - (UNIX - 3)

UNIX: -

 

Q) How to print lines without blank lines in a file?

Ans - $ grep –v ‘^$’ <file_name>

 

Q) Write a command to remove the first number on line 10 in file?

Ans - $ sed '10s/[0-9][0-9]*//' < filename

 

Q) Write a command to remove the first number on all lines that start with "@"?
Ans - $ sed '\,^@, s/[0-9][0-9]*//' < filename

 

Q) Write a command to replace the word "apple" with "(apple)" in a file?
Ans - $ sed s/apple/(&)/ < filename

 

Q) Write a command to replace the character '/' with ',' in a file?
Ans - $ sed 's/\//,/' < filename

 

Q) Write a command to see your current directory you are present in unix system?

Ans - $ pwd

pwd – Present Working Directory

 

Q) Which command will show the creation, modification and access time, inode number and number of links of a file?

Ans - $ stat <File Name>

 

Q) Whether the file file.sh is present in /var/logs/script directory or not ?

Ans - $ find /var/logs/script –type f –name file.sh

Whereas

–type f -> option search only files

-name -> option related to name of any files or directory

If you will get the file name in output, then file is present in the above directory otherwise not.

 

Q) Give me those files which are modified between 5-7 days in current directory?

Ans - $ find . –type f –mtime -7 –mtime +5

-mtime -> modified time option in days

-ctime -> creation time option in days

-7 -> within 7 days

+5 -> beyond or before 5 days.

 

Q) Find those files whose size is 12 GB in current directory?

Ans - $ find . –type f –size 20g

 

Q) Find those files whose size is more than 20 GB in current directory?

Ans - $ find . –type f –size +20g

 

Q) Find those files whose size is less than 20 GB in current directory?

Ans - $ find . –type f –size -20g

 

Q) Find all files whose permission is 644 and change it to 755 in current directory?

Ans - $ find . –type f –perm 644 –exec chmod 755 {} \;

 

Q) How to delete the temporary files in /tmp directory?

Ans - $ find /tmp –type f –name ‘*.tmp’ –exec rm –f {} \;

 

Q) Find all the files created before 6 months having ‘core’ word in the name of the file and remove it ?

Ans - $ find . –type f –ctime +180 –name ‘*core*’ –delete

Or

$ find . –type f –ctime +180 –name ‘*core*’ –exec rm –f {} \;

 

Q) Search all ‘log’ files in /log directory and give me those files having ‘error’ word in it?

Ans - $ find /log –type f –name ‘*.log’ –exec grep –l error {} \;

 

Q) Move all the files which are not modified within 6 months to /usr/archieve directory?

Ans - $ find . –type f –mtime +180 –exec mv {} /usr/archieve \;

Interview Questions: - (UNIX - 4)

UNIX: -

 

Q) How to create an empty directory?

Ans - $ mkdir <Directory_Name>

 

Q) How to create multiple directories in same level?

Ans - $ mkdir <1st Directory Name> <2nd Directory Name> <3rd Directory Name>

Example - $ mkdir d1 d2 d3 d4

 

Q) How to create multiple directories in hierarchical structure?

Ans - $ mkdir –p <1st Directory Name>/<2nd Directory Name>/<3rd Directory Name>

Example - $ mkdir –p d1/d2/d3/d4

 

Q) Why we go for Unix Operating Systems where window is a popular operating system?
Ans - These are the below points why we go for Unix Operating System.
1. Multi User, Multi Tasking
2. Crash Free
3. Virus Free


Q) Unix Architecture?
Ans -


SHELL - It is the interface between user and kernel. It receives the input from user, converts it

into kernel understandable codes and send to kernel.
KERNEL - It interacts with hardware, process the input received from shell and response back
to shell.
HARDWARE - It stores physical data as computer hardware.

 

Q) Why we go for shell scripting?

Ans – In Unix command prompt, we can run a single command at a time. To combine and run multiple commands for performing certain tasks, shell script is evolved.

Interview Questions: - (UNIX - 0) UNIX: -   Q) How to get inode number of a file/directory? Ans – $ ls –i <File/Directory_Name...