1. What is UNIX?
It is a portable operating system that is designed for both efficient multi-tasking and mult-user functions. Its portability allows it to run on different hardware platforms. It was written is C and lets user do processing and control under a shell.
2. What is Shell?
A shell acts as an interface between the user and the system. As a command interpreter, the shell takes commands and sets them up for execution.
3. What are the key features of the Korn Shell?
- history mechanism with built-in editor that simulates emacs or vi
- built-in integer arithmetic
- string manipulation capabilities
- command aliasing
- arrays
- job control
- built-in integer arithmetic
- string manipulation capabilities
- command aliasing
- arrays
- job control
4. What are some common shells and what are their indicators?
sh – Bourne shell
csh – C SHell
bash – Bourne Again Shell
tcsh – enhanced C Shell
zsh – Z SHell
ksh – Korn SHell
csh – C SHell
bash – Bourne Again Shell
tcsh – enhanced C Shell
zsh – Z SHell
ksh – Korn SHell
5. What is shell scripting in UNIX?
Shell scripting is used to program command line of an operating system. Shell Scripting is also used to program the shell which is the base for any operating system. Shell scripts often refer to programming UNIX. Shell scripting is mostly used to program operating systems of windows, UNIX, Apple etc. Also this script is used by companies to develop their own operating system with their own features.
6. What is a typical syntax being followed when issuing commands in shell?
Typical command syntax under the UNIX shell follows the format:
Command [-argument] [-argument] [--argument] [file]
Command [-argument] [-argument] [--argument] [file]
7. What is command substitution?
Command substitution is one of the steps being performed every time commands are processed by the shell. Commands that are enclosed in backquotes are executed by the shell. This will then replace the standard output of the command and displayed on the command line.
8. What is a directory?
Every file is assigned to a directory. A directory is a specialized form of file that maintains a list of all files in it.
9. What is history command in UNIX?
We use history command along with grep command in unix to find any relevant command you have already executed.
10. How do you copy file from one host to other?
By using "scp" command. You can also use rsync command to answer this UNIX interview question or even sftp would be ok.
11. How do you find which process is taking how much CPU?
By using "top" command in UNIX.
12. How do you check how much space left in current drive?
By using "df" command in UNIX. For example "df -h ." will list how full your current drive is.
13. How do you know if a remote host is alive or not?
You can check these by using either ping or telnet command in UNIX.
14. How will you run a process in background? How will you bring that into foreground and how will you kill that process?
For running a process in background use "&" in command line. For bringing it back in foreground use command "fg jobid" and for getting job id you use command "jobs", for killing that process find PID and use kill -9 PID command.
15. How will you find which operating system your system is running on in UNIX?
By using command "uname -a" in UNIX
16. What is the command to list all the links from a directory?
You can answer command like: ls -lrt | grep "^l"
17. How will you create a read-only file in your home directory?
You need to create a file and change its parameter to read-only by using chmod command you can also change your umask to create read only file.
touch file
chmod 400 file
touch file
chmod 400 file
18. What is the difference between Swapping and Paging?
Swapping:Whole process is moved from the swap device to the main memory for execution. Process size must be less than or equal to the available main memory. It is easier to implementation and overhead to the system. Swapping systems does not handle the memory more flexibly as compared to the paging systems.
Paging:Only the required memory pages are moved to main memory from the swap device for execution. Process size does not matter. Gives the concept of the virtual memory. It provides greater flexibility in mapping the virtual address space into the physical memory of the machine. Allows more number of processes to fit in the main memory simultaneously. Allows the greater process size than the available physical memory. Demand paging systems handle the memory more flexibly.
Paging:Only the required memory pages are moved to main memory from the swap device for execution. Process size does not matter. Gives the concept of the virtual memory. It provides greater flexibility in mapping the virtual address space into the physical memory of the machine. Allows more number of processes to fit in the main memory simultaneously. Allows the greater process size than the available physical memory. Demand paging systems handle the memory more flexibly.
19. What are filters?
The term Filter is often used to refer to any program that can take input from standard input, perform some operation on that input, and write the results to standard output. A Filter is also any program that can be used between two other programs in a pipeline.
20. Differentiate multiuser from multitask.
Multiuser means that more than one person can use the computer at the same time. Multitask means that even a single user can have the computer work on more than one task or program at the same time.
21. What is inode?
An inode is an entry created on a section of the disk set aside for a file system. The inode contains nearly all there is to know about a file, which includes the location on the disk where the file starts, the size of the file, when the file was last used, when the file was last changed, what the various read, write and execute permissions are, who owns the file, and other information
- How do you find out what’s your shell? – echo $SHELL
- What’s the command to find out today’s date? – date
- What’s the command to find out users on the system? – who
- How do you find out the current directory you’re in? – pwd
- How do you remove a file? – rm
- How do you remove a – rm -rf
- How do you find out your own username? – whoami
- How do you send a mail message to somebody? – mail somebody@techinterviews.com -s ‘Your subject’ -c ‘cc@techinterviews.com‘
- How do you count words, lines and characters in a file? – wc
- How do you search for a string inside a given file? – grep string filename
- How do you search for a string inside a directory? – grep string *
- How do you search for a string in a directory with the subdirectories recursed? – grep -r string *
- What are PIDs? – They are process IDs given to processes. A PID can vary from 0 to 65535.
- How do you list currently running process? – ps
- How do you stop a process? – kill pid
- How do you find out about all running processes? – ps -ag
- How do you stop all the processes, except the shell window? – kill 0
- How do you fire a process in the background? – ./process-name &
- How do you refer to the arguments passed to a shell script? – $1, $2 and so on. $0 is your script name.
- What’s the conditional statement in shell scripting? – if {condition} then … fi
- How do you do number comparison in shell scripts? – -eq, -ne, -lt, -le, -gt, -ge
- How do you test for file properties in shell scripts? – -s filename tells you if the file is not empty, -f filename tells you whether the argument is a file, and not a directory, -d filename tests if the argument is a directory, and not a file, -w filename tests for writeability, -r filename tests for readability, -x filename tests for executability
- How do you do Boolean logic operators in shell scripting? – ! tests for logical not, -a tests for logical and, and -o tests for logical or.
- How do you find out the number of arguments passed to the shell script? – $#
- What’s a way to do multilevel if-else’s in shell scripting? – if {condition} then {statement} elif {condition} {statement} fi
- How do you write a for loop in shell? – for {variable name} in {list} do {statement} done
- How do you write a while loop in shell? – while {condition} do {statement} done
- How does a case statement look in shell scripts? – case {variable} in {possible-value-1}) {statement};; {possible-value-2}) {statement};; esac
- How do you read keyboard input in shell scripts? – read {variable-name}
- How do you define a function in a shell script? – function-name() { #some code here return }
- How does getopts command work? – The parameters to your script can be passed as -n 15 -x 20. Inside the script, you can iterate through the getopts array as while getopts n:x option, and the variable $option contains the value of the entered option.
- How do you find out what’s your shell? - echo $SHELL
- How do you fire a process in the background? - ./process-name &
- How do you refer to the arguments passed to a shell script? - $1, $2 and so on. $0 is your script name.
- What’s the conditional statement in shell scripting? - if then … fi
- How do you do number comparison in shell scripts? - -eq, -ne, -lt, -le, -gt, -ge
- How do you test for file properties in shell scripts? - -s filename tells you if the file is not empty, -f file…
- How do you do Boolean logic operators in shell scripting? - ! tests for logical not, -a tests for logical and, and …
- How do you find out the number of arguments passed to the shell script? - $#
- What’s a way to do multilevel if-else’s in shell scripting? - if then elif fi
- How do you write a for loop in shell? – for in do done\
- How do you write a while loop in shell? – while do done
- How does a case statement look in shell scripts? - case in ) ;; ) ;; esac
- How do you read keyboard input in shell scripts? - read
- How do you define a function in a shell script? - function-name()
- How do you stop all the processes, except the shell window? - kill 0
- How do you find out about all running processes? - ps -ag
- How do you stop a process? - kill pid
- What’s the command to find out today’s date? – date
- What’s the command to find out users on the system? - who
- How do you find out the current directory you’re in? – pwd
- How do you remove a file? - rm
- How do you remove recursively? – rm -rf
- How do you find out your own username? – whoami
- How do you send a mail message to somebody? – mail somebody@interviewduniya.com -s ‘Your subject’ -c …
- How do you count words, lines and characters in a file? - wc
- How do you search for a string inside a given file? – grep string filename
- How do you search for a string inside a directory? – grep string *
- How do you search for a string in a directory with the subdirectories recursed? - grep -r string *
- What are PIDs? - They are process IDs given to processes. A PID can vary…
- How do you list currently running process? – ps