4. Linux FAQ
4. Linux FAQ
46. How do you search for files containing specific text in Linux?
Ans: The grep command is commonly used to search for files containing specific text in Linux. By
using the syntax grep "search_text" file_pattern, it will display lines from the specified file(s) that
match the search text.
54. How do you check the size of a directory and its contents in Linux?
Ans: The du command is commonly used to check the size of a directory and its contents in Linux. By
running du -sh directory, it will display the summarized disk usage of the specified directory,
including all its subdirectories. The -s option provides a summary, and the -h option displays sizes
in a human-readable format.
Ans: The ln command is used to create symbolic links (also known as soft links) in Linux. By running ln -
s target link_name, it will create a symbolic link named link_name that points to the target file or
directory. Symbolic links are references to the target, not actual copies.
62. How do you create a new user in Linux? How do you grant that user sudo
privileges?
Ans: To create a new user, use the adduser command followed by the username. To grant sudo
privileges to a user, add the user to the sudo group using the usermod command.
63. How do you list the contents of a directory, and how do you recursively
list the contents of subdirectories?
Ans: To list the contents of a directory, use the ls command. To recursively list the contents of
subdirectories, use the ls -R command.
+91 – 99 85 39 66 77
64. How do you search for a file by name, and how do you search for a string
within the contents of a file?
Ans: To search for a file by name, use the find command. To search for a string within the contents of
a file, use the grep command.
65. How do you set environment variables in Linux, and how do you
temporarily set environment variables for a single command?
Ans: To set environment variables in Linux, you can use the export command. To temporarily set
environment variables for a single command, you can use the env command.
66. How do you view and navigate the filesystem hierarchy in Linux?
Ans: To view and navigate the filesystem hierarchy in Linux, you can use the cd command to change
directories, the ls command to list the contents of a directory, and the pwd command to display the
current working directory.
67. How do you create and edit a file in Linux using the command line?
Ans: To create and edit a file in Linux using the command line, you can use a text editor such as vi or
nano.
68. How do you create and extract tar, gzip, and bzip2 archives in Linux?
Ans: To create a tar archive, use the tar command followed by the -cf flag and the desired filename. To
extract a tar archive, use the tar command followed by the -xf flag and the archive filename. To create
a gzip archive, use the gzip command followed by the desired filename. To extract a gzip archive, use
the gunzip command followed by the archive filename. To create a bzip2 archive, use the bzip2
command followed by the desired filename. To extract a bzip2 archive, use the bunzip2 command
followed by the archive filename.
69. How do you schedule a task to run automatically in Linux using cron?
Ans: To schedule a task to run automatically in Linux using cron, you can use the crontab command to
open the crontab file and add a new entry specifying the schedule and command to be run.
70. How do you view and kill running processes in Linux, and how do you view
log files?
Ans: To view running processes in Linux, use the ps command. To kill a process, use the kill command
followed by the process ID. To view log files, you can use a text editor or the tail command to view the
end of a log file.
+91 – 99 85 39 66 77
71. What is Linux and How it is different from Windows ?
Ans: Linux is free and open source Operating System and it is Multi User operating System developed
by Linux Torvalds
Windows OS developed by Microsoft and it is single user operating system developed by Microsoft.
Ex: Amazon Linux, Ubuntu, Fedora, Red Hat Linux, SUSE etc..
Ans: BASH (Bourne Again Shell) is basically a command language interpreter. It was written by Brian
Fox for GNU OS and can be used in place of Bourne Shell. It is similar to Bourne Shell but includes some
additional features such as command-line editing that make it easier and more convenient to use. It is
the default user shell on most Linux installations. It is basically an interpreted and non-compiled
process that can also run in the terminal window. It is also capable of reading commands from shell
scripts
Memory Management
Process Management
Device Management
Storage Management
Manage access, and use of various peripherals that are connected to the computer.
Ans: Swap space, as the name suggests, is basically a space on a hard disk that is used when the
amount of physical memory or RAM is full. It is considered a substitute for physical memory. Its main
function is to substitute disk space for RAM memory when real RAM does not have enough space to
hold all programs that are executing, and more space is required. In simple words, it can be used as an
extension of RAM by Linux.
Ans: VI editor (Visual Editor) is basically a default text editor that usually comes with most of the Linux
OS. There are basically three types of modes used in VI editor as given below:
79. What are file permissions in Linux? Name different types of file systems in
Linux.
Ans: There are three owners in the Linux System i.e., user, group, and others. These owners have
three types of permissions defined as listed below:
Read (r): It allows the user to open and read the file or list the directory.
Write (w): It allows the user to open and modify the file. One can also add new files to the directory.
Execute (x): It allows the user to execute or run the file. One can also lookup a specific file within a
directory.
Ans. To delete files that are two months old on a Linux machine, you can use a combination of the find
command and the rm command. Here's an example command you can use:
84. You need to transfer files securely between two Linux servers. How would
you set up and configure an encrypted SSH connection to ensure secure file
transfers?
Ans. To securely transfer files between two Linux servers, you can set up and configure an encrypted
SSH connection using the Secure Copy (SCP).
$ ssh-copy-id <REMOTE_SERVER>
Ans: The shell to be used in a shell script is defined by the shebang line, which is placed at the
beginning of the script. For example, #!/bin/bash specifies that the Bash shell should be used.
Ans: Arguments can be passed to a shell script using positional parameters. Inside the script, these
arguments can be accessed using variables like $1, $2, etc., where $1 represents the first argument, $2
represents the second argument, and so on.
91. How can you get the number of arguments passed to a shell script?
Ans: The number of arguments passed to a shell script can be obtained using the special variable $#.
For example, echo $# will display the count of arguments.
92. How do you read input from the user within a shell script?
Ans: Input can be read from the user within a shell script using the read command. For example, read
name will prompt the user to enter their name, and the value will be stored in the variable $name.
Ans: The output of a command can be redirected to a file using the > operator. For example, ls >
file.txt will redirect the output of the ls command to the file "file.txt".
Ans: Functions can be defined in a shell script using the function keyword or simply by defining a block
of code.
For example:
function greet {
echo "Hello, $1!"
}
greet "John"
This will output "Hello, John!".
Ans: Errors or exceptions in a shell script can be handled using the trap command to set up a signal
handler. This allows you to catch and handle specific signals or errors. Additionally, you can use
conditional statements like if-else to handle errors based on exit codes or specific condition
Ans: You can check the existence of a directory using the -d flag with the test or [ command. For
example, [ -d directory ] will return true if the directory "directory" exists.
99.How can you pass the output of one command as an argument to another
command?
Ans: The output of one command can be passed as an argument to another command using command
substitution with the $() syntax. For example, command2 $(command1) will pass the output of
command1 as an argument to command2.
101. How can you get the length of a string in a shell script?
Ans: The length of a string can be obtained using the ${#string} syntax. For example, length=${#str} will
store the length of the string str in the variable length.
+91 – 99 85 39 66 77
Ans: You can check if a variable is empty using conditional statements. For example, [ -z "$var" ] will
return true if the variable var is empty.
105. You are troubleshooting a Linux server that is experiencing high CPU usage.
How would you identify the processes consuming the most CPU resources and
take appropriate actions?
106. A Linux server is running out of disk space. How would you identify the
directories or files consuming the most disk space and free up space?
107. You need to schedule a task to run at a specific time every day on a Linux
system. How would you set up a cron job to accomplish this?
108. You want to restrict SSH access to a Linux server only to specific IP
addresses. How would you configure the firewall to allow SSH access from
specific IP ranges?
109. You suspect that a particular process is causing system instability on a Linux
server. How would you trace system calls and monitor the process to gather
diagnostic information?
+91 – 99 85 39 66 77
110. You need to configure a Linux system as a router to enable network traffic
between multiple subnets. How would you set up IP forwarding and configure
the necessary network settings?
111. A Linux server is experiencing slow network performance. How would you
diagnose network-related issues, such as latency or packet loss, and
troubleshoot them?
112. You have accidentally deleted an important file on a Linux system. How
would you attempt to recover the deleted file using command-line tools or
utilities?
113. You want to secure a Linux server by disabling unnecessary services and
closing unused network ports. How would you identify running services and
check for open ports?
114. You need to transfer files securely between two Linux servers. How would
you set up and configure an encrypted SSH connection to ensure secure file
transfers?