Unix/Linux Interview Questions and Answers

What is relative path and absolute path?
Absolute path : Exact path from root directory. Relative path : Relative to the current path.
How to count number char, line in a file?
by using wc-stands for word count. wc -c for counting number of characters in a file. wc -l for counting lines in a file.
What is du command do?

With the help of this command you can find the disk capacity and free space of the disk.

What is the use of the command 'ls -x chapter[1-5]'?
ls stands for list; so it displays the list of the files that starts with 'chapter' with suffix '1' to '5', chapter1, chapter2, and so on.

What will the following command do?
$echo *

It is similar to 'ls' command and displays all the files in the current directory.

Which command is used to delete all files in the current directory and all its sub-directories?
rm -r *

What is the use of "grep" command?
"grep" is a pattern search command. It searches for the pattern, specified in the command line with appropriate option, in a file(s). Example : grep 99mx mcafile
What is a pipe and give an example?
Unix commands alone are powerful, but when you combine them together, you can accomplish complex tasks with ease. The way you combine Unix commands is through using pipes and filters. The symbol | is the Unix pipe symbol that is used on the command line. What it means is that the standard output of the command to the left of the pipe gets sent as standard input of the command to the right of the pipe. However, the pipe is different because it is used to pass the output of a command to another command- example: $ cat apple.txt | wc
What is the difference between cat and more command?
"Cat" displays file contents. If the file is large the contents scroll off the screen before we view it. So command "more" is like a pager which displays the contents page by page.

How do display the 10th, 11th and 12th line of a file in Unix?

Combining the two commands head and tail can give you the result -

$ head -12 <filename> | tail -3
Ex -

$ head -12 test.txt | tail -3

What is nohup command in unix?

Nohup stands for no hang up. It is a Unix command that is used to run another command. It tells Unix not to stop passed command once it has started, that will keep running until done.
When you execute a Unix job in the background( &, bg command), and logout from the session, then that process will get killed. It can avoid this by executing the job with nohup.
Nohup prevents the command from being aborted automatically when you log out or exit the shell.

# nohup sample.sh &

By default, standard output will be redirected to nohup.out file in the current directory. You can also redirect the output to an other file using the normal shell redirection.

# nohup sh sample.sh > sample-out.log &

Once a job is started or executed using the nohup command, stdin will not be available to the user.

Latest Updates