Tuesday, 27 October 2015

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 {} \;

What is the significance of $? ?

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

Write the syntax for “if” conditionals in linux?

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

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.

Write down the syntax of “for “ loop

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

How to set an array in Linux?

In bash
A=(element1 element2 element3 …. elementn)

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