Tuesday, March 19, 2013

Unix Real Time Interview Questions with answers

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.
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

No comments:

Post a Comment