• Updating.......
    • Waiting.....

Linux/UNIX Interview PART - 1

Linux command line Q&A

  1. You need to see the last fifteen lines of the files dog, cat and horse. What command should you use? tail -15 dog cat horse
    The tail utility displays the end of a file. The -15 tells tail to display the last fifteen lines of each specified file.
  2. Who owns the data dictionary?
    The SYS user owns the data dictionary. The SYS and SYSTEM users are created when the database is created.
  3. You routinely compress old log files. You now need to examine a log from two months ago. In order to view its contents without first having to decompress it, use the _________ utility.
    zcat
    The zcat utility allows you to examine the contents of a compressed file much the same way that cat displays a file.
  4. You suspect that you have two commands with the same name as the command is not producing the expected results. What command can you use to determine the location of the command being run?
    which
    The which command searches your path until it finds a command that matches the command you are looking for and displays its full path.
  5. You locate a command in the /bin directory but do not know what it does. What command can you use to determine its purpose.
    whatis
    The whatis command displays a summary line from the man page for the specified command.
  6. You wish to create a link to the /data directory in bob’s home directory so you issue the command ln /data /home/bob/datalink but the command fails. What option should you use in this command line to be successful.
    Use the -F option
    In order to create a link to a directory you must use the -F option.
  7. When you issue the command ls -l, the first character of the resulting display represents the file’s ___________.
    type
    The first character of the permission block designates the type of file that is being displayed.
  8. What utility can you use to show a dynamic listing of running processes? __________
    top
    The top utility shows a listing of all running processes that is dynamically updated.
  9. Where is standard output usually directed?
    to the screen or display
    By default, your shell directs standard output to your screen or display.
  10. You wish to restore the file memo.ben which was backed up in the tarfile MyBackup.tar. What command should you type?
    tar xf MyBackup.tar memo.ben
    This command uses the x switch to extract a file. Here the file memo.ben will be restored from the tarfile MyBackup.tar.
  11. You need to view the contents of the tarfile called MyBackup.tar. What command would you use?
    tar tf MyBackup.tar
    The t switch tells tar to display the contents and the f modifier specifies which file to examine.
  12. You want to create a compressed backup of the users’ home directories. What utility should you use?
    tar
    You can use the z modifier with tar to compress your archive at the same time as creating it.
  13. What daemon is responsible for tracking events on your system?
    syslogd
    The syslogd daemon is responsible for tracking system information and saving it to specified log files.
  14. You have a file called phonenos that is almost 4,000 lines long. What text filter can you use to split it into four pieces each 1,000 lines long?
    split
    The split text filter will divide files into equally sized pieces. The default length of each piece is 1,000 lines.
  15. You would like to temporarily change your command line editor to be vi. What command should you type to change it?
    set -o vi
    The set command is used to assign environment variables. In this case, you are instructing your shell to assign vi as your command line editor. However, once you log off and log back in you will return to the previously defined command line editor.
  16. What account is created when you install Linux?
    root
    Whenever you install Linux, only one user account is created. This is the superuser account also known as root.
  17. What command should you use to check the number of files and disk space used and each user’s defined quotas?
    repquota
    The repquota command is used to get a report on the status of the quotas you have set including the amount of allocated space and amount of used space.


Basic sed tricks

  1. What is sed? - sed is stream editor, a Unix tool for working with streams of text data.
  2. How do you substitute strings with sed? - Use ’s/old/new’ command, so sed ’s/hello/goodbye/’ would substitute the occurrence of the word hello to goodbye.
  3. How do you inject text with sed? - & in the substitution string defines the pattern found in the search string. As an example, here’s us trying to find a word ‘hello’ and replacing it with ‘hello and how are you’:
    echo ‘hello there’ | sed ’s/^hello/& and how are you/’
  4. Can I find several patterns and refer to them in the replacement string? - Yes, use (pattern) and then refer to your patterns as \1, \2, \3 and so on.
  5. If the string is ‘old old old’ and I run ’s/old/new’, I get ‘new old old’ as the result. I need ‘new new new‘. - You forgot the global modifier, which would replace every occurrence of the pattern with the substitution. ’s/old/new/g‘ will work.
  6. But I want ‘old old new’ from the previous example. - Just use the numeric modifier saying you want the third occurrence to be replaced. ’s/old/new/3‘ will work.
  7. I wrote a rather complex sed script. How do I save and run it? - Assuming that your file is named myscript1.sed, you can invoke sed -f myscript1.sed.
  8. How do I delete trailing whitespaces from each line? - sed ’s/[ \t]*$//’ Here we’re replacing any occurrence of a space or a tab with nothing.
  9. How do you print just a few first lines of the file? - sed 1q will give you just the first line, sed 10q the first 10 lines.
  10. How do you replace a pattern only if it’s found, so that it’s executed faster? - Nest the replacement statement: sed ‘/old/ s/old/new/g’ file.txt

Linux application programming questions

  1. Explain the difference between a static library and a dynamic library? - Static library is linked into the executable, while a dynamic library (or shared object) is loaded while the executable has started.
  2. How do you create a static library? - If you have a collection of object (.o) files, you can do it by running ar command. Generally a static library has a .a extension, and you can link it into an executable by providing -l libraryname to gcc.
  3. Where should the developed libraries be installed on the system? - GNU recommends /usr/local/bin for binaries and /usr/local/lib for libraries.
  4. What’s LD_LIBRARY_PATH? - It’s an environment variable that lists all the directories which should be searches for libraries before the standard directories are searched.
  5. How do you create a shared library? - Create the object file with -fPIC for position-independent code, then run gcc with -shared option.
  6. How do you install a shared library? - Run ldconfig in the standard directory that it’s installed in.
  7. What does ldd do? - It shows a list of installed shared libraries.
  8. How do you dynamically load a library in your app? - Use dlopen()
  9. What does nm command do? - It reports the list of symbols in a given library.