Saturday, April 13, 2013

Nitheen Kumar

Shell Scripting Interview Questions 4

 
31: What is the difference between grep and egrep?

egrep is Extended grep that supports added grep features like “+” (1 or more occurrence of previous character),”? ”(0 or 1 occurrence of previous character) and “|” (alternate matching)

32: How will you print the login names of all users on a system?

/etc/shadow file has all the users listed. awk –F ‘:’ ‘{print $1} /etc/shadow’|uniq -u

33: How to set an array in Linux?

Syntax in ksh: Set –A arrayname= (element1 element2 ….. element) In bash A=(element1 element2 element3 …. elementn)

34: Write down the syntax of “for “ loop?

Syntax: for iterator in (elements) do execute commands done

35:How will you find the total disk space used by a specific user?

du -s /home/user1 ….where user1 is the user for whom the total disk space needs to be found.

36: Write the syntax for “if” conditionals in linux?

Syntax If condition is successful then execute commands else execute commands fi

37:What is the significance of $?

? $? gives the exit status of the last command that was executed.

38: How do we delete all blank lines in a file?

sed ‘^ [(backslash)011(backslash)040]*$/d’ file1 where (backslash)011 is octal equivalent of space and (backslash)040 is octal equivalent of tab

39: How will I insert a line “ABCDEF” at every 100th line of a file?

sed ‘100i\ABCDEF’ file1

40: Write a command sequence to find all the files modified in less than 2 days and print the record count of each.?

find . –mtime -2 –exec wc –l {} \;

<< 1 2 3 4 5 >>

Subscribe to get more Posts :