Showing posts with label Interview questions. Show all posts
Showing posts with label Interview questions. Show all posts

Tuesday, August 6, 2013

Advanced use of sed command                                                    useful tricks of sed command

UNIX is an open source operating system. It is a multiuser, multitasking operating system and developed in 1969 at AT & T’s laboratory. First, it was developed in assembly language but later it was recoded in ‘C’ language when this language developed by Dennis Ritchie. Actually, Unix is not an operating system, it is trademark which we use to say, is it unix like operating system or not. i.e. any operating follows the protocol which open group created for unix, it can be called as Unix operating system. E.g. BSD, HP-AX, Sequent, AIX.

Let’s talk about UNIX interview questions and its answers:

  • What is the difference between Linux and UNIX?

Ans -- If any operating system follows the UNIX protocols then we can say that it is a unix operating system. E.g. BSD, HP-AX etc. In case of Linux, actually Linux is a kernel which is most important part of operating system. Operating system comprised kernel, device drivers, desktop, other application etc. so, Linux is not an operating system, it is just a kernel which operating system uses like Red hat Linux, Open Suse etc. These operating system uses Linux kernel so, we can say that these operating systems are Linux.

  • Which command can we use to rename the file in Unix?

Ans -- In unix, there is no separate command to rename the file. We have to use ‘mv command’ to rename the file as below.
root@hello:~/hello/test# ls
fil5  file1  file2  file3  file4  test1
root@hello:~/hello/test#
root@hello:~/hello/test# mv file4 rename_file4
root@hello:~/hello/test# ls
fil5  file1  file2  file3  rename_file4  test1
root@hello:~/hello/test#

Use of command:
mv source_file destination_file

  • What is sed?

Ans -- Sed is a stream editor used to parse and transform the text. Sed does specified operations line by line on each line of input file or stream. Sed script either command line script or separate file.

  • Is sed command edit file?

Ans -- Yes. Sed command can edit the file. But this feature is available in Linux like operating only. This feature is not available in Solaris.

  • What is alias and how to do it? What is the use of it?

Ans -- Alias used to map some letters to specific command and instead of running that command, just type those letters. Please see below example to map ‘ls –l’ command to ‘ll’ letters.

root@01hw394566:~/ctier/test# alias
alias ls='ls --color=auto'
root@01hw394566:~/ctier/test#
root@01hw394566:~/ctier/test# alias ll='ls -l'
root@01hw394566:~/ctier/test# alias
alias ll='ls -l'
alias ls='ls --color=auto'
root@01hw394566:~/ctier/test#
root@01hw394566:~/ctier/test# ll
total 4
-rw-r--r-- 1 root root  0 2013-07-30 20:09 fil5
-rw-r--r-- 1 root root  0 2013-07-30 20:09 file1
-rw-r--r-- 1 root root  0 2013-07-30 20:09 file2
-rw-r--r-- 1 root root  0 2013-07-30 20:09 file3
-rw-r--r-- 1 root root  0 2013-07-30 20:09 rename_file4
-rw-r--r-- 1 root root 20 2013-07-30 20:09 test1
root@01hw394566:~/ctier/test#

  • Which daemons are running for NFS service?

Ans -- There are many NFS service daemons are running when we start the service. These daemons as follows:
Nfs
Nfsblock
Rpcbind
Rpc.mountd
Rpc.nfsd
Lockd
Rpc.statd
Rpc.rquotad
Rpc.idmapd

  • What is NFS port number and main configuration file?

Ans -- NFS service is using 2049 port and its main configuration file is /etc/exports.

  • What is port number for https?

Ans -- Https port number is 443.

  • How to strip all html tags from a file using sed command?

Ans – please find below example for stripping all html tags from a file using sed command.

root@01hw394566:~/ctier/test# cat test.html
<html>
<body>
<b>
Hello, Linux Administrator...!!!
</b>
</body>
</html>
root@01hw394566:~/ctier/test# sed -e 's/<[^>]*>//g' test.html



Hello, Linux Administrator...!!!



root@01hw394566:~/ctier/test# sed -e 's/<[^>]*>//g' -e '/^$/ d' test.html
Hello, Linux Administrator...!!!
root@01hw394566:~/ctier/test#

If you have seen in above example, we see that after stripping html tags, there are blank lines as it is. That’s why, we have used sed again to strip all blank lines.

  • What is inode?

Inode is a data structure found in unix file system. Each inode stores all the information about a file system object except data content and file name. We can see any file’s inode by command as “ls –i file name”. Inode is a unique in a file system. Inode contains following information:
File Type
Permissions (read, write, execute)
Owner
Group
File Size
File access, change, modification time
File deletion time
Number of links
Access control list

  • How do I see a inode number of file?

Ans – Please see below example.

root@01hw394566:~/ctier/test# ls –li
total 8
1206521 -rw-r--r-- 1 root root  0 2013-07-30 20:09 fil5
1206512 -rw-r--r-- 1 root root  0 2013-07-30 20:09 file1
1206515 -rw-r--r-- 1 root root  0 2013-07-30 20:09 file2
1206516 -rw-r--r-- 1 root root  0 2013-07-30 20:09 file3
1206559 drwxr-xr-x 2 root root 4096 2013-08-05 21:39 how
1206517 -rw-r--r-- 1 root root  0 2013-07-30 20:09 rename_file4
1206556 -rw-r--r-- 1 root root 20 2013-07-30 20:09 test1
1206560 -rw-r--r-- 1 root root 72 2013-08-05 20:22 test.html
root@01hw394566:~/ctier/test#

  • How to check port is open or not in Unix?

Ans— We can check port is open or not in Unix by netstat command. Please see below example for checking for port 80.
root@01hw394566:~/ctier/test# netstat -aeen | grep -w 80
tcp        0      0 127.0.0.1:80            0.0.0.0:*               LISTEN      0          8817
root@01hw394566:~/ctier/test#

If you see port 80 is tcp port. We have used double e option to get more detailed information about this port.
If you want to read more interview questions for Linux Administrator then click on below Link.
If you want to read more about shell scripting interview questions then click on below link:

Shell scripting interview questions and answers
Posted by Machindra Dharmadhikari On 8/06/2013 01:17:00 AM 5 comments READ FULL POST

Friday, May 10, 2013

Difference between SAN and NAS                                Netstat Command in Linux

1.       What are the run levels?
There are total seven run levels as follows:
0 – halt
1—single user mode
2—multiuser mode without NFS
3—Multiuser with NFS
4 -- Unused
5 -- Multiuser mode with X11.
6 – Reboot.

2.       How to check all logged in user currently on server?
Ans.  W and who are the commands to check all logged in users on server. There many different commands to check this but mostly used w or who or finger.
root@rhel:~/rhel/shellscript# w
 01:17:45 up 12 days,  6:43,  3 users,  load average: 0.03, 0.04, 0.05
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
nielsen2 pts/0    10.136.26.166    Wed20    3days  1.05s  0.69s -bash
nielsenpts/1    10.136.26.227    01:05    0.00s  0.62s  0.07s sshd: nielsen [priv]
nielsen2 pts/2    10.136.26.92     Wed20    4days  0.43s  3.39s sshd: nielsen2 [priv]
root@rhel:~/rhel/shellscript#
root@rhel:~/rhel/shellscript# who
nielsen2 pts/0        2013-04-24 20:24 (10.136.26.166)
nielsenpts/1        2013-04-30 01:05 (10.136.26.227)
nielsen2 pts/2        2013-04-24 20:26 (10.136.26.92)
root@rhel:~/rhel/shellscript# finger
Login     Name       Tty      Idle  Login Time   Office     Office Phone
nielsen   Nielsen   *pts/1          Apr 30 01:05 (10.136.26.227)
nielsen2             pts/0      3d  Apr 24 20:24 (10.136.26.166)
nielsen2            *pts/2      4d  Apr 24 20:26 (10.136.26.92)
root@rhel:~/rhel/shellscript#

3.       What is the difference between soft link and hard link?
Ans. Soft link also called as Symbolic link. Soft link means link the new file to original file without copying whole file to new location. And New files size will be the characters in filename of original file. If you want to get detailed difference then click on next link: Difference between Soft Link and Hard Link.

4.       How to change hostname permanently for server?
Ans. Generally, we are changing hostname from `hostname command` but this is not the way to change the hostname permanently. You should have to open the file `/etc/sysconfig/network` and change the hostname parameter of this file and then restart the network service.

5.       What is the command to convert dos file into unix format ?
Ans. `dos2unix` command is generally used for convert dos file into unix format and `unix2dos` command is used to vice versa.
6.       On which port DNS server is running ?
Ans. 53 Port .
7.       How to get the lines which matches pattern and 4 lines after the matched pattern ?
Ans. We can use grep command to get 4 lines after matched pattern.
root@rhel:~/rhel/shellscript# cat /etc/passwd | grep -nA 4 root
1:root:x:0:0:root:/root:/bin/bash
2-daemon:x:1:1:daemon:/usr/sbin:/bin/sh
3-bin:x:2:2:bin:/bin:/bin/sh
4-sys:x:3:3:sys:/dev:/bin/sh
5-sync:x:4:65534:sync:/bin:/bin/sync
root@rhel:~/rhel/shellscript#

To get 4 lines before the matched pattern:
root@rhel:~/rhel/shellscript# cat /etc/passwd | grep -nB 4 snmp
45-jenkins:x:120:65534::/var/lib/jenkins:/bin/bash
46-bind:x:121:131::/var/cache/bind:/bin/false
47-nagios:x:122:132::/var/lib/nagios:/bin/false
48-guest-ZI4XVo:x:123:133:Guest,,,:/tmp/guest-ZI4XVo:/bin/bash
49:snmp:x:124:134::/var/lib/snmp:/bin/false
root@rhel:~/rhel/shellscript#

8.       How to create 10 files in single command?
Ans.  You can use 10 different names after touch command.
root@rhel:~/rhel/shellscript/test# touch test{1..10}
root@rhel:~/rhel/shellscript/test# ls
test1  test10  test2  test3  test4  test5  test6  test7  test8  test9
root@rhel:~/rhel/shellscript/test#

9.       Find commans syntax to find the file by inodenumber ?
Ans. as follows:
root@rhel:~/rhel/shellscript# ls -li
total 32
5644165 -rw-r--r-- 1 root root 4922 2013-04-17 20:02 bid.log
5644164 -rwxr-xr-x 1 root root  479 2013-04-24 22:27 shellscript.sh
5770666 drwxr-xr-x 2 root root 4096 2013-04-30 01:42 test
5644159 -rw-r--r-- 1 root root 2173 2013-04-17 17:50 test1.log
5644160 -rwxr-xr-x 1 root root  353 2013-04-16 20:04 test1.sh
5644161 -rwxr-xr-x 1 root root  514 2013-04-16 18:30 test2.sh
5644117 -rw-r--r-- 1 root root 1731 2013-04-17 17:55 test.log
root@rhel:~/rhel/shellscript# find . -inum 5644164
./shellscript.sh
root@rhel:~/rhel/shellscript#

10.   Find command syntax to get files accessed within last 30 days:
Ans:
root@rhel:~/rhel/shellscript#
root@rhel:~/rhel/shellscript# find . -type f -atime -30
./test2.sh
./bid.log
./test/test1
./test/test9
./test/test5
./test/test6
./test/test10
./test/test4
./test/test2
root@rhel:~/rhel/shellscript#

Check CPU usage in Linux                                              Usermod command in Linux
Posted by Machindra Dharmadhikari On 5/10/2013 09:27:00 AM 5 comments READ FULL POST
  • RSS
  • Delicious
  • Digg
  • Facebook
  • Twitter
  • Linkedin
  • Youtube

    Chitika Ads 2

    Histat

    About

    Enter your email address:

    Delivered by FeedBurner