1: What are the 3 standard streams in Linux?
Output
stream , represented as 0 , Input stream, represented as 1 and Error
stream represented as 2.
2: I want to read all input to the command from file1 direct all
output to file2 and error to file 3, how can I achieve this?
command
<file1 0>file2 2>file3
3: What will happen to my current process when I execute a
command using exec?
“exec”
overlays the newly forked process on the current process ; so when I
execute the command using exec a new process corresponding to the command
will be created and the current process will die.
Eg: Executing “exec com1” on command prompt will execute com1 and return to login prompt since my logged in shell is superimposed with the new process of the command .
Eg: Executing “exec com1” on command prompt will execute com1 and return to login prompt since my logged in shell is superimposed with the new process of the command .
4: How will you emulate wc –l using awk?
awk
‘END {print NR} fileName’
5: Given a file find the count of lines containing word “ABC”.
grep
–c “ABC” file1
6: 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)
7: 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
8: How to set an array in Linux?
Syntax
in ksh:
Set –A arrayname= (element1 element2 ….. element)
In bash
A=(element1 element2 element3 …. elementn)
Set –A arrayname= (element1 element2 ….. element)
In bash
A=(element1 element2 element3 …. elementn)
9: Write down the syntax of “for “ loop
Syntax:
for
iterator in (elements)
do
execute commands
done
do
execute commands
done
10: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.
space needs to be found.
11: Write the syntax for “if” conditionals in linux?
Syntax
If
condition is successful
then
execute commands
else
execute commands
fi
then
execute commands
else
execute commands
fi
12:What is the significance of $? ?
$?
gives the exit status of the last command that was executed.
13: 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
14: How will I insert a line “ABCDEF” at every 100th
line of a file?
sed
‘100i\ABCDEF’ file1
15: 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 {} \;
16: How can I set the default rwx permission to all users on
every file which is created in the current shell?
We
can use:
umask 777
|
This
will set default rwx permission for every file which is created to every user.
17: How can we find the process name from its process id?
We
can use “ps –p ProcessId”
18: What are the four fundamental components of every file
system on linux?
bootblock,
super block, inode block and datablock
19: What is a boot block?
This
block contains a small program called “Master Boot record”(MBR) which loads the
kernel during system boot up.
20: What is a super block?
Super
block contains all the information about the file system like size of file
system, block size used by it,number of free data blocks and list of free
inodes and data blocks.
21: What is an inode block?
This
block contains the inode for every file of the file system along with all the
file attributes except its name.
22: How can I send a mail with a compressed file as an
attachment?
zip
file1.zip file1|mailx –s “subject” Recepients email id
Email content
EOF
Email content
EOF
23: How do we create command aliases in shell?
alias
Aliasname=”Command whose alias is to be created”
24: What are “c” and “b” permission fields of a file?
“c
“ and “b” permission fields are generally associated with a device file. It
specifies whether a file is a character special file or a block special file.
25: What is the use of a shebang line?
Shebang
line at top of each script determines the location of the engine which is to be
used in order to execute the script.
njoy the simplicity.......
Atul Singh
No comments :
Post a Comment