Thursday, October 11, 2012

InterviewFreak


4 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. This is my first blog. This is basically for people planning to switch jobs and hence have to face interviews.

    I know there are multiple sites available with Interview tips, interview Q&A. However what I have observed is that none of the sites provides you the best answers, the explanations in a manner that it is understood even by the novice.

    Job interviews are always stressful - even for job seekers who have gone on countless interviews. The best way to reduce the stress is to be prepared. Take the time to review the common interview questions you will most likely be asked. Also review sample answers to these typical interview questions.

    Whatever I have learned from my 6.9 years of experience is that one should be very clear on the basics. If basics fundas are clear nobody can stop you from clearing any interview.

    To start with my first blog will be dedicated to UNIX Lovers..

    So come on and dive to UNIX world. As all of you are aware - UNIX is an amazing masterpiece created by a group of AT&T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Brian Kernighan, Douglas McIlroy, Michael Lesk and Joe Ossanna.

    UNIX is a multitasking, multi-user computer operating system. The Unix operating system was first developed in assembly language, but by 1973 had been almost entirely recoded in C, greatly facilitating its further development and porting to other hardware.

    In this blog I am planning to put couple of new questions/answers daily.

    However please note that the idea behind this is to create a community site where people can come up with there set of questions/answers which will help us increasing the knowledge bank of our blog.

    Without wasting much time I lets go to the Q&A World :-)

    ReplyDelete
  3. Question 1: This is basically related to Shell Scripting which is a powerful feature in UNIX.

    Question is how we can rename multiple files in UNIX? For e.g. if we want to rename all *.c files to *.cpp files in a particular directory how can we do that?


    Answer: We can use basename command. basename is a standard command which allows you to strip suffixes from filenames:

    SYNTAX:
    Basename

    For example -

    $ basename c.jpg .jpg
    c

    $ basename c.jpg pg
    c.j

    Here you can see that the command just returns the filename you've specified with the second argument removed from it.

    So we will apply the concept of basename to solve our problem. Remember we need to rename multiple files in a single directory. Move command will not work here.

    If you are thinking something like

    mv a.c b.c c.c a.cpp b.cpp c.cpp you are totally wrong. mv will not work that way.

    The solution is to use basename command as shown in example above:

    We can write a simple shell script as below:

    #!/usr/bin/sh
    # Read all c files

    for filename in *.c
    do
    b=$(basename $filename .c)
    mv $filename $b.cpp
    done

    That's it...done with first Q/A of my blog.

    Hope that its very very easy to understand and help you memorize the concept of basename

    ReplyDelete
  4. As promised writing second question of the day....which is fairly easy one...

    Question 2: How will you find the 99th line of a file using only tail and head command?

    Answer: tail +99 |head -1

    # tail +99 debug.log|head -1 true
    #

    That's it

    ReplyDelete