0% found this document useful (0 votes)
132 views

Linux Interview Question - Answers

Uploaded by

ravi_kishore21
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
132 views

Linux Interview Question - Answers

Uploaded by

ravi_kishore21
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 39

Linux Interview Question

1. What is the boot process in Linux?


2. How to create zero size file
Linux?
 Using touch command we can create zero
size file
3. What is soft link and hard link?
How to create? What is the
difference between these two?
Using in command we will create
link
$ ln myfile.txt my-hard-link

$ ln -s myfile.txt my-soft-link
4.What is first line written in shell script?
What is the meaning of that? If I didn’t write
that line what will happen? Then how to run
the script?
 #!/bin/bash – Execute the file using
the Bash shell.
 #! Called shebang
 The #! syntax used in scripts to indicate
an interpreter for execution under UNIX
or Linux operating systems
 If not writen in file we need to execute
like below
/bin$ bash /home/madhu/test.sh
5. How to run a shell script in
background?
 Execute a command in the background using &
$ ./my-shell-script.sh &
 2. Execute a command in the background using
nohup
 After you execute a command (or shell script) in
the background using &, if you logout from the
session, the command will get killed. To avoid that,
you should use nohup as shown below.
 $ nohup ./my-shell-script.sh &
6. What is cron tab? Explain it? How
to configure the schedule a job?
 crontab uses a daemon, crond, which runs
constantly in the background and
scheduled jobs need to be executed.
 MIN HOUR DOM MOY DOW
* * * * *
 0-59 0-23 1-31 1-12 0-6

 To check crontblist “ crontab -l”


 To edit crontab “crontab -e”
7.How to allow the ports in Linux?

 iptables -A INPUT -p tcp --dport 12375 -j


ACCEPT
 iptables -A OUTPUT -p tcp --dport
12375 -j ACCEPT
 you can also add them to your iptables-
config file then restart iptables

/etc/init.d/iptables restart
8. How to trouble shoot the
remote server having some issue?
 First will do ssh if it’s connected
 Uptime
 Top
 Free
 df
 du
9. What is ping? Telnet? Curl? Wget?

 Ping commonly used to check whether


your connection to the server is
healthy or not.
 Telnet is a user command and an
underlying TCP/IP protocol for accessing
remote computers.
 wget is a tool to download files from
servers.
 curl is a tool that let's you exchange
requests/responses with a server
10. How to check the services in
Linux machine?
 chkconfig –list
11. How to kill the process in Linux?

 First check the whichh process you want


to kill using ps command. Then will get pid

 Kill -9 <pid>
12. What is nice and renice?

 You can ask the kernel to put a particular process


of yours, on higher priority than others using
nice commnad
 Process priority values range from -20 to 19
nice value.
nice -10 <command name>
 In order to change the priority of an already
running process you can use "renice" command.
 renice 13 -p <PID>
 -20 (most favorable to the process) to 19 (least
favorable to the process)
13. What is inode value?
 An inode is an entry in inode table,
containing information ( the metadata )
about a regular file and directory. An
inode is a data structure on a traditional
Unix-style file system such as ext3 or
ext4
 $ ls -il myfile.txt
1150561 -rw-r--r-- 1 root root 0 Mar 10
01:06 myfile.txt
14. How to check the CPU
utilization?
 Using top command
15. Difference between Top/HTop?
 In 'htop' you can scroll the list vertically and horizontally to
see all processes and complete command lines.
 In 'top' you are subject to a delay for each unassigned key
you press (especially annoying when multi-key escape
sequences are triggered by accident).
 'htop' starts faster ('top' seems to collect data for a while
before displaying anything).
 In 'htop' you don't need to type the process number to kill a
process, in 'top' you do.
 In 'htop' you don't need to type the process number or the
priority value to renice a process, in 'top' you do.
 'htop' supports mouse operation, 'top' doesn't
 'top' is older, hence, more used and tested.
16. What is mount? How to create
mount?
 Mounting a filesystem means making the particular
filesystem accessible at a certain point in the Linux
directory tree.
 $ mount
 When you type this at a command prompt, this
command will display all the mounted devices, the
filesystem type it is mounted as, and the mount point.
 mount [OPTION...] DEVICE_NAME DIRECTORY
 https://linuxize.com/post/how-to-mount-and-
unmount-file-systems-in-linux/
17. How to trouble shoot live logs?

 Using “tail –f filename”


18. What is sed command?

 SED command in UNIX is stands for


stream editor and it can perform lot’s of
function on file like, searching, find and
replace, insertion or deletion.
 $sed 's/unix/linux/' file.txt
19. What is AWK command?

 Awk is a scripting language used for


manipulating data and generating
reports.The awk command programming
language requires no compiling, and allows
the user to use variables, numeric functions,
string functions, and logical operators.
 Awk is abbreviated from the names of the
developers – Aho, Weinberger, and
Kernighan.
 https://www.geeksforgeeks.org/awk-
command-unixlinux-examples/
20. What is grep and egrep?

 grep command we will use to search


particular content.
grep madhu filename.txt
 Egrep we will use you want grep mutiple
word at a time
 egrep ‘madhu|sudhan’ filename.txt
21. How to list out the only
directories in a Linux?
 $ ls -l | grep ‘^d’
22. How to check the process in
Linux?
 Using ps command
23. How to get the java thread
dump?
 Using jstack command
24. How to check the running
ports?
 Using netstat -tulpn | grep LISTEN
25. How to declare a variable in a
shell script?
days=5
name=”madhu”
26.What is $?, $#, $*,$@ ?

 $# Stores the number of command-line


arguments that were passed to the shell
program.
 $? Stores the exit value of the last command
that was executed. (0 or 1)
 $0 Stores the first word of the entered
command (the name of the shell program).
 $* Stores all the arguments that were
entered on the command line ($1 $2 ...).
 "$@" Stores all the arguments that were
entered on the command line, individually
quoted ("$1" "$2" ...).
./test.sh one two "three four"
 Using $*:
one
two
three
four
 Using "$@":
one
two
three four
27. How to read a command line
input in shell script?
 with $<arguementnumber>
 $1 or $2 or $3
28. What is umask?

 Return, or set, the value of the system's file mode


creation mask.

In Linux, the default permissions value is 666 for
a regular file, and 777 for a directory. When
creating a new file or directory, the kernel takes
this default value, "subtracts" the umask value, and
gives the new files the resulting permissions.( 666
– 022 = 644)
 /etc/profile.d
 https://www.computerhope.com/unix/uumask.ht
m
29. How to change file permission in
Linux?
 using chmod commnad.
 the user can read, write, ande xecute it;
 members of your group can read ande xecute it;
and
 others may only read it.
chmod u=rwx,g=rx,o=r myfile
chmod 754 myfile
 4 stands for "read",
 2 stands for "write",
 1 stands for "execute", and
 0 stands for "no permission."
30. How to connect remote servers
without password? How to archive
this?
 using ssh-keygen
 To use public key authentication, the
public key must be copied to a server and
installed in an authorized_keys file. This
can be conveniently done using the ssh-
copy-id tool. Like this:
 ssh-copy-id -i ~/.ssh/tatu-key-ecdsa
user@host
31. How to open file in read only
mode in VI editor?
 vi –R filename
32. What is the purpose of export
command?
 export - Set export attribute for shell
variables.
Example:
To Set JAVA_HOME:
$ export JAVA_HOME=/usr/local/jdk
33. How to send error logs and
stdout logs in to files?
 There are two main output streams in Linux (and other
OSs), standard output (stdout) and standard error (stderr).
Error messages, like the ones you show, are printed to
standard error. The classic redirection operator (command >
file) only redirects standard output, so standard error is still
shown on the terminal. To redirect stderr as well, you have a
few choices:
 Redirect stdout to one file and stderr to another file:
command > out 2>error
 Redirect stderr to stdout (&1), and then redirect stdout to a
file:
command >out 2>&1
 Redirect both to a file:
command &> out

34. What is nohup command?

 to run a script in backround


35. What is netstat command in
Linux?
 netstat (network statistics) is a command line tool for
monitoring network connections both incoming and
outgoing as well as viewing routing tables, interface statistics
etc.
# netstat -a | more : To show both listening and non-listening
sockets.
# netstat -at : To list all tcp ports.
# netstat -au : To list all udp ports.
# netstat -l : To list only the listening ports.
# netstat -lt : To list only the listening tcp ports.
# netstat -lu : To list only the listening udp ports.
# netstat -lx : To list only the listening UNIX ports.
# netstat -s : To list the statistics for all ports.
# netstat -an | grep ':80' : To get the process which is using
the given port.
36.How to run a script at boot
level?
 n the file you put in /etc/init.d/ you have
to set it executable with:
chmod +x /etc/init.d/start_my_app
 If this does not run you have to create a
symlink to /etc/rc.d/
ln -s /etc/init.d/start_my_app /etc/rc.d/

You might also like