Linux Interview Questions And Answers

  • By
  • September 7, 2019
  • Linux
Linux Interview Questions And Answers

Linux Interview Questions And Answers

 

1: How SSH is different than Telnet?

Answer:

SSH and Telnet are both communication protocols to manage a remote system, Unlike Telnet which sends the data on clear-text, SSH is the secured version of the telnet, and will require key exchange . 

 2: How do you change the default editor to nano when used by a system command (like crontab -e)?

Answer:

It can be set by “export EDITOR=nano”  The system will use the editor defined in your EDITOR environment variable .

 

3: You encounter issues while using X and you cannot quit the X server, how can you force it to restart?

Answer:

Use keyboard combination of Alt-Ctrl-Backspace which will force restarting X server

4: Which TCP ports are used for FTP, SSH, SMTP, POP3, HTTP and HTTPS respectively?

Answer:

For the mentioned services following TCP ports 21, 22, 25, 110, 80, 443 are used respectively. 

5: What is the difference between ping and ping6?

Answer:

The commands ping, traceroute, tracepath are used on ipv4 addresses. The commands ending with 6 are intended to use on ipv6 addresses i.e. ping6, traceroute6, tracepath6.

 6: What does an open mail relay server mean?

Answer:

It means that this is a server that everyone can send emails through it without the need to identify first or be a part of the domain group. 

7: How to create a symbolic link between /bin/runme to the new file /bin/runmetoo?

Answer:

Use the command “ln”

ln -s /bin/runme /bin/runmetoo.

8: You want to find and delete all of the “.tmp” files in /home/* then how can you do it in a command?

Answer:

First you need to find these files using find command, then delete them using rm command –

find /home/ -name ‘*.tmp’ | xargs rm –rf.

For Free Demo classes Call:7798058777

Registration Link: Click Here!

9: How can you add an “auto correction” that will automatically fix “cd /homr” to “cd /home”?

Answer:

You can use cdspell option to your shell options by typing “shopt -s cdspell”. 

10: How do you get additional information about any command – for example get information about passwd?

Answer:

If you want to learn about a command in detail then you can use the commands

man passwd or info passwd to learn more about passwd.

11: You are running a any linux command and doesn’t want the command to send an output to the terminal, how can you handle it?

Answer:

You can redirect (send) all of the output from the command (STDOUT AND STDERR) to /dev/null – a command which you want to execute 2>&1 >/dev/null 

12: Which command we can use to list the arp cache table of the current machine?

Answer:

Using arp command you can control and view the arp table. 

13: How can you eject your cdrom drive from the console?

Answer:

In order to eject the cdrom drive, you can use the command eject. 

 14: You see a process “./myApplication” with PID 5645, how can you know where was the file executed from?

Answer:

You can identify the path where the PID was executed by running pwdx 5646 and you will get the command executing path as an output.

15: Doing Linux Operating System Installation process if you want to record your commands and outputs for later review, how can you do that?

Answer:

You can take the help of script application for this functionality – type script – a mysession.log and it will start recording your terminal to mysession.log, when you want to exit then type exit.

16: How can you get a view of the calendar of March 2019 on a Linux console?

Answer:

cal 03 2019. By using this command you can get a view of the month/year calendar. 

17: You have hundreds of text files in a directory, you want to know in which file you have the string “My String”, how can you do it?

Answer:

You can use the command “grep” with regular expression in order to find data in files – grep “My String” *.txt 

18: What command is used to get the IP address(es) (domain resolution process)of the domain name Google.com in Linux?

Answer:

In order to find the related IP Address(es) of the domain google.com you can use “nslookup google.com” 

19: What will be the outcome of the following command – touch – m myFile?

Answer:

If the file doesn’t exist, it will create a new file with myFile name. If the file exists, it will only change the modification time of the given file. 

For Free Demo classes Call:7798058777

Registration Link: Click Here!

20: Given the directory “myImportantFiles” how can you create a tar file “myImportantTar.tar” containing this folder?

Answer:

You need to use the tar command to create a tar file – tar -cf myImportantTar.tar myImportantFiles. 

21: How can you check, which Kernel version is currently loaded to the system without checking the logs?

Answer:

The uname tool allows you to get various system information – to get only the kernel data, you can use uname –rsv.

 

22: What is the similar tool for “Windows Commander” or “Norton commander” for Linux console?

Answer:

Linux provides a unique tool i.e. mc (Midnight Commander) to allow the linux user to have an interactive interface for file management in Linux Console. 

23: How can you change a password of a different user (john), when you have root access?

Answer:

Using the passwd command with the destination username – passwd john 

24: How do you make sure that your computer date & time always syncs with environment network?

Answer:

You need to run manually “ntptime ntpserver.com” command or connect your server to an ntp server using ntpd. 

25: You have a tar file (myFile.tar), how do you convert it to a gzip file on best compression?

Answer:

If you need to compress the file with best compression ratio then you need to run the command “gzip -9 myFile.tar” and it will convert myFile.tar file into myFile.tar.gz. file. 

 26: How to disable eth1 during runtime?

Answer:

Use command “ifdown eth1” or “ifconfig eth1 down”  to disable a network card for the current runtime , 

27: How to get the current username that you are logged in with?

Answer:

Use command “who am I” or “whoami”, you can find the user that you are logged in with.

 

28: How can you install gcc compiler using the apt-get application,?

Answer:

Use command “apt-get install gcc” The apt-get allows you to download and install new applications like gcc. 

29: How to run “remote-desktop” VNC application on Linux?

Answer:

In order to run the vncserver daemon and connect to the server using a vncviewer on port 5900 + vnc instance number (5901,5902). 

30: How can you search all lines starting with the word “Error” in the log file “mylog.log”, with a single command?

Answer:

Use commnad “grep ^Error mylog.log” The  command grep allows you to find only lines beginning with the provided string. 

 31: You have a file that you want to randomize lines within a file and create permutations of it for distinctive file list, how do you perform a permutation operation on the file and convert it into a new permuted file?

Answer:

The Linux tool shuf that allows you to create permutations of a file and shuffle the lines within a file, which will allow you to create new files it contains permutation output- shuf old_file.txt > new_file.txt. 

32: How can you verify that the file has not been corrupted when you have moved a file from one server to another, but you are not sure that the file has been perfectly moved, 

Answer:

You have to use the md5sum tool on both servers on the file and match the result, if it is the same, the file has not been corrupted. 

For Free Demo classes Call:7798058777

Registration Link: Click Here!

33: How would you copy the file “file1.txt” owned by root using secure ftp from 10.1.1.2 on /root/ to your local folder in one command?

Answer:

You need to use the scp tool (secure copy over sftp) which allows copying in one line scp root@10.1.1.2:/root/file1.txt ./ 

34: Which command will you use to change all the ownership of /home/user2 to user10 (recursively)?

Answer:

You need to use the chown command on the directory – chown –R user2:user2 /home/user10 

35: How to check how long is the system running since the last restart and the load average on it?

Answer:

The uptime command will show you the current time, how long the system has been running since the last restart, how many users are currently logged on to the system, it also shows system load averages in last 1, 5, and 15 minutes. 

36: How can you check what processes a specified user (susan) is currently running?

Answer:

Use ps command can be used to show the current processes of all or specific users –

ps -U susan. 

37: Which command will show all the running processes at the system and their resources use on a live auto-refreshing view?

Answer:

top command will show all the processes in the system and sort them by resources usage. 

38: Which command is used with gzip for decompression?

Answer:

The gzip tool provides another tool gunzip for gzip files decompression. 

39: You are waiting for a 100M file to complete upload (file.tar.gz) by a user to your directory. Which command can be used to sample the file every 5 seconds ?

Answer:

Use command “watch -n 5 ‘ls -sh file.tar.gz‘”

and it will show the output of the command every 5 seconds.

40: How to see the contents of a gzip compressed file without decompressing it first?

Answer:

You can use zcat with the following command: zcat <filename>.gz

OR

You can use tar with the following command: tar -tvzf <filename>.gz

41: You have found a command in /bin/ and you want a brief explanation about it. What do you do in order to find it?

Answer:

You can find a command brief information using: whatis <command> 

42: What is the difference between locate and slocate?

Answer:

locate will search the updated results for the file,

slocate will search for files that the user have access to. 

For Free Demo classes Call:7798058777

Registration Link: Click Here!

43: The command locate is expecting what in order to provide successful results?

Answer:

The command locate uses the database created by updatedb and it will provide results according to the last updated database. 

44: How can you search for the word “FindMe” in all of the “.txt”

files in the current directory, recursively?

Answer:

Find . -name “*.txt” | xargs grep “FindMe” 

45: How can you send a message “Hello Everyone” to everyone who is currently connected to the system?

Answer:

You can use the command “wall Hello Everyone”. If you want to send a message to all of the connected users. 

46: Use the command crontab to run task once a day at 3am and write the output of ls into /tmp/ls_result?

Answer:

  1. a) Edit crontab: crontab -e
  2. b) Add crontab line: 0 3 * * * /bin/ls > /tmp/ls_result
  3. c) Save crontab.

 

47: How can you make the file untouchable.txt to be immutable (un-alterable) so it will not be able to be changed or deleted by any user including root?

Answer:

You can use attributes to change the file to be immutable using chattr +i untouchable.txt.

48: Use a PHP statement from the command line without creating a file?

Answer:

php -r ‘echo “Hello World\r\n”;’

49: Which command will find the usage time of all the users on the machine (individually)?

Answer:

Use the command ac to get login information about users

ac -p

50: Which command would you use to create network statistics and graphs for your server?

Answer:

Use network statistics command called mrtg (Multi Router Traffic Grapher) and is the most recommended open-source tool.

51: Which command used to send the BIOS a query message directly from the command line?

Answer:

You can send it a message from the console by using the biosdecode command to query the BIOS,

52: Which commands are used to manage partitions on a Linux system?

 Answer:

Partition management on linux is done by two commands fdisk and parted.

53: What is the use of the lsmod command?

Answer:

The lsmod command is used to show the status of modules that are loaded into the Linux kernel. It is a nice way to see /proc/modules.

 

For Free Demo classes Call:7798058777

Registration Link: Click Here!

Call the Trainer and Book your free demo Class for now!!!

call icon

© Copyright 2019 | Sevenmentor Pvt Ltd.

 

Submit Comment

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

*
*