Top 50 Linux Interview Questions and Answers for Devops

Top 50 Linux Interview Questions and Answers for DevOps

in this article i am going to explain top 50 interview question and answers for devops. These questions and answers are very useful in realtime projects.

1)   How to find the files containing particular string

using grep command we can find the files containing particular string

grep -rl “string”  <path>

grep -rl "devops" ./abcd

./abcd/hello.txt
./abcd/tt/sf.txt

-l represents show the file name not the lines

-r represents recursive search.

Here it will find the files in abcd directory .

2)  How to find the files older than 7 days

using find command we can find the files greater than n days

find <path> -type f -mtime  +7

mantis~$ find ./ -type f -mtime +7

CI_CD.odt
qwerty.pem

3) How to To Replace String in A File

using sed command we can replace a string in a file

sed -i -e 's/old/new/g'   hello.txt

sed -i -e 's/cat/dog/g' hello.txt

Here it will replace all the strings dog with cat

4) How to find the files greater than 1gb

find /path...  -type f   -size +1G

using find command we can find the files greater than 1gb. here it will all files greater than 1gb

5) How to List processes which are listening on a particular port

we can list the processes which are listening on a particular port using 'lsof' command

lsof -i :portnumber

lsof -i :8080

it will list all the process listening on port 8080

or

using below command we can display open sockets

lsof -n -P | grep LISTEN

lsof -n -P | grep LISTEN

or

netstat -tunlp 

using netstat command also we can list the open ports

netstat -tunlp

6) difference b/w hard link and softlink in linux

hardlinks act as a shortcut to that file that is hard linked. inode of hardlink and file are same and hardlink cannot created for directories. Unlike a hard link, a symbolic link does not contain the data. when you delete a target file, symbolic links become unusable, whereas hard links preserve the contents of the file.

7) How to create a hardlink

using ln command we can create hardlink

ln <filename/path> <hardlinkname>

8) How to create a softlink

using ln -s command we can create softlink

ln -s <filename/path> <softlinkname>

9) what is symbolic link

Symbolic link known as soft link or symlink. It is shortcut to file or directory like in windows system. Soft Link contains the path of original file and not the content. softlink become inactive if you delete the original file. inode values of softlink and original files are different.

10) what is hard link

hard link also one type of pointer to a file. hard links and original file will have same i node values so the hard link represent the same original file location. hard links contains the file content. if you delete the original file still you will have the content in hard link. we can not create hard links for directories.

11) what is i node

Inode is a data structure that stores all the information about a file. Like size of the file, userid of the file, group id of the file, timestamps for file creation, modification..etc. Inode numbers uniquely exist for all the files on Linux.

12) How will you find the inode of a file

using ls -i command we can list all the files with their i node numbers.

172.17.12.1~:~$ ls -i

1019550 Applications	 982931 Movies		1122935 hello
 982879 Desktop		 982874 Music		
 982865 Documents	 982877 Pictures	
 982867 Downloads	 982927 Public		
 982853 Library

 

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *