Prepare better with the best interview questions and answers, and walk away with top interview tips. These interview questions and answers will boost your core interview skills and help you perform better. Be smarter with every interview.
The linux directory commands are :
1) pwd: It is a built-in command which stands for ‘print working directory’. It displays the current working location, working path starting with a / and directory of the user. Basically, it displays the full path to the directory you are currently in.
2) Is: This command lists out all the files in the directed folder.
3) cd: This stands for ‘change directory’. This command is used to change to the directory you want to work from the present directory. We just need to type cd followed by the directory name to access that particular directory.
4) mkdir: This command is used to create an entirely new directory.
5) rmdir: This command is used to remove a directory from the system.
The Linux Kernel is a low-level systems software whose main role is to manage hardware resources for the user. It is also used to provide an interface for user-level interaction.
There are so many Linux distributions but the one thing that they have in common is the Linux kernel. Each operating system uses a kernel. Without a kernel, we can’t have an operating system that actually works. The kernel's main responsibility is to talk to the hardware and software, and to manage the system’s resources as best as possible. It talks with the hardware by means of the drivers that are included in the kernel. For example, when an application needs to accomplish something (say change the brightness of the display), it can simply submit the request to the kernel, and the kernel can utilize the driver it has for the display to change its brightness.
The kernel is highly involved in resource management. It has to ensure that there is sufficient memory available for an application to run, as well as to load an application in the correct location in memory. It tries to optimize the usage of the processor so that it can complete tasks as quickly as possible. It also aims to avoid deadlocks, which are problems that completely halt the system when one application needs a resource that another application is using.
A linux process can be in any one of the following process states:
The cat (short for “concatenate“) command allows us to create single or multiple files, view content of file, concatenate files and redirect output in terminal or files.
1. Display contents of a file.
In this example , it will show the contents of the file debug.log
2. View contents of multiple files.
In this example , it will show contents of multiple files.
3. Create a file with cat command
In this example we create a text file using the cat >filename
Command.(Press ctrl + D to exit)
4. Use standard output with redirection operator.
We can redirect standard output of a file into a new file or
existing file with ‘>‘ (greater than) symbol but the contents
of the existing file will be replaced.
The ps (i.e., process status) command is used to provide information about the currently running processes, including their process identification numbers(PIDs).
A process, also referred to as a task, is an executing (i.e., running) instance of a program. Every process is assigned a unique PID by the system.The basic syntax of ps is - ps [options]
netstat(short for network statistics) is a command-line network utility which we can use to check the network ports in use and their incoming connections.
Netstat basically checks the network status.
It can also display network connections for the transmission control protocol, routing tables, and a number of network interface and network protocol statistics.
It is used for finding problems in the network and to determine the amount of traffic on the network as a performance measurement.
Linux operating system basically consists of 3 components which are as follows:
It is always required to keep a check on the memory usage in order to find out whether the user is able to access the server or the resources are adequate. There are basically 5 methods that determine the total memory used by the Linux.
This is explained as below
Every file and directory in Linux are assigned three types of owners namely ‘User’, ‘Group’, and ‘Others’. The three types of permissions defined for all the three owners are :
Process management in linux uses certain system calls.The system calls are as follows :
For executing any commands user uses a program known as the shell. Linux shell is basically a user interface used for executing the commands and communicating with Linux operating system. Shell does not use the kernel to execute certain programs, create files, etc. There are several shells available with Linux which includes the following
There are basically two types of Shell commands
To change permissions in linux , we need to understand the concept of binary assignment.
Each permission within a permission group is assigned a binary representation.
Read - 4 ( 100 )
Write - 2 (010)
Execute - 1 (001)
For example, if we wanted to give the owner ‘rwx’ , owner’s group ‘r-x’ and others ‘r--’ permissions will be summed up to give the permission i.e for owner- r + w + x = 4 + 2 + 1 = 7 , for owner’s group r + x = 4+1=5 , and for others = r = 2.
So, the permission will be “752”.
Now coming to the question , an admin or an owner can change the permissions of a file using the “chmod” command line utility.
Syntax of the chmod command is of the form:
chmod <file-permission> file-name.
So for bringing the permissions of the above example into effect ,we can use the command chmod 752 file.txt
The wc (word count) command is used to find out the count of
number of characters in a file.
Apart from count of characters wc command can also be used to find out the newline count , byte and character count in files Specified by file arguments.
The syntax of the wc command is of the form:
wc [options] filename
The following are the options and usage provided by the command:
wc -l : prints the number of lines in a file.
wc -w : prints the number of words in a file.
wc -c : prints the number of bytes in a file.
wc -m : prints the number of count of characters in a file.
wc -L : prints only the length of the longest line in a file.
So the answer is the command wc -m file.txt
The Linux “du” (short for disk usage) is a standard Linux command, used to check the information of disk usage of files and directories on a machine. The du command has many parameter options that can be used to get the results in many formats. The du command also displays the files and directory sizes in a recursively manner.
The & (ampersand) should be appended to a command to run a process in the background.
Contents of file.
We can make use of the sort command found in linux to arrange.The records of a file in a particular order.
By default, the sort command sorts file assuming the contents are ASCII. Using options in sort command, it can also be used to sort numerically.
It is well known that every command takes an input and displays an output. Keyboard serves as the standard input device and screen serves as the standard output device. Redirection is defined as the process of directing data from one output to another or even cases exist where output serves as an input data for another process.
There are basically three streams available in which input and output of Linux environment are distributed.
These are explained as below:
Yes , it is absolutely legal to edit Linux Kernel. Kernel is released under General Public License(GPL) , and anyone can edit Linux Kernel to the extent permitted under GPL. Linux Kernel comes under the category of Free and Open Source Software(FOSS).
‘init’ is the first process in linux which is started by the kernel and its process id is 1.
grep -c “error” debug.log
The grep command which stands for globally search for regular expression and print out , searches a file for a particular pattern of characters and displays all lines that matches that pattern.
The pattern that is searched in the file is referred to as regular expression.
Syntax of a grep command is of the form : grep [options] pattern [files]
In the above command the -c options description prints the count of lines in the file debug.log that match the pattern “error”.
Although if we would want to ignore case for matching i.e consider both the words “error” and “ERROR” we need to use the following command:
grep -c -i “error” debug.log , where -i is an option that ignores case for matching.
The six stages of the linux boot process are:
These are the runlevel programs, executed from the run level directory as defined by the run level.
We use the command head -n5 sample.txt to display the first five lines of the file and the command tail -n5 sample.txt to display the last five lines of the file.
The idea is to make use of the head and tail commands to get the required results.
The head command reads the first ten lines of any given file.
The basic syntax of the head command is:
head [options] [file(s)]
If we need to print more or less than the default ten number of lines from the beginning of a file we need to use the ‘-n’ option along with an integer telling the number of lines to be retrieved.
Similarly the tail command displays the last ten lines of any given file.
The basic syntax of the tail command is:
If we need to print more or less than the default ten number of lines from the end of a file we need to use the ‘-n’ option along with an integer telling the number of lines to be retrieved.
LILO stands for Linux Loader that is used to load Linux into memory. It can boot operating systems from floppy disks, hard disks, and it does not depend on a specific file system. Lilo handles some tasks such as locate the kernel, identify other supporting programs, load memory and starts the kernel. The configuration file of lilo is located at “/etc/lilo.conf”. Lilo reads this configuration file and it tells Lilo where it should place the bootloader.
When LILO loads itself, it displays the name LIO where each word specifies some actions
Swap space is a type of memory used by linux to increase the amount of virtual memory available to the host.
Virtual memory is the memory that appears to exist as main storage although most of it is supported by data held in secondary storage.
It can use one or more dedicated swap partitions or a swap file on a regular filesystem or logical volume.
The primary function of swap space is to substitute disk space for RAM memory when the RAM is filled up and more space is required.
Let’s say , we have a computer with 4GB of RAM. If we run programs that don’t fill up the RAM , they will run and no swapping will be required. But , let’s say that the spreadsheet we are working on grows when we add more rows , and plus everything else that’s running , now fills all of RAM. Without swap space available we would have to stop working on the spreadsheet until we free up some RAM by closing down some other programs.
The kernel uses a memory management program that detects Pages of memory in which the contents have not been used recently.The memory management program swaps enough of these relatively infrequently used pages of memory out to a special partition on the hard drive specifically designed for paging , or swapping. This frees up RAM and makes room for more data to be entered into the spreadsheet.Those pages of memory swapped out to the hard drive are tracked by the memory management code of the kernel and can be paged back into RAM if needed.
Linux keeps user account information in a text file called /etc/passwd. This file also stores one way encrypted password. It is accessed by several tools to get user information, which is a security risk, so file needs to be ‘Word Readable.’ To minimize the security risk, we can use shadow password format. This method saves account information in regular file /etc/passwd.
However, the password is stored as a single “x” character (not actually stored in this file). A second file, called “/etc/shadow” contains encrypted password as well as other information such as account or password expiration values, etc. The /etc/shadow file is readable only by the root account and is therefore less of a security risk.
Yes, a Linux machine can be made a router. This is called “IP Masquerade.” IP Masquerade is a networking function in Linux similar to the one-to-many (1: Many) NAT (Network Address Translation) servers found in many commercial firewalls and network routers.
The IP Masquerade feature allows other “internal” computers connected to this Linux box (via PPP, Ethernet, etc.) to also reach the Internet as well. Linux IP Masquerading allows this functionality even if the internal computers do not have IP addresses.
The IP masquerading can be done by the following steps :
The list of modes used in Network Bonding are :
It is quite common to access servers using ssh. So the following steps can be taken to secure the SSH service, such as:
We can use the command : tail -F $logfile.
where $logfile is an environment variable corresponding to the path to the log file to be monitored.
By default, the Linux tail command prints the last 10 lines of a given file to standard output. The -F(short for --follow) option causes additional file content to be displayed in real time as the file continues to grow.