SlideShare a Scribd company logo
1 of 18
Download to read offline
3/26/2015 UNIX INTERVIEW QUESTIONS
data:text/html;charset=utf-8,%3Cdiv%20class%3D%22article-header%22%20style%3D%22margin%3A%200px%3B%20outlin… 1/18
Awk is powerful tool in Unix. Awk is an excellent tool for processing the files which have data arranged in
rows and columns format. It is a good filter and report writer. 
1. How to run awk command specified in a file?
awk ­f filename
2. Write a command to print the squares of numbers from 1 to 10 using awk command
awk 'BEGIN { for(i=1;i<=10;i++) {print "square of",i,"is",i*i;}}'
3. Write a command to find the sum of bytes (size of file) of all files in a directory.
ls ­l | awk 'BEGIN {sum=0} {sum = sum + $5} END {print sum}'
4. In the text file, some lines are delimited by colon and some are delimited by space. Write a command to
print the third field of each line.
awk '{ if( $0 ~ /:/ ) { FS=":"; } else { FS =" "; } print $3 }' filename
5. Write a command to print the line number before each line?
awk '{print NR, $0}' filename
6. Write a command to print the second and third line of a file without using NR.
awk 'BEGIN {RS="";FS="n"} {print $2,$3}' filename
7. Write a command to print zero byte size files?
ls ­l | awk '/^­/ {if ($5 !=0 ) print $9 }'
8. Write a command to rename the files in a directory with "_new" as postfix?
ls ­F | awk '{print "mv "$1" "$1".new"}' | sh
9. Write a command to print the fields in a text file in reverse order?
awk 'BEGIN {ORS=""} { for(i=NF;i>0;i­­) print $i," "; print "n"}' filename
10. Write a command to find the total number of lines in a file without using NR
awk 'BEGIN {sum=0} {sum=sum+1} END {print sum}' filename
Another way to print the number of lines is by using the NR. The command is
awk 'END{print NR}' filename
The grep is one of the powerful tools in unix. Grep stands for "global search for regular expressions and
print". The power of grep lies in using regular expressions mostly.
UNIX INTERVIEW QUESTIONS
UNIX INTERVIEW QUESTIONS ON AWK COMMAND
UNIX INTERVIEW QUESTIONS ON GREP COMMAND
3/26/2015 UNIX INTERVIEW QUESTIONS
data:text/html;charset=utf-8,%3Cdiv%20class%3D%22article-header%22%20style%3D%22margin%3A%200px%3B%20outlin… 2/18
The general syntax of grep command is
grep [options] pattern [files]
1. Write a command to print the lines that has the the pattern "july" in all the files in a particular directory?
grep july *
This will print all the lines in all files that contain the word “july” along with the file name. If any of the files
contain words like "JULY" or "July", the above command would not print those lines.
2. Write a command to print the lines that has the word "july" in all the files in a directory and also
suppress the filename in the output.
grep ­h july *
3. Write a command to print the lines that has the word "july" while ignoring the case.
grep ­i july *
The option i make the grep command to treat the pattern as case insensitive.
4. When you use a single file as input to the grep command to search for a pattern, it won't print the
filename in the output. Now write a grep command to print the filename in the output without using the '­H'
option.
grep pattern filename /dev/null
The /dev/null or null device is special file that discards the data written to it. So, the /dev/null is always an
empty file.
Another way to print the filename is using the '­H' option. The grep command for this is
grep ­H pattern filename
5. Write a Unix command to display the lines in a file that do not contain the word "july"?
grep ­v july filename
The '­v' option tells the grep to print the lines that do not contain the specified pattern.
6. Write a command to print the file names in a directory that has the word "july"?
grep ­l july *
The '­l' option make the grep command to print only the filename without printing the content of the file. As
soon as the grep command finds the pattern in a file, it prints the pattern and stops searching other lines
in the file.
7. Write a command to print the file names in a directory that does not contain the word "july"?
grep ­L july *
The '­L' option makes the grep command to print the filenames that do not contain the specified pattern.
8. Write a command to print the line numbers along with the line that has the word "july"?
grep ­n july filename
The '­n' option is used to print the line numbers in a file. The line numbers start from 1
9. Write a command to print the lines that starts with the word "start"?
grep '^start' filename
The '^' symbol specifies the grep command to search for the pattern at the start of the line.
3/26/2015 UNIX INTERVIEW QUESTIONS
data:text/html;charset=utf-8,%3Cdiv%20class%3D%22article-header%22%20style%3D%22margin%3A%200px%3B%20outlin… 3/18
10. Write a command to print the lines which end with the word "end"?
grep 'end$' filename
The '$' symbol specifies the grep command to search for the pattern at the end of the line.
11. Write a command to select only those lines containing "july" as a whole word?
grep ­w july filename
The '­w' option makes the grep command to search for exact whole words. If the specified pattern is found
in a string, then it is not considered as a whole word. For example: In the string "mikejulymak", the pattern
"july" is found. However "july" is not a whole word in that string.
UNIX INTERVIEW QUESTIONS ON SED COMMAND
SED is a special editor used for modifying files automatically.
1. Write a command to replace the word "bad" with "good" in file?
sed s/bad/good/ < filename
2. Write a command to replace the word "bad" with "good" globally in a file?
sed s/bad/good/g < filename
3. Write a command to replace the character '/' with ',' in a file?
sed 's///,/' < filename
sed 's|/|,|' < filename
4. Write a command to replace the word "apple" with "(apple)" in a file?
sed s/apple/(&)/ < filename
5. Write a command to switch the two consecutive words "apple" and "mango" in a file?
sed 's/(apple) (mango)/2 1/' < filename
6. Write a command to replace the second occurrence of the word "bat" with "ball" in a file?
sed 's/bat/ball/2' < filename
7. Write a command to remove all the occurrences of the word "jhon" except the first one in
a line with in the entire file?
sed 's/jhon//2g' < filename
8. Write a command to remove the first number on line 5 in file?
sed '5 s/[0­9][0­9]*//' < filename
9. Write a command to remove the first number on all lines that start with "@"?
sed ',^@, s/[0­9][0­9]*//' < filename
10. Write a command to replace the word "gum" with "drum" in the first 100 lines of a file?
sed '1,00 s/gum/drum/' < filename
11. write a command to replace the word "lite" with "light" from 100th line to last line in a
file?
sed '100,$ s/lite/light/' < filename
3/26/2015 UNIX INTERVIEW QUESTIONS
data:text/html;charset=utf-8,%3Cdiv%20class%3D%22article-header%22%20style%3D%22margin%3A%200px%3B%20outlin… 4/18
12. Write a command to remove the first 10 lines from a file?
sed '1,10 d' < filename
13. Write a command to duplicate each line in a file?
sed 'p' < filename
14. Write a command to duplicate empty lines in a file?
sed '/^$/ p' < filename
15. Write a sed command to print the lines that do not contain the word "run"?
sed ­n '/run/!p' < filename
UNIX INTERVIEW QUESTIONS ON CUT COMMAND
The cut command is used to used to display selected columns or fields from each line of a
file. Cut command works in two modes:
Delimited selection: The fields in the line are delimited by a single character like
blank,comma etc.
Range selection: Each field starts with certain fixed offset defined as range.
1. Write a command to display the third and fourth character from each line of a file?
cut ­c 3,4 filename
2. Write a command to display the characters from 10 to 20 from each line of a file?
cut ­c 10­20 filename
3. Write a command to display the first 10 characters from each line of a file?
cut ­c ­10 filename
4. Write a comamnd to display from the 10th character to the end of the line?
cut ­c 10­ filename
5. The fields in each line are delimited by comma. Write a command to display third field
from each line of a file?
cut ­d',' ­f2 filename
6. Write a command to print the fields from 10 to 20 from each line of a file?
cut ­d',' ­f10­20 filename
7. Write a command to print the first 5 fields from each line?
cut ­d',' ­f­5 filename
8. Write a command to print the fields from 10th to the end of the line?
cut ­d',' ­f10­ filename
9. By default the cut command displays the entire line if there is no delimiter in it. Which cut
option is used to supress these kind of lines?
The ­s option is used to supress the lines that do not contain the delimiter.
10. Write a cut command to extract the username from 'who am i' comamnd?
3/26/2015 UNIX INTERVIEW QUESTIONS
data:text/html;charset=utf-8,%3Cdiv%20class%3D%22article-header%22%20style%3D%22margin%3A%200px%3B%20outlin… 5/18
who am i | cut ­f1 ­d' '
UNIX INTERVIEW QUESTIONS ON FIND COMMAND
Find utility is used for searching files using the directory information.
1. Write a command to search for the file 'test' in the current directory?
find ­name test ­type f
2. Write a command to search for the file 'temp' in '/usr' directory?
find /usr ­name temp ­type f
3. Write a command to search for zero byte size files in the current directory?
find ­size 0 ­type f
4. Write a command to list the files that are accessed 5 days ago in the current directory?
find ­atime 5 ­type f
5. Write a command to list the files that were modified 5 days ago in the current directory?
find ­mtime 5 ­type f
6. Write a command to search for the files in the current directory which are not owned by
any user in the /etc/passwd file?
find . ­nouser ­type f
7. Write a command to search for the files in '/usr' directory that start with 'te'?
find /usr ­name 'te*' ­type f
8. Write a command to search for the files that start with 'te' in the current directory and
then display the contents of the file?
find . ­name 'te*' ­type f ­exec cat {} ;
9. Write a command to list the files whose status is changed 5 days ago in the current
directory?
find ­ctime 5 ­type f
10. Write a command to list the files in '/usr' directory that start with 'ch' and then display the
number of lines in each file?
find /usr ­name 'ch*' ­type f ­exec wc ­l {} ;
TOP UNIX INTERVIEW QUESTIONS ­ PART 1
1. How to display the 10th line of a file?
head -10 filename | tail -1
2. How to remove the header from a file?
3/26/2015 UNIX INTERVIEW QUESTIONS
data:text/html;charset=utf-8,%3Cdiv%20class%3D%22article-header%22%20style%3D%22margin%3A%200px%3B%20outlin… 6/18
sed -i '1 d' filename
3. How to remove the footer from a file?
sed -i '$ d' filename
4. Write a command to find the length of a line in a file?
The below command can be used to get a line from a file.
sed –n '<n> p' filename
We will see how to find the length of 10th line in a file
sed -n '10 p' filename|wc -c
5. How to get the nth word of a line in Unix?
cut –f<n> -d' '
6. How to reverse a string in unix?
echo "java" | rev
7. How to get the last word from a line in Unix file?
echo "unix is good" | rev | cut -f1 -d' ' | rev
8. How to replace the n­th line in a file with a new line in Unix?
sed -i'' '10 d' filename # d stands for delete
sed -i'' '10 i new inserted line' filename # i stands for insert
9. How to check if the last command was successful in Unix?
3/26/2015 UNIX INTERVIEW QUESTIONS
data:text/html;charset=utf-8,%3Cdiv%20class%3D%22article-header%22%20style%3D%22margin%3A%200px%3B%20outlin… 7/18
echo $?
10. Write command to list all the links from a directory?
ls -lrt | grep "^l"
11. How will you find which operating system your system is running on in UNIX?
uname -a
12. Create a read­only file in your home directory?
touch file; chmod 400 file
13. How do you see command line history in UNIX?
The 'history' command can be used to get the list of commands that we are executed.
14. How to display the first 20 lines of a file?
By default, the head command displays the first 10 lines from a file. If we change the option
of head, then we can display as many lines as we want.
head -20 filename
An alternative solution is using the sed command
sed '21,$ d' filename
The d option here deletes the lines from 21 to the end of the file
15. Write a command to print the last line of a file?
The tail command can be used to display the last lines from a file.
tail -1 filename
Alternative solutions are:
3/26/2015 UNIX INTERVIEW QUESTIONS
data:text/html;charset=utf-8,%3Cdiv%20class%3D%22article-header%22%20style%3D%22margin%3A%200px%3B%20outlin… 8/18
sed -n '$ p' filename
awk 'END{print $0}' filename
TOP UNIX INTERVIEW QUESTIONS ­ PART 2
1. How do you rename the files in a directory with _new as suffix?
ls -lrt|grep '^-'| awk '{print "mv "$9" "$9".new"}' | sh
2. Write a command to convert a string from lower case to upper case?
echo "apple" | tr [a-z] [A-Z]
3. Write a command to convert a string to Initcap.
echo apple | awk '{print toupper(substr($1,1,1)) tolower(substr($1,2))}'
4. Write a command to redirect the output of date command to multiple files?
The tee command writes the output to multiple files and also displays the output on the
terminal.
date | tee -a file1 file2 file3
5. How do you list the hidden files in current directory?
ls -a | grep '^.'
6. List out some of the Hot Keys available in bash shell? 
Ctrl+l ­ Clears the Screen.
Ctrl+r ­ Does a search in previously given commands in shell.
Ctrl+u ­ Clears the typing before the hotkey.
Ctrl+a ­ Places cursor at the beginning of the command at shell.
Ctrl+e ­ Places cursor at the end of the command at shell.
Ctrl+d ­ Kills the shell.
Ctrl+z ­ Places the currently running process into background.
3/26/2015 UNIX INTERVIEW QUESTIONS
data:text/html;charset=utf-8,%3Cdiv%20class%3D%22article-header%22%20style%3D%22margin%3A%200px%3B%20outlin… 9/18
7. How do you make an existing file empty?
cat /dev/null >  filename
8. How do you remove the first number on 10th line in file?
sed '10 s/[0-9][0-9]*//' < filename
9. What is the difference between join ­v and join ­a?
join -v : outputs only matched lines between two files.
join -a : In addition to the matched lines, this will output unmatched lines also.
10. How do you display from the 5th character to the end of the line from a file?
cut -c 5- filename
TOP UNIX INTERVIEW QUESTIONS ­ PART 3
1. Display all the files in current directory sorted by size?
ls -l | grep '^-' | awk '{print $5,$9}' |sort -n|awk '{print $2}'
2. Write a command to search for the file 'map' in the current directory?
find -name map -type f
3. How to display the first 10 characters from each line of a file?
cut -c -10 filename
4. Write a command to remove the first number on all lines that start with "@"?
sed ',^@, s/[0-9][0-9]*//' < filename
3/26/2015 UNIX INTERVIEW QUESTIONS
data:text/html;charset=utf-8,%3Cdiv%20class%3D%22article-header%22%20style%3D%22margin%3A%200px%3B%20outli… 10/18
5. How to print the file names in a directory that has the word "term"?
grep -l term *
The '­l' option make the grep command to print only the filename without printing the
content of the file. As soon as the grep command finds the pattern in a file, it prints the
pattern and stops searching other lines in the file.
6. How to run awk command specified in a file?
awk -f filename
7. How do you display the calendar for the month march in the year 1985?
The cal command can be used to display the current month calendar. You can pass the
month and year as arguments to display the required year, month combination calendar.
cal 03 1985
This will display the calendar for the March month and year 1985.
8. Write a command to find the total number of lines in a file?
wc -l filename
Other ways to print the total number of lines are
awk 'BEGIN {sum=0} {sum=sum+1} END {print sum}' filename
awk 'END{print NR}' filename
9. How to duplicate empty lines in a file?
sed '/^$/ p' < filename
10. Explain iostat, vmstat and netstat?
Iostat: reports on terminal, disk and tape I/O activity.
Vmstat: reports on virtual memory statistics for processes, disk, tape and CPU
activity.
3/26/2015 UNIX INTERVIEW QUESTIONS
data:text/html;charset=utf-8,%3Cdiv%20class%3D%22article-header%22%20style%3D%22margin%3A%200px%3B%20outli… 11/18
1. How do you write the contents of 3 files into a single file?
cat file1 file2 file3 > file
2. How to display the fields in a text file in reverse order?
awk 'BEGIN {ORS=""} { for(i=NF;i>0;i--) print $i," "; print "n"}' filename
3. Write a command to find the sum of bytes (size of file) of all files in a directory.
ls -l | grep '^-'| awk 'BEGIN {sum=0} {sum = sum + $5} END {print sum}'
4. Write a command to print the lines which end with the word "end"?
grep 'end$' filename
The '$' symbol specifies the grep command to search for the pattern at the end of the line.
5. Write a command to select only those lines containing "july" as a whole word?
grep -w july filename
The '­w' option makes the grep command to search for exact whole words. If the specified pattern is found
in a string, then it is not considered as a whole word. For example: In the string "mikejulymak", the pattern
"july" is found. However "july" is not a whole word in that string.
6. How to remove the first 10 lines from a file?
sed '1,10 d' < filename
7. Write a command to duplicate each line in a file?
sed 'p' < filename
Netstat: reports on the contents of network data structures.
TOP UNIX INTERVIEW QUESTIONS ­ PART 4
3/26/2015 UNIX INTERVIEW QUESTIONS
data:text/html;charset=utf-8,%3Cdiv%20class%3D%22article-header%22%20style%3D%22margin%3A%200px%3B%20outli… 12/18
8. How to extract the username from 'who am i' comamnd?
who am i | cut -f1 -d' '
9. Write a command to list the files in '/usr' directory that start with 'ch' and then display the number of
lines in each file?
wc -l /usr/ch*
Another way is 
find /usr -name 'ch*' -type f -exec wc -l {} ;
10. How to remove blank lines in a file ?
grep -v ‘^$’ filename > new_filename
1. How to display the processes that were run by your user name ?
ps -aef | grep <user_name>
2. Write a command to display all the files recursively with path under current directory?
find . -depth -print
3. Display zero byte size files in the current directory?
find -size 0 -type f
4. Write a command to display the third and fifth character from each line of a file?
cut -c 3,5 filename
TOP UNIX INTERVIEW QUESTIONS ­ PART 5
3/26/2015 UNIX INTERVIEW QUESTIONS
data:text/html;charset=utf-8,%3Cdiv%20class%3D%22article-header%22%20style%3D%22margin%3A%200px%3B%20outli… 13/18
5. Write a command to print the fields from 10th to the end of the line. The fields in the line are delimited
by a comma?
cut -d',' -f10- filename
6. How to replace the word "Gun" with "Pen" in the first 100 lines of a file?
sed '1,00 s/Gun/Pen/' < filename
7. Write a Unix command to display the lines in a file that do not contain the word "RAM"?
grep -v RAM filename
The '­v' option tells the grep to print the lines that do not contain the specified pattern.
8. How to print the squares of numbers from 1 to 10 using awk command
awk 'BEGIN { for(i=1;i<=10;i++) {print "square of",i,"is",i*i;}}'
9. Write a command to display the files in the directory by file size?
ls -l | grep '^-' |sort -nr -k 5
10. How to find out the usage of the CPU by the processes?
The top utility can be used to display the CPU usage by the processes.
TOP UNIX INTERVIEW QUESTIONS ­ PART 6
1. Write a command to remove the prefix of the string ending with '/'.
The basename utility deletes any prefix ending in /. The usage is mentioned below:
basename /usr/local/bin/file
This will display only file
2. How to display zero byte size files?
3/26/2015 UNIX INTERVIEW QUESTIONS
data:text/html;charset=utf-8,%3Cdiv%20class%3D%22article-header%22%20style%3D%22margin%3A%200px%3B%20outli… 14/18
ls -l | grep '^-' | awk '/^-/ {if ($5 !=0 ) print $9 }'
3. How to replace the second occurrence of the word "bat" with "ball" in a file?
sed 's/bat/ball/2' < filename
4. How to remove all the occurrences of the word "jhon" except the first one in a line with in
the entire file?
sed 's/jhon//2g' < filename
5. How to replace the word "lite" with "light" from 100th line to last line in a file?
sed '100,$ s/lite/light/' < filename
6. How to list the files that are accessed 5 days ago in the current directory?
find -atime 5 -type f
7. How to list the files that were modified 5 days ago in the current directory?
find -mtime 5 -type f
8. How to list the files whose status is changed 5 days ago in the current directory?
find -ctime 5 -type f
9. How to replace the character '/' with ',' in a file?
sed 's///,/' < filename
sed 's|/|,|' < filename
10. Write a command to find the number of files in a directory.
ls -l|grep '^-'|wc -l
3/26/2015 UNIX INTERVIEW QUESTIONS
data:text/html;charset=utf-8,%3Cdiv%20class%3D%22article-header%22%20style%3D%22margin%3A%200px%3B%20outli… 15/18
TOP UNIX INTERVIEW QUESTIONS ­ PART 7
1. Write a command to display your name 100 times.
The Yes utility can be used to repeatedly output a line with the specified string or 'y'.
yes <your_name> | head -100
2. Write a command to display the first 10 characters from each line of a file?
cut -c -10 filename
3. The fields in each line are delimited by comma. Write a command to display third field
from each line of a file?
cut -d',' -f2 filename
4. Write a command to print the fields from 10 to 20 from each line of a file?
cut -d',' -f10-20 filename
5. Write a command to print the first 5 fields from each line?
cut -d',' -f-5 filename
6. By default the cut command displays the entire line if there is no delimiter in it. Which cut
option is used to suppress these kind of lines?
The ­s option is used to suppress the lines that do not contain the delimiter.
7. Write a command to replace the word "bad" with "good" in file?
sed s/bad/good/ < filename
8. Write a command to replace the word "bad" with "good" globally in a file?
sed s/bad/good/g < filename
3/26/2015 UNIX INTERVIEW QUESTIONS
data:text/html;charset=utf-8,%3Cdiv%20class%3D%22article-header%22%20style%3D%22margin%3A%200px%3B%20outli… 16/18
  
9. Write a command to replace the word "apple" with "(apple)" in a file?
sed s/apple/(&)/ < filename
10. Write a command to switch the two consecutive words "apple" and "mango" in a file?
sed 's/(apple) (mango)/2 1/' < filename
11. Write a command to display the characters from 10 to 20 from each line of a file?
cut -c 10-20 filename
TOP UNIX INTERVIEW QUESTIONS ­ PART 8
1. Write a command to print the lines that has the the pattern "july" in all the files in a
particular directory?
grep july *
This will print all the lines in all files that contain the word “july” along with the file name. If
any of the files contain words like "JULY" or "July", the above command would not print
those lines.
2. Write a command to print the lines that has the word "july" in all the files in a directory
and also suppress the file name in the output.
grep -h july *
3. Write a command to print the lines that has the word "july" while ignoring the case.
grep -i july *
The option i make the grep command to treat the pattern as case insensitive.
4. When you use a single file as input to the grep command to search for a pattern, it won't
print the filename in the output. Now write a grep command to print the file name in the
output without using the '­H' option.
grep pattern file name /dev/null
3/26/2015 UNIX INTERVIEW QUESTIONS
data:text/html;charset=utf-8,%3Cdiv%20class%3D%22article-header%22%20style%3D%22margin%3A%200px%3B%20outli… 17/18
The /dev/null or null device is special file that discards the data written to it. So, the /dev/null
is always an empty file.
Another way to print the file name is using the '­H' option. The grep command for this is
grep -H pattern filename
5. Write a command to print the file names in a directory that does not contain the word
"july"?
grep -L july *
The '­L' option makes the grep command to print the file names that do not contain the
specified pattern.
6. Write a command to print the line numbers along with the line that has the word "july"?
grep -n july filename
The '­n' option is used to print the line numbers in a file. The line numbers start from 1
7. Write a command to print the lines that starts with the word "start"?
grep '^start' filename
The '^' symbol specifies the grep command to search for the pattern at the start of the line.
8. In the text file, some lines are delimited by colon and some are delimited by space. Write
a command to print the third field of each line.
awk '{ if( $0 ~ /:/ ) { FS=":"; } else { FS =" "; } print $3 }' filename
9. Write a command to print the line number before each line?
awk '{print NR, $0}' filename
10. Write a command to print the second and third line of a file without using NR.
3/26/2015 UNIX INTERVIEW QUESTIONS
data:text/html;charset=utf-8,%3Cdiv%20class%3D%22article-header%22%20style%3D%22margin%3A%200px%3B%20outli… 18/18
awk 'BEGIN {RS="";FS="n"} {print $2,$3}' filename
11. How to create an alias for the complex command and remove the alias?
The alias utility is used to create the alias for a command. The below command creates
alias for ps ­aef command.
alias pg='ps -aef'
If you use pg, it will work the same way as ps ­aef.
To remove the alias simply use the unalias command as
unalias pg
12. Write a command to display today's date in the format of 'yyyy­mm­dd'?
The date command can be used to display today's date with time
date '+%Y-%m-%d'

More Related Content

What's hot

Non regular languages
Non regular languagesNon regular languages
Non regular languageslavishka_anuj
 
Translation of expression(copmiler construction)
Translation of expression(copmiler construction)Translation of expression(copmiler construction)
Translation of expression(copmiler construction)IrtazaAfzal3
 
Presentation of awk
Presentation of awkPresentation of awk
Presentation of awkyogesh4589
 
Algorithm chapter 10
Algorithm chapter 10Algorithm chapter 10
Algorithm chapter 10chidabdu
 
Git Aliases of the Gods!
Git Aliases of the Gods!Git Aliases of the Gods!
Git Aliases of the Gods!Atlassian
 
An introduction to Python for absolute beginners
An introduction to Python for absolute beginnersAn introduction to Python for absolute beginners
An introduction to Python for absolute beginnersKálmán "KAMI" Szalai
 
Introduction to Python programming
Introduction to Python programmingIntroduction to Python programming
Introduction to Python programmingDamian T. Gordon
 
Variants of Turing Machine
Variants of Turing MachineVariants of Turing Machine
Variants of Turing MachineRajendran
 
Software Estimation Strategy & Technique
Software Estimation Strategy & TechniqueSoftware Estimation Strategy & Technique
Software Estimation Strategy & TechniquePanji Gautama
 
3.2 javascript regex
3.2 javascript regex3.2 javascript regex
3.2 javascript regexJalpesh Vasa
 
Write microservice in golang
Write microservice in golangWrite microservice in golang
Write microservice in golangBo-Yi Wu
 

What's hot (20)

Shell scripting
Shell scriptingShell scripting
Shell scripting
 
Introduction to LaTeX
Introduction to LaTeXIntroduction to LaTeX
Introduction to LaTeX
 
Non regular languages
Non regular languagesNon regular languages
Non regular languages
 
TOC_Solutions-Adi.pdf
TOC_Solutions-Adi.pdfTOC_Solutions-Adi.pdf
TOC_Solutions-Adi.pdf
 
Translation of expression(copmiler construction)
Translation of expression(copmiler construction)Translation of expression(copmiler construction)
Translation of expression(copmiler construction)
 
Presentation of awk
Presentation of awkPresentation of awk
Presentation of awk
 
Unix commands
Unix commandsUnix commands
Unix commands
 
Algorithm chapter 10
Algorithm chapter 10Algorithm chapter 10
Algorithm chapter 10
 
Git Aliases of the Gods!
Git Aliases of the Gods!Git Aliases of the Gods!
Git Aliases of the Gods!
 
Python Programming Essentials - M9 - String Formatting
Python Programming Essentials - M9 - String FormattingPython Programming Essentials - M9 - String Formatting
Python Programming Essentials - M9 - String Formatting
 
Python programming : Control statements
Python programming : Control statementsPython programming : Control statements
Python programming : Control statements
 
Linux intro 4 awk + makefile
Linux intro 4  awk + makefileLinux intro 4  awk + makefile
Linux intro 4 awk + makefile
 
Huffman codes
Huffman codesHuffman codes
Huffman codes
 
An introduction to Python for absolute beginners
An introduction to Python for absolute beginnersAn introduction to Python for absolute beginners
An introduction to Python for absolute beginners
 
Introduction to Python programming
Introduction to Python programmingIntroduction to Python programming
Introduction to Python programming
 
Variants of Turing Machine
Variants of Turing MachineVariants of Turing Machine
Variants of Turing Machine
 
Software Estimation Strategy & Technique
Software Estimation Strategy & TechniqueSoftware Estimation Strategy & Technique
Software Estimation Strategy & Technique
 
Resumo 2
Resumo 2Resumo 2
Resumo 2
 
3.2 javascript regex
3.2 javascript regex3.2 javascript regex
3.2 javascript regex
 
Write microservice in golang
Write microservice in golangWrite microservice in golang
Write microservice in golang
 

Viewers also liked

Hadoopp0f 150325024427-conversion-gate01
Hadoopp0f 150325024427-conversion-gate01Hadoopp0f 150325024427-conversion-gate01
Hadoopp0f 150325024427-conversion-gate01Kalyan Hadoop
 
Orienit hadoop practical cluster setup screenshots
Orienit hadoop practical cluster setup screenshotsOrienit hadoop practical cluster setup screenshots
Orienit hadoop practical cluster setup screenshotsKalyan Hadoop
 
Hadoop hdfs interview questions
Hadoop hdfs interview questionsHadoop hdfs interview questions
Hadoop hdfs interview questionsKalyan Hadoop
 
Kalyan Hadoop
Kalyan HadoopKalyan Hadoop
Kalyan HadoopCanarys
 
Hadoop interview questions
Hadoop interview questionsHadoop interview questions
Hadoop interview questionsKalyan Hadoop
 
Big data interview questions and answers
Big data interview questions and answersBig data interview questions and answers
Big data interview questions and answersKalyan Hadoop
 
Linux 系統管理與安全:基本 Linux 系統知識
Linux 系統管理與安全:基本 Linux 系統知識Linux 系統管理與安全:基本 Linux 系統知識
Linux 系統管理與安全:基本 Linux 系統知識維泰 蔡
 
配布用Cacti running with cherokee
配布用Cacti running with cherokee配布用Cacti running with cherokee
配布用Cacti running with cherokeeyut148atgmaildotcom
 
Groovy Introduction for Java Programmer
Groovy Introduction for Java ProgrammerGroovy Introduction for Java Programmer
Groovy Introduction for Java ProgrammerLi Ding
 
Cheatsheet: Hex file headers and regex
Cheatsheet: Hex file headers and regexCheatsheet: Hex file headers and regex
Cheatsheet: Hex file headers and regexKasper de Waard
 
Web_DBの監視
Web_DBの監視Web_DBの監視
Web_DBの監視ii012014
 
Nagios的安装部署和与cacti的整合(linuxtone)
Nagios的安装部署和与cacti的整合(linuxtone)Nagios的安装部署和与cacti的整合(linuxtone)
Nagios的安装部署和与cacti的整合(linuxtone)Yiwei Ma
 
Linux 系統管理與安全:系統防駭與資訊安全
Linux 系統管理與安全:系統防駭與資訊安全Linux 系統管理與安全:系統防駭與資訊安全
Linux 系統管理與安全:系統防駭與資訊安全維泰 蔡
 
Tmux quick-reference
Tmux quick-referenceTmux quick-reference
Tmux quick-referenceRamesh Kumar
 
Webサーバ勉強会#5mod sedについて
Webサーバ勉強会#5mod sedについてWebサーバ勉強会#5mod sedについて
Webサーバ勉強会#5mod sedについてyut148atgmaildotcom
 
Sorting techniques in Perl
Sorting techniques in PerlSorting techniques in Perl
Sorting techniques in PerlYogesh Sawant
 

Viewers also liked (20)

Hadoopp0f 150325024427-conversion-gate01
Hadoopp0f 150325024427-conversion-gate01Hadoopp0f 150325024427-conversion-gate01
Hadoopp0f 150325024427-conversion-gate01
 
Orienit hadoop practical cluster setup screenshots
Orienit hadoop practical cluster setup screenshotsOrienit hadoop practical cluster setup screenshots
Orienit hadoop practical cluster setup screenshots
 
Hadoop hdfs interview questions
Hadoop hdfs interview questionsHadoop hdfs interview questions
Hadoop hdfs interview questions
 
Kalyan Hadoop
Kalyan HadoopKalyan Hadoop
Kalyan Hadoop
 
Hadoop interview questions
Hadoop interview questionsHadoop interview questions
Hadoop interview questions
 
Big data interview questions and answers
Big data interview questions and answersBig data interview questions and answers
Big data interview questions and answers
 
Linux 系統管理與安全:基本 Linux 系統知識
Linux 系統管理與安全:基本 Linux 系統知識Linux 系統管理與安全:基本 Linux 系統知識
Linux 系統管理與安全:基本 Linux 系統知識
 
配布用Cacti running with cherokee
配布用Cacti running with cherokee配布用Cacti running with cherokee
配布用Cacti running with cherokee
 
Groovy Introduction for Java Programmer
Groovy Introduction for Java ProgrammerGroovy Introduction for Java Programmer
Groovy Introduction for Java Programmer
 
Donate Organs
Donate OrgansDonate Organs
Donate Organs
 
Cheatsheet: Hex file headers and regex
Cheatsheet: Hex file headers and regexCheatsheet: Hex file headers and regex
Cheatsheet: Hex file headers and regex
 
Web_DBの監視
Web_DBの監視Web_DBの監視
Web_DBの監視
 
Nagios的安装部署和与cacti的整合(linuxtone)
Nagios的安装部署和与cacti的整合(linuxtone)Nagios的安装部署和与cacti的整合(linuxtone)
Nagios的安装部署和与cacti的整合(linuxtone)
 
Linux 系統管理與安全:系統防駭與資訊安全
Linux 系統管理與安全:系統防駭與資訊安全Linux 系統管理與安全:系統防駭與資訊安全
Linux 系統管理與安全:系統防駭與資訊安全
 
Tmux quick-reference
Tmux quick-referenceTmux quick-reference
Tmux quick-reference
 
Webサーバ勉強会#5mod sedについて
Webサーバ勉強会#5mod sedについてWebサーバ勉強会#5mod sedについて
Webサーバ勉強会#5mod sedについて
 
RHEL roadmap
RHEL roadmapRHEL roadmap
RHEL roadmap
 
UNIX SHELL IN DBA EVERYDAY
UNIX SHELL IN DBA EVERYDAYUNIX SHELL IN DBA EVERYDAY
UNIX SHELL IN DBA EVERYDAY
 
Cacti manual
Cacti manualCacti manual
Cacti manual
 
Sorting techniques in Perl
Sorting techniques in PerlSorting techniques in Perl
Sorting techniques in Perl
 

Similar to Unix interview questions

intro unix/linux 06
intro unix/linux 06intro unix/linux 06
intro unix/linux 06duquoi
 
27.1.5 lab convert data into a universal format
27.1.5 lab   convert data into a universal format27.1.5 lab   convert data into a universal format
27.1.5 lab convert data into a universal formatFreddy Buenaño
 
Runtime Environment Of .Net Divya Rathore
Runtime Environment Of .Net Divya RathoreRuntime Environment Of .Net Divya Rathore
Runtime Environment Of .Net Divya RathoreEsha Yadav
 
Software Development Automation With Scripting Languages
Software Development Automation With Scripting LanguagesSoftware Development Automation With Scripting Languages
Software Development Automation With Scripting LanguagesIonela
 
intro unix/linux 05
intro unix/linux 05intro unix/linux 05
intro unix/linux 05duquoi
 
intro unix/linux 03
intro unix/linux 03intro unix/linux 03
intro unix/linux 03duquoi
 
Why is Azure Data Explorer fast in petabyte-scale analytics?
Why is Azure Data Explorer fast in petabyte-scale analytics?Why is Azure Data Explorer fast in petabyte-scale analytics?
Why is Azure Data Explorer fast in petabyte-scale analytics?Sheik Uduman Ali
 
Program 1 – CS 344This assignment asks you to write a bash.docx
Program 1 – CS 344This assignment asks you to write a bash.docxProgram 1 – CS 344This assignment asks you to write a bash.docx
Program 1 – CS 344This assignment asks you to write a bash.docxwkyra78
 
C5 c++ development environment
C5 c++ development environmentC5 c++ development environment
C5 c++ development environmentsnchnchl
 
CS 23001 Computer Science II Data Structures & AbstractionPro.docx
CS 23001 Computer Science II Data Structures & AbstractionPro.docxCS 23001 Computer Science II Data Structures & AbstractionPro.docx
CS 23001 Computer Science II Data Structures & AbstractionPro.docxfaithxdunce63732
 
Unit I - 1R introduction to R program.pptx
Unit I - 1R introduction to R program.pptxUnit I - 1R introduction to R program.pptx
Unit I - 1R introduction to R program.pptxSreeLaya9
 

Similar to Unix interview questions (20)

awk_intro.ppt
awk_intro.pptawk_intro.ppt
awk_intro.ppt
 
Unix day4 v1.3
Unix day4 v1.3Unix day4 v1.3
Unix day4 v1.3
 
Awk programming
Awk programming Awk programming
Awk programming
 
intro unix/linux 06
intro unix/linux 06intro unix/linux 06
intro unix/linux 06
 
27.1.5 lab convert data into a universal format
27.1.5 lab   convert data into a universal format27.1.5 lab   convert data into a universal format
27.1.5 lab convert data into a universal format
 
Unix Tutorial
Unix TutorialUnix Tutorial
Unix Tutorial
 
Awk Introduction
Awk IntroductionAwk Introduction
Awk Introduction
 
Linux intro 5 extra: awk
Linux intro 5 extra: awkLinux intro 5 extra: awk
Linux intro 5 extra: awk
 
Unix - Class7 - awk
Unix - Class7 - awkUnix - Class7 - awk
Unix - Class7 - awk
 
Runtime Environment Of .Net Divya Rathore
Runtime Environment Of .Net Divya RathoreRuntime Environment Of .Net Divya Rathore
Runtime Environment Of .Net Divya Rathore
 
Unix t2
Unix t2Unix t2
Unix t2
 
Software Development Automation With Scripting Languages
Software Development Automation With Scripting LanguagesSoftware Development Automation With Scripting Languages
Software Development Automation With Scripting Languages
 
intro unix/linux 05
intro unix/linux 05intro unix/linux 05
intro unix/linux 05
 
intro unix/linux 03
intro unix/linux 03intro unix/linux 03
intro unix/linux 03
 
Why is Azure Data Explorer fast in petabyte-scale analytics?
Why is Azure Data Explorer fast in petabyte-scale analytics?Why is Azure Data Explorer fast in petabyte-scale analytics?
Why is Azure Data Explorer fast in petabyte-scale analytics?
 
Program 1 – CS 344This assignment asks you to write a bash.docx
Program 1 – CS 344This assignment asks you to write a bash.docxProgram 1 – CS 344This assignment asks you to write a bash.docx
Program 1 – CS 344This assignment asks you to write a bash.docx
 
C5 c++ development environment
C5 c++ development environmentC5 c++ development environment
C5 c++ development environment
 
CS 23001 Computer Science II Data Structures & AbstractionPro.docx
CS 23001 Computer Science II Data Structures & AbstractionPro.docxCS 23001 Computer Science II Data Structures & AbstractionPro.docx
CS 23001 Computer Science II Data Structures & AbstractionPro.docx
 
Awk
AwkAwk
Awk
 
Unit I - 1R introduction to R program.pptx
Unit I - 1R introduction to R program.pptxUnit I - 1R introduction to R program.pptx
Unit I - 1R introduction to R program.pptx
 

Recently uploaded

Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 

Recently uploaded (20)

Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 

Unix interview questions

  • 1. 3/26/2015 UNIX INTERVIEW QUESTIONS data:text/html;charset=utf-8,%3Cdiv%20class%3D%22article-header%22%20style%3D%22margin%3A%200px%3B%20outlin… 1/18 Awk is powerful tool in Unix. Awk is an excellent tool for processing the files which have data arranged in rows and columns format. It is a good filter and report writer.  1. How to run awk command specified in a file? awk ­f filename 2. Write a command to print the squares of numbers from 1 to 10 using awk command awk 'BEGIN { for(i=1;i<=10;i++) {print "square of",i,"is",i*i;}}' 3. Write a command to find the sum of bytes (size of file) of all files in a directory. ls ­l | awk 'BEGIN {sum=0} {sum = sum + $5} END {print sum}' 4. In the text file, some lines are delimited by colon and some are delimited by space. Write a command to print the third field of each line. awk '{ if( $0 ~ /:/ ) { FS=":"; } else { FS =" "; } print $3 }' filename 5. Write a command to print the line number before each line? awk '{print NR, $0}' filename 6. Write a command to print the second and third line of a file without using NR. awk 'BEGIN {RS="";FS="n"} {print $2,$3}' filename 7. Write a command to print zero byte size files? ls ­l | awk '/^­/ {if ($5 !=0 ) print $9 }' 8. Write a command to rename the files in a directory with "_new" as postfix? ls ­F | awk '{print "mv "$1" "$1".new"}' | sh 9. Write a command to print the fields in a text file in reverse order? awk 'BEGIN {ORS=""} { for(i=NF;i>0;i­­) print $i," "; print "n"}' filename 10. Write a command to find the total number of lines in a file without using NR awk 'BEGIN {sum=0} {sum=sum+1} END {print sum}' filename Another way to print the number of lines is by using the NR. The command is awk 'END{print NR}' filename The grep is one of the powerful tools in unix. Grep stands for "global search for regular expressions and print". The power of grep lies in using regular expressions mostly. UNIX INTERVIEW QUESTIONS UNIX INTERVIEW QUESTIONS ON AWK COMMAND UNIX INTERVIEW QUESTIONS ON GREP COMMAND
  • 2. 3/26/2015 UNIX INTERVIEW QUESTIONS data:text/html;charset=utf-8,%3Cdiv%20class%3D%22article-header%22%20style%3D%22margin%3A%200px%3B%20outlin… 2/18 The general syntax of grep command is grep [options] pattern [files] 1. Write a command to print the lines that has the the pattern "july" in all the files in a particular directory? grep july * This will print all the lines in all files that contain the word “july” along with the file name. If any of the files contain words like "JULY" or "July", the above command would not print those lines. 2. Write a command to print the lines that has the word "july" in all the files in a directory and also suppress the filename in the output. grep ­h july * 3. Write a command to print the lines that has the word "july" while ignoring the case. grep ­i july * The option i make the grep command to treat the pattern as case insensitive. 4. When you use a single file as input to the grep command to search for a pattern, it won't print the filename in the output. Now write a grep command to print the filename in the output without using the '­H' option. grep pattern filename /dev/null The /dev/null or null device is special file that discards the data written to it. So, the /dev/null is always an empty file. Another way to print the filename is using the '­H' option. The grep command for this is grep ­H pattern filename 5. Write a Unix command to display the lines in a file that do not contain the word "july"? grep ­v july filename The '­v' option tells the grep to print the lines that do not contain the specified pattern. 6. Write a command to print the file names in a directory that has the word "july"? grep ­l july * The '­l' option make the grep command to print only the filename without printing the content of the file. As soon as the grep command finds the pattern in a file, it prints the pattern and stops searching other lines in the file. 7. Write a command to print the file names in a directory that does not contain the word "july"? grep ­L july * The '­L' option makes the grep command to print the filenames that do not contain the specified pattern. 8. Write a command to print the line numbers along with the line that has the word "july"? grep ­n july filename The '­n' option is used to print the line numbers in a file. The line numbers start from 1 9. Write a command to print the lines that starts with the word "start"? grep '^start' filename The '^' symbol specifies the grep command to search for the pattern at the start of the line.
  • 3. 3/26/2015 UNIX INTERVIEW QUESTIONS data:text/html;charset=utf-8,%3Cdiv%20class%3D%22article-header%22%20style%3D%22margin%3A%200px%3B%20outlin… 3/18 10. Write a command to print the lines which end with the word "end"? grep 'end$' filename The '$' symbol specifies the grep command to search for the pattern at the end of the line. 11. Write a command to select only those lines containing "july" as a whole word? grep ­w july filename The '­w' option makes the grep command to search for exact whole words. If the specified pattern is found in a string, then it is not considered as a whole word. For example: In the string "mikejulymak", the pattern "july" is found. However "july" is not a whole word in that string. UNIX INTERVIEW QUESTIONS ON SED COMMAND SED is a special editor used for modifying files automatically. 1. Write a command to replace the word "bad" with "good" in file? sed s/bad/good/ < filename 2. Write a command to replace the word "bad" with "good" globally in a file? sed s/bad/good/g < filename 3. Write a command to replace the character '/' with ',' in a file? sed 's///,/' < filename sed 's|/|,|' < filename 4. Write a command to replace the word "apple" with "(apple)" in a file? sed s/apple/(&)/ < filename 5. Write a command to switch the two consecutive words "apple" and "mango" in a file? sed 's/(apple) (mango)/2 1/' < filename 6. Write a command to replace the second occurrence of the word "bat" with "ball" in a file? sed 's/bat/ball/2' < filename 7. Write a command to remove all the occurrences of the word "jhon" except the first one in a line with in the entire file? sed 's/jhon//2g' < filename 8. Write a command to remove the first number on line 5 in file? sed '5 s/[0­9][0­9]*//' < filename 9. Write a command to remove the first number on all lines that start with "@"? sed ',^@, s/[0­9][0­9]*//' < filename 10. Write a command to replace the word "gum" with "drum" in the first 100 lines of a file? sed '1,00 s/gum/drum/' < filename 11. write a command to replace the word "lite" with "light" from 100th line to last line in a file? sed '100,$ s/lite/light/' < filename
  • 4. 3/26/2015 UNIX INTERVIEW QUESTIONS data:text/html;charset=utf-8,%3Cdiv%20class%3D%22article-header%22%20style%3D%22margin%3A%200px%3B%20outlin… 4/18 12. Write a command to remove the first 10 lines from a file? sed '1,10 d' < filename 13. Write a command to duplicate each line in a file? sed 'p' < filename 14. Write a command to duplicate empty lines in a file? sed '/^$/ p' < filename 15. Write a sed command to print the lines that do not contain the word "run"? sed ­n '/run/!p' < filename UNIX INTERVIEW QUESTIONS ON CUT COMMAND The cut command is used to used to display selected columns or fields from each line of a file. Cut command works in two modes: Delimited selection: The fields in the line are delimited by a single character like blank,comma etc. Range selection: Each field starts with certain fixed offset defined as range. 1. Write a command to display the third and fourth character from each line of a file? cut ­c 3,4 filename 2. Write a command to display the characters from 10 to 20 from each line of a file? cut ­c 10­20 filename 3. Write a command to display the first 10 characters from each line of a file? cut ­c ­10 filename 4. Write a comamnd to display from the 10th character to the end of the line? cut ­c 10­ filename 5. The fields in each line are delimited by comma. Write a command to display third field from each line of a file? cut ­d',' ­f2 filename 6. Write a command to print the fields from 10 to 20 from each line of a file? cut ­d',' ­f10­20 filename 7. Write a command to print the first 5 fields from each line? cut ­d',' ­f­5 filename 8. Write a command to print the fields from 10th to the end of the line? cut ­d',' ­f10­ filename 9. By default the cut command displays the entire line if there is no delimiter in it. Which cut option is used to supress these kind of lines? The ­s option is used to supress the lines that do not contain the delimiter. 10. Write a cut command to extract the username from 'who am i' comamnd?
  • 5. 3/26/2015 UNIX INTERVIEW QUESTIONS data:text/html;charset=utf-8,%3Cdiv%20class%3D%22article-header%22%20style%3D%22margin%3A%200px%3B%20outlin… 5/18 who am i | cut ­f1 ­d' ' UNIX INTERVIEW QUESTIONS ON FIND COMMAND Find utility is used for searching files using the directory information. 1. Write a command to search for the file 'test' in the current directory? find ­name test ­type f 2. Write a command to search for the file 'temp' in '/usr' directory? find /usr ­name temp ­type f 3. Write a command to search for zero byte size files in the current directory? find ­size 0 ­type f 4. Write a command to list the files that are accessed 5 days ago in the current directory? find ­atime 5 ­type f 5. Write a command to list the files that were modified 5 days ago in the current directory? find ­mtime 5 ­type f 6. Write a command to search for the files in the current directory which are not owned by any user in the /etc/passwd file? find . ­nouser ­type f 7. Write a command to search for the files in '/usr' directory that start with 'te'? find /usr ­name 'te*' ­type f 8. Write a command to search for the files that start with 'te' in the current directory and then display the contents of the file? find . ­name 'te*' ­type f ­exec cat {} ; 9. Write a command to list the files whose status is changed 5 days ago in the current directory? find ­ctime 5 ­type f 10. Write a command to list the files in '/usr' directory that start with 'ch' and then display the number of lines in each file? find /usr ­name 'ch*' ­type f ­exec wc ­l {} ; TOP UNIX INTERVIEW QUESTIONS ­ PART 1 1. How to display the 10th line of a file? head -10 filename | tail -1 2. How to remove the header from a file?
  • 6. 3/26/2015 UNIX INTERVIEW QUESTIONS data:text/html;charset=utf-8,%3Cdiv%20class%3D%22article-header%22%20style%3D%22margin%3A%200px%3B%20outlin… 6/18 sed -i '1 d' filename 3. How to remove the footer from a file? sed -i '$ d' filename 4. Write a command to find the length of a line in a file? The below command can be used to get a line from a file. sed –n '<n> p' filename We will see how to find the length of 10th line in a file sed -n '10 p' filename|wc -c 5. How to get the nth word of a line in Unix? cut –f<n> -d' ' 6. How to reverse a string in unix? echo "java" | rev 7. How to get the last word from a line in Unix file? echo "unix is good" | rev | cut -f1 -d' ' | rev 8. How to replace the n­th line in a file with a new line in Unix? sed -i'' '10 d' filename # d stands for delete sed -i'' '10 i new inserted line' filename # i stands for insert 9. How to check if the last command was successful in Unix?
  • 7. 3/26/2015 UNIX INTERVIEW QUESTIONS data:text/html;charset=utf-8,%3Cdiv%20class%3D%22article-header%22%20style%3D%22margin%3A%200px%3B%20outlin… 7/18 echo $? 10. Write command to list all the links from a directory? ls -lrt | grep "^l" 11. How will you find which operating system your system is running on in UNIX? uname -a 12. Create a read­only file in your home directory? touch file; chmod 400 file 13. How do you see command line history in UNIX? The 'history' command can be used to get the list of commands that we are executed. 14. How to display the first 20 lines of a file? By default, the head command displays the first 10 lines from a file. If we change the option of head, then we can display as many lines as we want. head -20 filename An alternative solution is using the sed command sed '21,$ d' filename The d option here deletes the lines from 21 to the end of the file 15. Write a command to print the last line of a file? The tail command can be used to display the last lines from a file. tail -1 filename Alternative solutions are:
  • 8. 3/26/2015 UNIX INTERVIEW QUESTIONS data:text/html;charset=utf-8,%3Cdiv%20class%3D%22article-header%22%20style%3D%22margin%3A%200px%3B%20outlin… 8/18 sed -n '$ p' filename awk 'END{print $0}' filename TOP UNIX INTERVIEW QUESTIONS ­ PART 2 1. How do you rename the files in a directory with _new as suffix? ls -lrt|grep '^-'| awk '{print "mv "$9" "$9".new"}' | sh 2. Write a command to convert a string from lower case to upper case? echo "apple" | tr [a-z] [A-Z] 3. Write a command to convert a string to Initcap. echo apple | awk '{print toupper(substr($1,1,1)) tolower(substr($1,2))}' 4. Write a command to redirect the output of date command to multiple files? The tee command writes the output to multiple files and also displays the output on the terminal. date | tee -a file1 file2 file3 5. How do you list the hidden files in current directory? ls -a | grep '^.' 6. List out some of the Hot Keys available in bash shell?  Ctrl+l ­ Clears the Screen. Ctrl+r ­ Does a search in previously given commands in shell. Ctrl+u ­ Clears the typing before the hotkey. Ctrl+a ­ Places cursor at the beginning of the command at shell. Ctrl+e ­ Places cursor at the end of the command at shell. Ctrl+d ­ Kills the shell. Ctrl+z ­ Places the currently running process into background.
  • 9. 3/26/2015 UNIX INTERVIEW QUESTIONS data:text/html;charset=utf-8,%3Cdiv%20class%3D%22article-header%22%20style%3D%22margin%3A%200px%3B%20outlin… 9/18 7. How do you make an existing file empty? cat /dev/null >  filename 8. How do you remove the first number on 10th line in file? sed '10 s/[0-9][0-9]*//' < filename 9. What is the difference between join ­v and join ­a? join -v : outputs only matched lines between two files. join -a : In addition to the matched lines, this will output unmatched lines also. 10. How do you display from the 5th character to the end of the line from a file? cut -c 5- filename TOP UNIX INTERVIEW QUESTIONS ­ PART 3 1. Display all the files in current directory sorted by size? ls -l | grep '^-' | awk '{print $5,$9}' |sort -n|awk '{print $2}' 2. Write a command to search for the file 'map' in the current directory? find -name map -type f 3. How to display the first 10 characters from each line of a file? cut -c -10 filename 4. Write a command to remove the first number on all lines that start with "@"? sed ',^@, s/[0-9][0-9]*//' < filename
  • 10. 3/26/2015 UNIX INTERVIEW QUESTIONS data:text/html;charset=utf-8,%3Cdiv%20class%3D%22article-header%22%20style%3D%22margin%3A%200px%3B%20outli… 10/18 5. How to print the file names in a directory that has the word "term"? grep -l term * The '­l' option make the grep command to print only the filename without printing the content of the file. As soon as the grep command finds the pattern in a file, it prints the pattern and stops searching other lines in the file. 6. How to run awk command specified in a file? awk -f filename 7. How do you display the calendar for the month march in the year 1985? The cal command can be used to display the current month calendar. You can pass the month and year as arguments to display the required year, month combination calendar. cal 03 1985 This will display the calendar for the March month and year 1985. 8. Write a command to find the total number of lines in a file? wc -l filename Other ways to print the total number of lines are awk 'BEGIN {sum=0} {sum=sum+1} END {print sum}' filename awk 'END{print NR}' filename 9. How to duplicate empty lines in a file? sed '/^$/ p' < filename 10. Explain iostat, vmstat and netstat? Iostat: reports on terminal, disk and tape I/O activity. Vmstat: reports on virtual memory statistics for processes, disk, tape and CPU activity.
  • 11. 3/26/2015 UNIX INTERVIEW QUESTIONS data:text/html;charset=utf-8,%3Cdiv%20class%3D%22article-header%22%20style%3D%22margin%3A%200px%3B%20outli… 11/18 1. How do you write the contents of 3 files into a single file? cat file1 file2 file3 > file 2. How to display the fields in a text file in reverse order? awk 'BEGIN {ORS=""} { for(i=NF;i>0;i--) print $i," "; print "n"}' filename 3. Write a command to find the sum of bytes (size of file) of all files in a directory. ls -l | grep '^-'| awk 'BEGIN {sum=0} {sum = sum + $5} END {print sum}' 4. Write a command to print the lines which end with the word "end"? grep 'end$' filename The '$' symbol specifies the grep command to search for the pattern at the end of the line. 5. Write a command to select only those lines containing "july" as a whole word? grep -w july filename The '­w' option makes the grep command to search for exact whole words. If the specified pattern is found in a string, then it is not considered as a whole word. For example: In the string "mikejulymak", the pattern "july" is found. However "july" is not a whole word in that string. 6. How to remove the first 10 lines from a file? sed '1,10 d' < filename 7. Write a command to duplicate each line in a file? sed 'p' < filename Netstat: reports on the contents of network data structures. TOP UNIX INTERVIEW QUESTIONS ­ PART 4
  • 12. 3/26/2015 UNIX INTERVIEW QUESTIONS data:text/html;charset=utf-8,%3Cdiv%20class%3D%22article-header%22%20style%3D%22margin%3A%200px%3B%20outli… 12/18 8. How to extract the username from 'who am i' comamnd? who am i | cut -f1 -d' ' 9. Write a command to list the files in '/usr' directory that start with 'ch' and then display the number of lines in each file? wc -l /usr/ch* Another way is  find /usr -name 'ch*' -type f -exec wc -l {} ; 10. How to remove blank lines in a file ? grep -v ‘^$’ filename > new_filename 1. How to display the processes that were run by your user name ? ps -aef | grep <user_name> 2. Write a command to display all the files recursively with path under current directory? find . -depth -print 3. Display zero byte size files in the current directory? find -size 0 -type f 4. Write a command to display the third and fifth character from each line of a file? cut -c 3,5 filename TOP UNIX INTERVIEW QUESTIONS ­ PART 5
  • 13. 3/26/2015 UNIX INTERVIEW QUESTIONS data:text/html;charset=utf-8,%3Cdiv%20class%3D%22article-header%22%20style%3D%22margin%3A%200px%3B%20outli… 13/18 5. Write a command to print the fields from 10th to the end of the line. The fields in the line are delimited by a comma? cut -d',' -f10- filename 6. How to replace the word "Gun" with "Pen" in the first 100 lines of a file? sed '1,00 s/Gun/Pen/' < filename 7. Write a Unix command to display the lines in a file that do not contain the word "RAM"? grep -v RAM filename The '­v' option tells the grep to print the lines that do not contain the specified pattern. 8. How to print the squares of numbers from 1 to 10 using awk command awk 'BEGIN { for(i=1;i<=10;i++) {print "square of",i,"is",i*i;}}' 9. Write a command to display the files in the directory by file size? ls -l | grep '^-' |sort -nr -k 5 10. How to find out the usage of the CPU by the processes? The top utility can be used to display the CPU usage by the processes. TOP UNIX INTERVIEW QUESTIONS ­ PART 6 1. Write a command to remove the prefix of the string ending with '/'. The basename utility deletes any prefix ending in /. The usage is mentioned below: basename /usr/local/bin/file This will display only file 2. How to display zero byte size files?
  • 14. 3/26/2015 UNIX INTERVIEW QUESTIONS data:text/html;charset=utf-8,%3Cdiv%20class%3D%22article-header%22%20style%3D%22margin%3A%200px%3B%20outli… 14/18 ls -l | grep '^-' | awk '/^-/ {if ($5 !=0 ) print $9 }' 3. How to replace the second occurrence of the word "bat" with "ball" in a file? sed 's/bat/ball/2' < filename 4. How to remove all the occurrences of the word "jhon" except the first one in a line with in the entire file? sed 's/jhon//2g' < filename 5. How to replace the word "lite" with "light" from 100th line to last line in a file? sed '100,$ s/lite/light/' < filename 6. How to list the files that are accessed 5 days ago in the current directory? find -atime 5 -type f 7. How to list the files that were modified 5 days ago in the current directory? find -mtime 5 -type f 8. How to list the files whose status is changed 5 days ago in the current directory? find -ctime 5 -type f 9. How to replace the character '/' with ',' in a file? sed 's///,/' < filename sed 's|/|,|' < filename 10. Write a command to find the number of files in a directory. ls -l|grep '^-'|wc -l
  • 15. 3/26/2015 UNIX INTERVIEW QUESTIONS data:text/html;charset=utf-8,%3Cdiv%20class%3D%22article-header%22%20style%3D%22margin%3A%200px%3B%20outli… 15/18 TOP UNIX INTERVIEW QUESTIONS ­ PART 7 1. Write a command to display your name 100 times. The Yes utility can be used to repeatedly output a line with the specified string or 'y'. yes <your_name> | head -100 2. Write a command to display the first 10 characters from each line of a file? cut -c -10 filename 3. The fields in each line are delimited by comma. Write a command to display third field from each line of a file? cut -d',' -f2 filename 4. Write a command to print the fields from 10 to 20 from each line of a file? cut -d',' -f10-20 filename 5. Write a command to print the first 5 fields from each line? cut -d',' -f-5 filename 6. By default the cut command displays the entire line if there is no delimiter in it. Which cut option is used to suppress these kind of lines? The ­s option is used to suppress the lines that do not contain the delimiter. 7. Write a command to replace the word "bad" with "good" in file? sed s/bad/good/ < filename 8. Write a command to replace the word "bad" with "good" globally in a file? sed s/bad/good/g < filename
  • 16. 3/26/2015 UNIX INTERVIEW QUESTIONS data:text/html;charset=utf-8,%3Cdiv%20class%3D%22article-header%22%20style%3D%22margin%3A%200px%3B%20outli… 16/18    9. Write a command to replace the word "apple" with "(apple)" in a file? sed s/apple/(&)/ < filename 10. Write a command to switch the two consecutive words "apple" and "mango" in a file? sed 's/(apple) (mango)/2 1/' < filename 11. Write a command to display the characters from 10 to 20 from each line of a file? cut -c 10-20 filename TOP UNIX INTERVIEW QUESTIONS ­ PART 8 1. Write a command to print the lines that has the the pattern "july" in all the files in a particular directory? grep july * This will print all the lines in all files that contain the word “july” along with the file name. If any of the files contain words like "JULY" or "July", the above command would not print those lines. 2. Write a command to print the lines that has the word "july" in all the files in a directory and also suppress the file name in the output. grep -h july * 3. Write a command to print the lines that has the word "july" while ignoring the case. grep -i july * The option i make the grep command to treat the pattern as case insensitive. 4. When you use a single file as input to the grep command to search for a pattern, it won't print the filename in the output. Now write a grep command to print the file name in the output without using the '­H' option. grep pattern file name /dev/null
  • 17. 3/26/2015 UNIX INTERVIEW QUESTIONS data:text/html;charset=utf-8,%3Cdiv%20class%3D%22article-header%22%20style%3D%22margin%3A%200px%3B%20outli… 17/18 The /dev/null or null device is special file that discards the data written to it. So, the /dev/null is always an empty file. Another way to print the file name is using the '­H' option. The grep command for this is grep -H pattern filename 5. Write a command to print the file names in a directory that does not contain the word "july"? grep -L july * The '­L' option makes the grep command to print the file names that do not contain the specified pattern. 6. Write a command to print the line numbers along with the line that has the word "july"? grep -n july filename The '­n' option is used to print the line numbers in a file. The line numbers start from 1 7. Write a command to print the lines that starts with the word "start"? grep '^start' filename The '^' symbol specifies the grep command to search for the pattern at the start of the line. 8. In the text file, some lines are delimited by colon and some are delimited by space. Write a command to print the third field of each line. awk '{ if( $0 ~ /:/ ) { FS=":"; } else { FS =" "; } print $3 }' filename 9. Write a command to print the line number before each line? awk '{print NR, $0}' filename 10. Write a command to print the second and third line of a file without using NR.
  • 18. 3/26/2015 UNIX INTERVIEW QUESTIONS data:text/html;charset=utf-8,%3Cdiv%20class%3D%22article-header%22%20style%3D%22margin%3A%200px%3B%20outli… 18/18 awk 'BEGIN {RS="";FS="n"} {print $2,$3}' filename 11. How to create an alias for the complex command and remove the alias? The alias utility is used to create the alias for a command. The below command creates alias for ps ­aef command. alias pg='ps -aef' If you use pg, it will work the same way as ps ­aef. To remove the alias simply use the unalias command as unalias pg 12. Write a command to display today's date in the format of 'yyyy­mm­dd'? The date command can be used to display today's date with time date '+%Y-%m-%d'