Unix/Linux Interview Questions and Answers

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.

Post comment
Cancel
Thanks for your comment.!
Write a comment(Click here) ...

What is Unix operating system?

UNIX is a powerful multitasking, multiuser computer Operating System initially developed by Ken Thompson, Dennis Ritchie at AT&T Bell laboratories in 1970.

What is a shell in Unix?

The shell is the Unix command line interpreter. It provides an interface between the user and the kernel and executes programs called commands.

What are the different types of shells available in unix?

There are following different Shells in unix operating system:

Bsh- Bourne shell, It is developed by Stephen Bourne.
ksh – This is called as Korn shell. This is developed by David Korn.
Bash- Bourne Again shell, It is most used for shell scripting in Unix operating system.
csh – This is also called as C-shell

What is Shell Script in unix

A shell script is a list of commands in a computer program that is run by the Unix shell which is a command line interpreter.

Example:

$cat testHello.sh
#!/bin/sh
echo "-------------" 
echo Hello World  
$./testHello.sh
-------------
Hello World 

What are different ways to create a file in Unix?

There are multiple ways to create a file in Unix-
cat command
$cat file.txt

touch command
$touch file.txt

echo and printf command
$echo 'New file.' > file.txt
$printf 'New file. ' > file.txt

Using Vi,emacs text editors
$vi file.txt

How to delete a file in Unix?

rm command is used to delete file

To delete a file
$rm file.txt

To delete a file with confirmation
$rm -i file.txt

To deletes a file forcefully
$ rm -f file.txt

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

rm command to delete the specified files and directories.

To delete all files and subdirectories in the current directory
$rm -rf *

To delete the files with name
$rm file1.txt file2.txt file3.txt

What is a pipe and give an example?

Unix commands alone are powerful, but when you combine them together. The symbol | is the Unix pipe symbol that is used in command line to combine them together.

The output of the command to the left of the pipe gets sent as input of the command to the right of the pipe.

Example:

$cat apple.txt | wc
ls - | grep "page" | wc -l

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. "More" command is like a pager which displays the contents page by page.

$cat bigfile.txt
$more bigfile.txt
$cat bigfile.txt | more

How to create and remove directory in Unix?

You make a new directory via mkdir newdirectoryname ,and can remove a directory using rmdir directoryname. To remove a directory, you must first remove all the files it contains.

$mkdir Directory_name
$rmdir Directory_name

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.

What is inode?

An inode is a unique entry which by default gets created on a disk section for a file system. It contains the following information:

Location on the disk
User of the file
Size of the file
Group of the file
Device ID
File size
Date of creation
Permission
Owner of the file

ls and stat command used to display the inode numbers of the files-
$ls -i file.txt
$stat file.txt

What is relative path and absolute path?

Absolute path : Exact path from root directory.
Relative path : Relative to the current path.

What are some basic UNIX commands?

Some basic Unix commands -
man – view manual pages for Unix commands
clear – clear screen
date – show current date and time
cal - shows a calendar of the current month
whoami – show your username
who – find out who is logged into the system
cd – change directory
pwd – show current directory
mkdir – make new directory
rmdir – remove directory
cat – create file and show contents to the standard output
more – basic pagination when viewing text files
less – improved pagination tool for viewing text files
ls – list files and directories
cp – copy files
rm – remove files and directories
mv – rename or move files and directories to another location
head – show the specified lines from first line of text file
tail – show the specified lines from last lines of text file
wc - tells you how many lines, words, and characters are in a file
grep – search for patterns in text files
chmod – change file/directory access permissions
chown – change file/directory ownership
ps – list processes
top – show tasks and system status
kill – kill a process (stop application running)
gzip - compresses files
gunzip- uncompresses files
du - shows the disk usage of the files and directories

What is du command do?

du command is short for disk usage, with the help of this command you can find the disk capacity and free space of the disk.

$du -h /home/demo/dict

Output:
44K /home/demo/dict/data
2.0M /home/demo/dict/system design
28K /home/demo/dict/table/sample_table
32K /home/demo/dict/table
98M /home/demo/dict

What will the following command do?
$echo *

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

What is the use of "grep" command?

grep (Global Regular Expression Print) is a pattern search command.
It searches for the pattern, specified in the command line with appropriate option, in a given file(s).
Syntax : grep [options] pattern [files]
Example :
$grep 99mx mcafile
$grep “coml” file.txt
$grep “me” file1.txt file2.txt file3.txt
$grep “me” *

$grep -i "Search" Filename --to use the option -i for case insensitive search

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

How will you find the 99th line of a file?

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

$ tail +99 test.txt|head -1

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
$grep -c 'me' file.txt for count the number of lines which is having that specific string

Which command is used to apply permission to a file?

“chmod” command which stands for “change mode” is used to add, remove, or modify file or directory permissions.

Ex-
$chmod 477 file.txt
provides Read Permission to User, Read/Write/Execute Permissions to Group & Others.
$chmod 777 file.txt
provides full read write and execute permission (code=7) to all the group.

$ls -l *
-rw-r--r-- 1 users 777 Dec 18 lookup.icn
-rwxr-x--x 1 users 562 Jan 10 hello
drwxr-xr--- 1 users 1024 Nov 2 mydir

- rw- r-- r--
type of file owner group others
the first character specifies the file type either a ‘-‘ means it’s a file, or a ‘d’ means it’s a directory.

Number Octal Permission Representation Ref Binary
0 No permission --- 000
1 Execute permission --x 001
2 Write permission -w- 010
3 Execute and write permission: 1 (execute) + 2 (write) = 3 -wx 011
4 Read permission r-- 100
5 Read and execute permission: 4 (read) + 1 (execute) = 5 r-x 101
6 Read and write permission: 4 (read) + 2 (write) = 6 rw- 110
7 All permissions: 4 (read) + 2 (write) + 1 (execute) = 7 rwx 111

How to find the latest file?

To get the latest file or directory in the current working directory

$ls -lrt |tail -1  

-t switch sorts the listing by 'time' so the output is displayed from newest to oldest, -r switch reverses so the newest file is at the end of the listing, And -l gives you the long listing.

Latest Updates

Articles

Choose appropriate article for the given sentence:
__________ teachers had ________ late lunch as their meeting lasted longer than___ hour.

Child Development & Pedagogy

Which of the following is the most effective way to create interest for learning in a student?

The rules of presenting the content to make them easy are called_________?

The term SLD in children’s mental health denotes for?

The child will be able to use proper sentences by the age of?

Indian Politics

______is an institutional mechanism to provide representation to the states of India?

Books and Authors

Which text is not written by Kalidasa?

Indian Constitution

Which Constitutional Amendment introduced Right to Education as a Fundamental Right?

Indian History

Which animal is engraved on Harappan seals?

Indian Politics

Who is known for initiating electoral reforms in India to ensure free and fair elections?

Indian Constitution

The sequence in which the given terms are mentioned in the preamble to the Constitution of India is?

Which of the following parts of the Constitution of India provides fundamental rights ?

Books and Authors

Who among the following is the author of ‘Politics’?

Which one is the text not written by Abul Fazl?

Which King was the author of Ratnawali, Nagananda, Priyadarsika?

Fill in the blank

Fill in the blanks with the most appropriate preposition in the given sentence.
The class begins _______ 7:30 am _____ the morning.

The workers were so skilled that their _____ was quite visible even to a layman.

Articles

Choose appropriate article for the given sentence:
______ German is ___ easy language to learn for English speaking students.

Latest Job Notifications

Banking Jobs

बैंकिंग कार्मिक चयन संस्थान Institute of Banking Personnel Selection(IBPS) - 7855 पद - 29/07/2022 अंतिम तिथि

SSC Recruitment

कर्मचारी चयन आयोग (एसएससी) Staff Selection Commission (SSC) - 1411 पद - 29/07/2022 अंतिम तिथि

Jobs in Rajasthan

राजस्थान अधीनस्थ और मंत्रिस्तरीय सेवा चयन बोर्ड Rajasthan Subordinate and Ministerial Services Selection Board (RSMSSB) - 5546 पद - 22-Jul-2022 अंतिम तिथि

Railway Recruitment

उत्तर मध्य रेलवे भर्ती प्रकोष्ठ Railway Recruitment Cell(NCR) - 1659 पद - 01/08/2022 अंतिम तिथि

Jobs in West Bengal

इंडियन पोस्ट सर्विस Indian Post Service - 2357 पद - 19/08/2021 अंतिम तिथि - पश्चिम बंगाल पोस्टल सर्कल

Banking Jobs

भारतीय स्टेट बैंक State Bank of India(SBI) - 6100 पद - 26/07/2021 अंतिम तिथि - CRPD/APPR/2021-22/10

SSC Recruitment

कर्मचारी चयन आयोग Staff Selection Commission(SSC) - 25271 पद - 31/08/2021 अंतिम तिथि

Jobs in Madhya Pradesh

राष्ट्रीय स्वास्थ्य मिशन मध्य प्रदेश National Health Mission MP(NRHM) - 5215 पद - 22/06/2021 अंतिम तिथि

Jobs in Punjab

पंजाब स्टेट पावर कॉर्पोरेशन लिमिटेड Punjab State Power Corporation Limited (PSPCL) - 2632 पद - 20/06/2021 अंतिम तिथि

Jobs in Chhattisgarh

स्वास्थ्य सेवा निदेशालय, छत्तीसगढ़ Department of Health & Family Welfare, Chhattisgarh - 267 पद - 26/06/2021 अंतिम तिथि