Linux Interview Questions And Answered Part-1

Q.1 What is the use of echo command.
Ans- echo is a command that outputs the strings that are passed to it as arguments.
#echo "Hello World"

Q.2 How to check the computer name or hostname in Linux?
#hostname

Q.3 How to check the current user in Linux terminal?
#whoami

Q.4 How to check your current path/directory you are working in?
#pwd

Q.5 Explain the difference between relative and absolute path?
Relative path: Start from current working directory.

Absolute path: The full path to a file or directory.

Q.6 Which command to be used to create a file in Linux?
#touch

#vi

#vim

#nano

Q.7 How to rename a file in Linux
#mv

Q.8 How to search for a string in a file?
#grep

Q.9 Difference between grep and egrep ?
In egrep, you can search for more than one strings at same time.
#egrep /"key1|key2|key3"

Q.10 How can you read a file without using cat command?
#less

#more

#vi

Q.11 What is the advantage of using less command?
We can easily read big files.
Forward and backward search is easy.
Navigation from top to bottom is easy.
Q.12 How to check a file's permission?
#ls -ltrh

#getfacl bhau

#ll

Q.13 How to check the IP of your Linux server?
#ifconfig

#ip addr

Q.14 How to read the top 2 lines in a file?
#head -2 file_name

Q.15 How to read the last 1st lines in a file?
#tail -1 file_name

Q.16 How to list hidden files?
#ls -la

Q.17 How to see all the recently used commands?
#history

Q.18 What is root?
Admin or super user
/root home directory for root user.
/ root directory
Q.19 What is inode and how to find it for a file?
#ls -li
inode is an index node. It serves as a unique identifier for a specific piece of metadata on a given filesystem.

Q.20 Which command can you use for finding files on a Linux system?
#locate

#find

Q.21 Command for counting words and lines?
#wc

#wc -l (Showing Only Lines)

Q.22 How can you combine two commands? or What is pipe used for?
We can combine two command using | (pipe sign)
ex: command1 | command2
Pipe is used to combine two commands and redirect output of command1 to command2

Q.23 How to view the difference between two files?
#diff file1 file2

Q.24 What is the use of the shred command?
permanently delete a file which is unable to recover
#shred -u file_name
#shred --remove file_name

Q.25 How to check system architecture info?
#lscpu

#dmidecode

Q.26 How to combine two files?
#cat file1 file2

#cat file1 file2 > file3
Q.27 How can you find the type of file?
#file file_name

Q.28 How to sort the content of a file?
#sort file_name

#cat file_name | sort

Q.29 Different ways to access a Linux server remotely(from a Windows machine)?
Using some tools and terminal like
* Putty
*git bash
* cmd
Thank you for reading!! I hope you find this article helpful!!
Happy Learning!!