ALL ABOUT LINUX  and useful COMMANDS

1)    How devices are represented in Linux?
ANS: All devices are represented by files called special files that are located in /dev directory. Thus, device files and other files are named and accessed in the same way. A 'regular file' is just an ordinary data file in the disk. A 'block special file' represents a device with characteristics similar to a disk (data transfer in terms of blocks). A 'character special file' represents a device with characteristics similar to a keyboard (data transfer is by stream of bits in sequential order).

2)    What is I-Node?
ANS: An inode is a data structure on a filesystem on Linux and other Unix-like operating systems that stores all the information about a file except its name and its actual data. A directory (referred to as a folder on some operating systems) in Unix-like operating systems is merely a special type of file that associates file names with a collection of inodes.
Every object on the file system is assigned a unique index, called an I-node.
All UNIX files have its description stored in a structure called 'inode'. The inode contains info about the file-size, its location, time of last access, time of last modification, permission and so on. Directories are also represented as files and have an associated inode. In addition to descriptions about the file, the inode contains pointers to the data blocks of the file. If the file is large, inode has indirect pointer to a block of pointers to additional data blocks (this further aggregates for larger files). A block is typically 8k.
Inode consists of the following fields:

1.    File owner identifier
2.    File type
3.    File access permissions
4.    File access times
5.    Number of links
6.    File size
7.    Location of the file data
NOTE: command to see inode for a file is - > (ls –id)

3)    What are the booting phases in RHEL?
ANS: Booting process : first BIOS loads the boot loaders, then boot loaders loads the kernel , then kernel mount the file systems and drivers installation will takes place and in it will be loaded.

4)    What are the commands available to check the System Kernel Version?
ANS: “uname -a” ; “cat /proc/version”.

5)    What is the command to check which UNIX flavor is installed?
ANS: “cat /etc/issue”

6)    How do you verify the log for boot message?
ANS: cat /var/log/message ; dmesg

7)    What are the different RAID levels available in RHEL?
ANS: RAID0, RAID1, RAID4, RAID5

8)    What are the different file systems available on RHEL?
ANS: ext2, ext3, hpfs, reiserfs, xfs

9)    How we can create a snapshot in RHEL?
ANS: “lvcreate -L10M -s -n snapbackup /dev/VolGroup00/LogVol00”; "mkdir /mnt/snapbackup" ; "mount /dev/VolGroup00/snapbackup /mnt/snapbackup/"

10)    How we can create a partition on a disk?
ANS: using command “fdisk”

11)    How we can format a disk into different file system?
ANS: “mkfs –t ext3 /dev/hdc01”

12)    What is the command to mount/dismount a volume?
ANS: “mount /dev/VolGroup00/snapbackup /mnt/snapbackup/”; “umount –force /dev/VolGroup00/snapbackup”

13)    What is the command to mount a “cifs” volume?
ANS: “mount -t cifs -o username=ajitesh,password= ///ajitesh /mnt/win”

14)    What is LVM?
ANS: Logical Volume Manager

15)    What is the command to check the file system and repair them?
ANS: fsck

16)    How do you check the disk usage by file/directory?
ANS: du

17)    What is the command to check the size of partition and available/used disk space?
ANS: df –h

18)    What is the command to see the current working directory?
ANS : pwd

19)    What is the command to list directory entries with all hidden files?
ANS: ls –a

20)    What is the command to list directory entries with i-nodes?
ANS: ls –li

21)    What is tee command?
 ANS: tee command reads standard input and copies it to both standard output and one or more files. E.g. ls -ltr | tee ls.txt | grep test (the command will send the output of ls to ls.txt file and also it will provide output to grep)

22)    What is the difference between /etc/fstab file /etc/mtab file?
ANS: fstab lists all the devices (typically hard disk partition and NFS/CIFS volume to be mounted at boot time, whereas the mtab file lists the dynamic list of mounted file system.

23)    Which file lists all the devices (typically hard disk partition) that are to be mounted at boot time?
ANS: /etc/fstab

24)    What is the difference between ext3 and ext2 file system?
ANS: ext3 is the advanced version of ext2 file system its journalized file system and are less prone to file corruption.

25)    How to copy blocks of data from one device to another device?
ANS: dd if=/dev/sda of=/dev/sdc

26)    What is the command to check integrity of the data?
ANS: md5sum –c

27)    What is the System Partition ID for type “Swap” and for “Linux”?
ANS: 82 for swap ; 83 for linux

28)    What are the different Linux file types available?
ANS: (-)Regular file, (l)Symbolic link, (c)Character special, (b)Block special, (p)Named pipe, (s)Socket, (d)Directory file

29)    What are the different commands available for LVM?
ANS: To see Logical volume on a linux box -> lvdisplay ; To reduce the size -> lvreduce /dev/vol/myvol -L 200M ; To resize -> resize2fs /dev/vol/myvol 200M

30)    How to create a RAID?
ANS: mdadm --create /dev/md0 --level=5 --raid-devices=3 /dev/hde1 /dev/hdf2 /dev/hdg1

31)    How do you tell the OS for new partition created? or how to update the OS for new partition created?
ANS: partprobe /dev/had

32)    How do we check running process in the system?
ANS: “ps” or “top”

33)    What is the difference between “ps” and “top” command?
ANS: ps display static information of process running, top command displays dynamic information of running process.

34)    Command to kill a process?
ANS: kill ( - 9 To forcefully kill a process)

35)    What is the default signal sent by kill command?
ANS: TERM (terminate -15)

36)    What are the different types of processes?
ANS: Running (R), Sleeping (S), Uninterruptable sleep (D), Stopped (T), Zombie (Z), A high priority process (<), A low priority process (N)

37)    What is the command to display running process in background?
ANS: job

38)    What is the command to make a program to execute on background?
ANS: “ & ”

39)    What is “Zombie”?
ANS: Zombie is a defunct process; this is child process that has terminated, but has not cleaned up by its parent process.

40)    What is the command to send signal to kill multiple process?
ANS: killall

41)    What is the command to change the priority of running process?
ANS: nice for new process and for changing existing process priority: renice

42)    What is the different file/directory permission available?
ANS: (r)-Read, (w) Write, (x)-Execute

43)    What is the Search command for files and directories?
ANS: find /root -type l -name "test*"

44)    What are Symbolic Links? OR What are Hard Link and Soft Link?
ANS: Symbolic links are ways of creating references to files and directories by different name, Symbolic links are of type Hard Link and Soft Link, Hard links can be created using command “ln ” and Hard link has the same inode, it cannot be reference to directories and files in another filesystem/partition. Soft link is created with command “ln –s ” and has different Inode and can be reference to file and directories residing on different filesystem/partition. In hard link when original file is deleted Reference files can be still accessed but in Soft link if original file is deleted the reference file becomes unusable and only a dangling link is present called broken link.
Softlink is displayed as: lrwxrwxrwx  1 root root   18 Jul 29 13:57 install_SL -> install.log.syslog

45)    What are “SUID” and “GUID”?
ANS: “SETUID” and “GUID” enables a user to run a command or application with the permissions of another; it inherits the privileges of the USER and GROUP owned, to set UID or GID use the following command:  “chmod o+s filename” or “chmod g+s filename”, the files with set UID or GID is listed as “-r-sr-xr-x”


46)    What is “Sticky Bit”?
ANS: “Sticky Bit” enables only user to delete the files owned by them from world writable shared directories. The “sticky bit” can be set using command: “chmod u+t SHAREDFOL” or “chmod 1777 SHAREDFOL” and the sticky bit folders are displayed through “ls” command as “drwxrwxrwt”.

47)    How to change user/group ownership of a file/directory?
ANS: chown owner fname, chgrp -> group fname

48)    What is umask?
ANS: When a new file is created default permission are set on the file by the system on basis of individual file creation mask, to see the mask type “umask”, default mask is 022 to set new mask type command “umask 027”

49)    How to change file permission?
ANS: chmod 775 filename (4-r, 2-w, 1-x)

50)    What is the command used for using /etc/shadow file to store password?
ANS: The command “pwconv” creates /etc/shadow file only accessible to “root” user and it stores encrypted password and makes ”x” in the /etc/passwd file. To revert back use the command “pwunconv”.

51)    What is the difference between “sudo” and “su” command?
ANS: SU command is used to run a shell as a different user, SUDO command is used to run a command as different user.

52)    When I am trying to change password of a specific user I am unable to do so what is the reason?
ANS: The first column of /etc/passwd file is set to “0” in front of the user.

53)    How do you find UID and GID of a specific user?
ANS: id root

54)    How to create missing parent directory?
ANS: mkdir –p /usr/local/tmp/tmp1

55)    How to change password aging setting in /etc/shadow file?
ANS: chage

56)    What is the command to check the network device in use?
ANS: ifconfig ; netstat –ie

57)    Which command is used to change the hostname?
ANS: hostname

58)    Which file is used to set the DNS setting?
ANS:/etc/resolv.conf

59)    Where do you find configured network device info?
ANS: /etc/sysconfig/network-scripts/

60)    What is bash_profile file used for?
ANS: This file is used for storing user related environment variables.

61)    Which folder contains skeleton for user files to be created in home directory when new user is created?
ANS: /etc/skel

62)    What is the default location for user environmental variables?
ANS: /etc/profile

63)    What are the different files available for user environmental variables?
ANS: .bash_profile, .bash_login, .profile.

64)    What is the command to set path?
ANS:  # export PATH=/usr/local

65)    What is the command to see the environmental path?
ANS: # env

66)    What are the different run levels available in Linux system?
ANS:  0:Halt, 1:Single User Mode, 2:Multiuser w/o networking, 3:Multiuser with network, 5:Graphical, 6:Reboot

67)    What is the command to query the run-level for a service?
 ANS: “chkconfig --list sshd”

68)    What is the command to modify the run level of a service? 

ANS: “chkconfig [--level <1>]

69)    What is the command to modify the runlevel on runtime?
ANS: telinit 3

70)    Which file lists all the runlevel of the configured in the system?
ANS: /etc/inittab

71)    What are the different RPM commands
ANS: To install software using – rpm –ivh
To install forcefully – rpm –force –ivh
To upgrade software – rpm –Uvh
To query installed software – rpm –qa

72)    What daemon is responsible for tracking events on your system?
ANS: syslogd

73)    You need to view the contents of the tarfile called MyBackup.tar. What command would you use?
ANS: tar -tvf MyBackup.tar

74)    You need to compress a file/folder to a tarfile called MyBackup.tar. What command would you use?
ANS: tar -cvf MyBackup.tar

75)    You need to extract files/folder from a tarfile called MyBackup.tar. What command would you use?
ANS: tar -xvf MyBackup.tar

76)    You need to see the last fifteen lines of the files abc.txt, xyz.log. What command should you use?
ANS: tail -15 -f abc.txt xyz.log

77)    In order to improve your system's security you decide to implement shadow passwords. What command should you use?
ANS: pwconv, The pwconv command creates the file /etc/shadow and changes all passwords to 'x' in the /etc/passwd file.

78)    You attempt to use shadow passwords but are unsuccessful. What characteristic of the /etc/passwd file may cause this?
ANS: The password field is blank

79)    In order to prevent a user from logging in, what you can do? OR User is created and user is present in the /etc/passwd file but user is unable to login what could be the problem?
ANS: asterick at the beginning of the password field in the /etc/passwd file. Also to prevent user from login we can use :passwd -l with the username to lock his account.

80)    You issue the following command useradd -m bobm But the user cannot logon. What is the problem?
ANS: The useradd command does not assign a password to newly created accounts. You will still need to use the passwd command to assign a password.


81)    What utility can you use to automate rotation of logs?
ANS: logrotate, The logrotate command can be used to automate the rotation of various logs.

82)    What command can you use to review boot messages?
ANS: dmesg

83)    What is the name and path of the main system log?
ANS: /var/log/messages

84)    Which daemon is used for scheduling of the commands?
ANS: The crontab command is used for scheduling of the commands to run at a later time. SYNTAX
crontab [ -u user ] file
crontab [ -u user ] { -l | -r | -e }
Options:
-l List - display the current crontab entries.
-r Remove the current crontab.
-e Edit the current crontab using the editor specified by the VISUAL or EDITOR environment variables.
When user exits from the editor, the modified crontab will be installed automatically. Each user can have their own crontab, and though these are files in /var, they are not intended to be edited directly. If the –u option is given than the crontab gives the name of the user whose crontab is to be tweaked. If it is given without this then it will display the crontab of the user who is executing the command.


85)    How environment variable is set so that the file permission can be automatically set to the newly created files?
ANS: umask command is used to set file permission on newly created files automatically.
Syntax
umask [-p] [-S] [mode]
It is represented in octal numbers. We can simply use this command without arguments to see the current file permissions. To change the permissions, mode is given in the arguments. The default umask used for normal user is 0002. The default umask for the root user is 0022. For calculating the original values, the values shown by the umask must be subtracted by the default values. It is mainly used for masking of the file and directory permission. The /etc/profile script is where the umask command is usually set for all users. The –S option can be used to see the current default permissions displayed in the alpha symbolic format.
For example, umask 022 ensures that new files will have at most 755 permissions (777 NAND 022).
The permissions can be calculated by taking the NAND of original value with the default values of files and directories. 

86)    Which command utility helps to view a compress files contents without first having to decompress it?
ANS: zcat

87)    If we need to we need to enlarge the partition in future what can be the best practice?
ANS: we can use LVM partitions, LVM partitions can be used to enlarge to reduce the partitions

88)    Which command do you use to change run levels?
ANS: init

89)    Which crontab command will display all scheduled cron jobs for all users?
ANS: crontab -l

90)    You have made changes to the /etc/syslog.conf file. Which of the following commands will cause these changes to be implemented without having to reboot your computer?
ANS: kill SIGHINT `cat /var/run/syslogd.pid`, When you use kill with the SIGHUP signal, it stops the daemon, rereads the /etc/syslog.conf file, and then starts the syslogd daemon. The last part of the command line extracts the PID for syslogd.

91)    Which daemon must be running in order to have any scheduled jobs run as scheduled?
ANS: crond

92)    Which two utilities can you use to set up a job to run at a specified time?
ANS: at and crontab, at command to schedule a job to run once, crontab command is used to schedule recurring jobs.

93)    What is difference between RAID & LVM?
ANS:RAID is “Redundant Array of Independent Disks”. Think of it in simplest terms, with say RAID and if you have RAID1 setup with two disks, they basically mirror one another.
Disk 1 has 5 partitions and Disk 2 has the same setup. If Disk 1 has a partition failure on say hda2, Disk 2 will pick up and take over.
Its redundant array of disks for better reliability. In more simply terms, both of those disks will mirror one another, so the data is in two locations instead of just one.
LVM on the other hand is a way to spread data or partitions across multiple disks or partitions, etc. Say you have two hard drives, each 80GB, you could with LVM make it look and act like one big disk, instead of having two disks.
RAID is designed for system reliability. Other than RAID0 which is used to make multiple disks appear as one big one, all RAID levels ensure that loss of a disk will not lead to data loss or system crash.
LVM is RAID0 in that you put together multiple disks into one or more volume groups. Then within each volume group you create logical volumes where you build your file systems. The real power of LVM is that if you have unallocated space in your volume group, then you can unmount a logical volume, extend it in size, extend the file system and then remount the logical volume. In the event, that you don’t have free space in the volume group, you can add more disks to your system, use them to extend the volume group’s size and then extend the logical volumes. If you don’t use LVM and you need a filesystem to be bigger, then your only choice is to unmount the filesystem, back it up to tape, resize the partition, and then restore. Depending on the sizes this could take quite awhile.
LVM and RAID solve two different problems, and should be used to provide maximum reliability and maximum flexibility.
LVM is logical volume manager and is used to extend the logical volume if required. It can be max to the size of disk or physical partition.
   
94)    How do you create special files like named pipes and device files?
ANS: The system call mknod creates special files in the following sequence.
•    kernel assigns new inode,
•    sets the file type to indicate that the file is a pipe, directory or special file,
•    If it is a device file, it makes the other entries like major, minor device numbers.
For example:
If the device is a disk, major device number refers to the disk controller and minor device number is the disk.

95)    How to copy entire directory from remote system using scp command to current directory?
ANS: scp -r root@192.168.1.100:/usr/data .

96)    How to setup Password less remote login/ssh?
ANS: Use “ssh-keygen -t dsa or rsa” at local system for creating public and private keys
Then copy /root/.ssh/id_dsa.pub to remote_server by name /root/.ssh/authorized_keys
Change permissions of /root/.ssh/authorized_keys file at remote_server “chmod 0600 ~/.ssh/authorized_keys”
Now try to login from local system to remote_server “ssh root@remote_server”

97)    What are block and character devices?
ANS: Both the devices are present in /dev directory
Block device files talks to devices block by block [1 block at a time (1 block = 512 bytes to 32KB)].
Examples: – USB disk, CDROM, Hard Disk (sda, sdb, sdc etc….)
Character device files talk to devices character by character.
Examples: – Virtual terminals, terminals, serial modems, random numbers (tty{0,1,2,3……})Cd

98)    How to Convert ext2 to ext3 File System?
ANS: tune2fs -j /dev/{device-name}Sdfs

99)    Which file in Linux stores services and respective port numbers?
ANS: /etc/services

100)    How do you find how many cpu are in your system and there details?
ANS: By looking into file /etc/cpuinfo for example you can use command: cat /proc/cpuinfo

101)    How do you find for how many days your Server is up?
ANS: By using uptime command in UNIX

102)    You have an IP address in your network how will you find hostname and vice versa?
ANS: By using nslookup command in UNIX

103)    How to setup Password less remote login/ssh?
ANS: Use "ssh-keygen -t dsa or rsa" at local system for creating public and private keys
        Then copy /root/.ssh/id_dsa.pub to remote_server by name /root/.ssh/authorized_keys
 Change permissions of /root/.ssh/authorized_keys file at remote_server "chmod 0600 ~/.ssh/authorized_keys"
Now try to login from local system to remote_server "ssh root@remote_server"

104)    What the Difference is between block and character device?
ANS: $ ls -altr /dev/
brw-rw----  1 root disk    8,   6 2010-07-26 14:20 sda6          --> block device
crw-rw----  1 root root   10,  59 2010-07-26 14:21 device-mapper --> character device
 

Character devices deal with IO on a character by character basis. The most obvious example is a keyboard, where every key generates a character on the device. The mouse is another. Every motion or button click sends a character to the /dev/input/mouse0 device. To test it out do   $cat /dev/input/mouse0 , then move your mouse (see what happens)

Block devices read data in larger chunks or blocks. Data storage devices, such as IDE hard drives (/dev/hd), SCSI hard drives (/dev/sd), and CD-ROMs (/dev/cdrom or /dev/sr0) are block devices. IO interactions with block devices transact with chunks of data (blocks), which allows large quantities of data to be moved back and forth more efficiently(unlike character device). eg:  $df  -h
Generically, block devices can be mounted and are cached, and char devices are for communication devices, aren’t cached nor block aligned, and can’t be mounted.
Specifically, /dev/scd* (block) are for cdroms, providing the block access and commands for ejecting, closing, playing, etc.
The corresponding character device for the cdrom is /dev/sg1

105)    How to configure crash dump and What is the location of crash dump file in Linux(redhat)?
ANS: 1) Install kexec-tools package
2) Verify the service is running - kdump (chkconfig kdump on; service kdump start; service kdump status)
3) Simulate the crash - echo 1 > /proc/sys/kernel/sysrq, echo c > /proc/sysrq-trigger
4) ls /var/crash - /var/crash/127.0.0.1-2010-08-25-08:45:02/vmcore linux-image-3.0.0-12-server.0.crash

106)    How to analyze the core dump?
ANS: 1) yum install crash
2) debuginfo-install kernel
3) Run the crash utility - crash /usr/lib/debug/lib/modules/2.6.32-69.el6.i686/vmlinux \
/var/crash/127.0.0.1-2010-08-25-08:45:02/vmcore

107)    What is the daemon service which monitors the events? and on which location the log is generate?
ANS: “syslogd” is the daemon service and /var/log/message is generated using the configuration file -/etc/syslog.conf

108)     What is the command to see the content of RPM package?
ANS: rpm -qpl (q=querry;p=package name; l=listing)

109)    How to extract an RPM Package without installing it?
ANS: rpm2cpio myrpmfile.rpm | cpio -idmv
 i: Restore archive
 d: Create leading directories where needed
m: Retain previous file modification times when creating files
v: Verbose i.e. display progress

110)    How to configure ip address as static and dhcp in linux?
ANS:     1)DHCP - iface eth0 inet dhcp
2)Static - iface eth0 inet static \
address 192.168.1.1
netmask 255.255.255.0
gateway xx.xx.xx.xx

111)     How to see memory usage in Linux?
ANS:  cat /proc/meminfo ;  free –m;  vmstat ;  top

112)    What are LVM1 and LVM2?
ANS: LVM1 and LVM2 are the versions of LVM.
LVM2 uses device mapper driver contained in 2.6 kernel version.
LVM 1 was included in the 2.4 series kernels.

113)    What is the maximum size of a single LV?
ANS: For 2.4 based kernels, the maximum LV size is 2TB.
For 32-bit CPUs on 2.6 kernels, the maximum LV size is 16TB.
For 64-bit CPUs on 2.6 kernels, the maximum LV size is 8EB.

114)    What are the important LVM related files and Directories?
ANS: ## Directories
/etc/lvm                - default lvm directory location
/etc/lvm/backup         - where the automatic backups go
/etc/lvm/cache          - persistent filter cache
/etc/lvm/archive        - where automatic archives go after a volume group change
/var/lock/lvm             - lock files to prevent metadata corruption
# Files
/etc/lvm/lvm.conf       - main lvm configuration file
$HOME/.lvm              - lvm history

115)    What are the steps to create LVM in Linux?
ANS: Create a physical volume by using pvcreate command, consider the disk is local.
#fdisk -l
#fdisk /dev/sda
Press "n" to create new partition. And mention the size / allocate whole disk to single partition. and assign the partition number also.
#press "t" to change the partition as LVM partition.
#enter "8e" ( 8e - is Hex decimal code for LVM )
#Enter "w" to write tghe information on Disk.
#fdisk -l ( Now you will get newly created disk numbers)
#pvcreate /dev/sda2

Add physical volume to volume group by “vgcreate” command
#vgcreate VLG0 /dev/sda2

Create logical volume from volume group by “lvcreate” command.
#lvcreate -L 1G -n LVM1 VG0

Now create file system on /dev/sda2 partition by “mke2fs”  or "mkfs.ext3" command.
#mke2fs -j /dev/VG0/LVM1
or
#mkfs.ext3 /dev/vg0/LVM1

Now mount this as file system
#mkdir /test
#mount /dev/VG0/LVM1 /test 

116)     How to extend a File system in Linux?
ANS: Check the free space on vg
#vgdisplay -v VG1
Now extend the FS
# lvextend -L+1G /dev/VG1/lvol1
# resize2fs /dev/VG1/lvol1

117)    How to reduce the File system size in Linux?
ANS: 1.First we need to reduce the file system size using "resize2fs"
2.Then reduce the lvol size using "lvreduce"
#resize2fs -f /dev/VolGroup00/LogVol00 3G
#lvreduce -L 5G /dev/VG1/Lvol1

118)    How to find server is configured with LVM RAID ?
ANS:
1.How to check linux LVM RAID ?
 check the RAID status in /proc/mdstat

 #cat /proc/mdstat
 or
 # mdadm --detail /dev/mdx
 or
 # lsraid -a /dev/mdx

2.Check the Volume group disks
 #vgdisplay -v vg01
 In disk we will get the device names like /dev/md1 , /dev/md2 . It means LVM RAID disks are configured and its added to Volume Group.

119)     What is Journaling file system?
ANS: A journaling file system is a file system that keeps track of the changes it intends to make in a journal (usually a circular log in a dedicated area of the file system) before committing them to the main file system. In the event of a system crash or power failure, such file systems are quicker to bring back online and less likely to become corrupted.

120)    How to see how long the system has been running since it was booted up?
ANS: uptime

121)    How to get the linux kernel version?
ANS: uname -r OR cat /proc/version OR dmesg | grep Linux OR rpm -q kernel

122)    What are the classes of Network?
ANS: Class A - 1 to 126, Class B - 128 to 191 and Class C - 192 to 233. The 127 is reserved for loopback address.

123)    How to Find the Block Size?
ANS:  A block is a uniformly sized unit of data storage for a filesystem. Block size can be an important consideration when setting up a system that is designed for maximum performance.
Block size is selected at the time of high-level formatting, i.e., preparing the hard disk drive (HDD) or other media for creation of a filesystem. If the mke2fs (i.e., make ext2 filesystem) command is used to create the filesystem, valid block size vales are 1024, 2048 and 4096 bytes. If omitted, block size is determined by an algorithm that considers the size of the filesystem and how it is expected to be used.The block size for any existing ext2 or ext3 filesystem (which are the most common filesystem types on Linux) can be obtained by using the dumpe2fs command with the device name as an argument (i.e., input data). The device name is the partition or disk on which the filesystem resides. A partition is a logically independent section of an HDD. On most systems it will be necessary to be the root user (i.e., administrative user) in order to use dumpe2fs. On home computers and other systems for which the user has access to the root password, that user can become root by issuing the su (i.e., substitute user) command and then supplying the password as prompted. It will also likely be necessary to use the full pathname of dumpe2fs by adding /sbin to its beginning.
Thus, for example, to find the block size for the second partition of the first HDD, the following can be used:
/sbin/dumpe2fs /dev/hda2 | grep 'Block size'
Because dumpe2fs provides a large amount of information, it is convenient to use the filter grep to remove everything from the output except the block size. Because grep is case-sensitive and the word Block begins with an upper case (i.e., capital) B, it is necessary to use an upper case B in this command.

124)    Which command is used to see all the system configuration? like hardware, HDD, memory etc.
ANS: lspci -w
 

125)    What is difference between inetd and xinetd ?
ANS: The major difference between inetd and the newer xinetd is that inetd uses a single configuration file, with one line per service, while xinetd uses a configuration directory, with one file per service

126)    What is LILO?
ANS: LILO stands for Linux boot loader. It will load the MBR, master boot record, into the memory, which tell the system which partition and hard drive to boot.

127)    How to give 2 different gateway IP addresses for 2 different interfaces in same system ?
ANS:     route add -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.0.2 dev eth0
route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.0.3 dev eth1

128)    What is the minimum number of partitions you need to install Linux?
ANS:     / (root partition)
/boot (boot partition)
/swap (swap partition)

129)     How to check all open ports on linux machine and block unsed ports?
ANS:     open ports – nmap localhost
        block unsed ports -
        #nmap -v localhost for tcp
#nmap -sU localhost for udp

130)    What is the difference between Ext2, Ext3 and Ext4?
ANS: 

Ext2 stands for second extended file system.  It was introduced in 1993. Developed by Rémy Card. This was developed to overcome the limitation of the original ext file system. Ext2 does not have journaling feature.On flash drives, usb drives, ext2 is recommended, as it doesn’t need to do the over head of journaling. Maximum individual file size can be from 16 GB to 2 TB. Overall ext2 file system size can be from 2 TB to 32 TB

Ext3
Ext3 stands for third extended file system. It was introduced in 2001. Developed by Stephen Tweedie.  Starting from Linux Kernel 2.4.15 ext3 was available. The main benefit of ext3 is that it allows journaling. Journaling has a dedicated area in the file system, where all the changes are tracked. When the system crashes, the possibility of file system corruption is less because of journaling. Maximum individual file size can be from 16 GB to 2 TB Overall ext3 file system size can be from 2 TB to 32 TB There are three types of journaling available in ext3 file system. Journal – Metadata and content are saved in the journal. Ordered – Only metadata is saved in the journal. Metadata are journaled only after writing the content to disk. This is the default. Writeback – Only metadata is saved in the journal. Metadata might be journaled either before or after the content is written to the disk. You can convert a ext2 file system to ext3 file system directly (without backup/restore).

Ext4
Ext4 stands for fourth extended file system.It was introduced in 2008. Starting from Linux Kernel 2.6.19 ext4 was available. Supports huge individual file size and overall file system size. Maximum individual file size can be from 16 GB to 16 TB. Overall maximum ext4 file system size is 1 EB (exabyte). 1 EB = 1024 PB (petabyte). 1 PB = 1024 TB (terabyte). Directory can contain a maximum of 64,000 subdirectories (as opposed to 32,000 in ext3). You can also mount an existing ext3 fs as ext4 fs (without having to upgrade it). Several other new features are introduced in ext4: multiblock allocation, delayed allocation, journal checksum. fast fsck, etc. All you need to know is that these new features have improved the performance and reliability of the filesystem when compared to ext3.  In ext4, you also have the option of turning the journaling feature “off”


131)    How do we compare 2 different (binary) files if there contents are same?
ANS: We can use diff, cmp command.

The difference between these 2 commands are:
cmp
-Byte by byte comparison performed for two files comparison and displays the first mismatch byte.
-cmp returns the 1st byte and the line no of the 1st file to make the changes to make the 1st file identical to 2nd file.
-Directory names can not be used.

diff
-Line by line comparison performed for 2 files, Indicates the changes that are to be done to make the files identical.
-Returns the text of 1st file that is different from 2nd file.
-Directory names can be used


We can use diff  command : $ diff a.bin b.bin
Output:
4,5c4
< This is a test
< This is a test
---
> This is a test1

We can use cmp command : $cmp a.txt b.txt
Output:
/root/a.txt /root/b.txt differ: char 60, line 4

132)  What are the different ways of checking memory and cpu utilization by the process running on a Linux system and get a report every 5 seconds?

We can use "top", "free", "vmstat" command.

1. "free" displays the total amount of free and used physical and swap memory in the system, as well as the buffers used by the kernel. The shared memory column should be ignored; it is obsolete.
2. "vmstat" reports information about processes, memory, paging, block IO, traps, and cpu activity.
The first report produced gives averages since the last reboot. Additional reports give information on a sampling period of length delay. The process and memory reports are instantaneous in either case.

suse10:~ # vmstat 1
procs -----------memory---------- ---swap-- -----io---- -system-- -----cpu------
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 1  0      0 261584  53472 358084    0    0    90    17  264  304  0  1 97  2  0
 0  0      0 261584  53472 358084    0    0     0     0  270  213  0  0 100  0  0
 0  0      0 261584  53472 358084    0    0     0     0  253  212  0  0 100  0  0

 

No comments:

Post a Comment

/**/