Linux Commands Cheat Sheet
Linux Commands Cheat Sheet
Linux Commands Cheat Sheet
unix/linux ?
cd /directoryname - change directory
ls -ltr - list files
pwd - present working directory
touch - create an empty file
mkdir - create a new directory
rmdir - remove an empty directory
rm -rf - remove file forecefully and recursevily
chmod - change file/ directory persmissions
chown - change owner of the file or directory
================================
Explain ls command usage?
ls
1. How do you check the list of files and directories timestamp wise ?
ls -ltr
cd - command usage
cd - change directory
3. Go to last directory
cd -
4. Go to a particular directory
cd /etc
mkdir one
mkdir -p one/four/six
==
=
rmdir - command usage
rmdir : This command removes empty directories
Example:
rmdir dir1
rmdir -p dir1/subdir1
Examples of Cat :
Create a file :-
cat >testfile
Contents [hide]
1 – SYSTEM INFORMATION
2 – HARDWARE INFORMATION
3 – PERFORMANCE MONITORING AND STATISTICS
4 – USER INFORMATION AND MANAGEMENT
5 – FILE AND DIRECTORY COMMANDS
6 – PROCESS MANAGEMENT
7 – FILE PERMISSIONS
8 – NETWORKING
9 – ARCHIVES (TAR FILES)
10 – INSTALLING PACKAGES
11 – SEARCH
12 – SSH LOGINS
13 – FILE TRANSFERS
14 – DISK USAGE
15 – DIRECTORY NAVIGATION
1 – SYSTEM INFORMATION
# Display Linux system information
uname -a
# Display the last users who have logged onto the system.
last
# Create a directory
mkdir directory
PERMISSION EXAMPLE
U G W
rwx rwx rwx chmod 777 filename
rwx rwx r-x chmod 775 filename
rwx r-x r-x chmod 755 filename
rw- rw- r-- chmod 664 filename
rw- r-- r-- chmod 644 filename
LEGEND
U = User
G = Group
W = World
r = Read
w = write
x = execute
- = no access
8 – NETWORKING
# Display all network interfaces and ip address
ifconfig -a
# Download http://domain.com/file
wget http://domain.com/file
# Install package.
yum install package
# Remove/uninstall package.
yum remove package
14 – DISK USAGE
# Show free and used space on mounted filesystems
df -h
https://www.linuxtrainingacademy.com/linux-commands-cheat-sheet/
https://plsqlblog.blogspot.com/p/interview-questions.html
==
What is Linux?
Ans:Linux is an operating system, multitask GUI based open source
operating system developed by Linus Torvalds. We use the term
“Linux” refer to Linux kernel, Comprises the set of programs, tools,
and services that are typically bundled together with the Linux
kernel to provide all of the necessary components of a fully
functional operating system. Linux is most-used open source
operating system. Linux is a Multi Tasking , Multi User, Multi Process
operating system.
Linux Operating system is widely used in smartphones to cars,
supercomputers and home appliances.
1. Shell
2. Scripting
3. Kernel
4. Command
5. Terminal
Shell: A command process that allows you to control the computer
via commands typed into a text interface.
Scripting: A shell script is a computer program designed to be run
by the shell, a command-line interpreter.
Kernel: Kernel is the core of the system and manages the CPU,
memory, and peripheral devices.
Command:A command is an instruction given by a user telling a
computer to do something, such a run a single program or a group
of linked programs.
Terminal:The terminal is a container for the shell (or any other
program). It provides input (through connected input devices) and
displays output.
What is the basic difference between UNIX and Linux
Operating System?
Answer : Linux Operating System is Free and Open Source
Software, the kernel of which is created by Linus Torvalds and
community. UNIX Operating System doesn’t comes under the
category of Free and Open Source Software, BSD, is a variant of
UNIX which comes under the category of FOSS. Moreover Big
companies like Apple, IBM, Oracle, HP, etc. are contributing to UNIX
Kernel.
What is LILO?
LILO is Linux Loader is a boot loader for Linux. It is used to load
Linux into the memory and start the Operating system. LILO can be
configured to boot other operating systems as well.LILO is also a
code snippet which loads PC BIOS into the main memory at the time
of starting the computer system.
What is the advantage of Linux?
Every aspect comes with additional features and it provides a free
downloading facility for all codes.
What is BASH?
BASH is a short form of Bourne Again SHell. It was a replacement to
the original Bourne shell, written bu Steve Bourne
Read: User can read the file and list the directory.
To set SGID
* What are the process states in linux
* How to find out the linux kernel version and how to upgrade
kernel ?.
To check the kernel version use any of the following command.
[root@node213 ~]# uname -a
Linux node213.example.com 2.6.18-348.el5 #1 SMP Wed Nov 28
21:22:00 EST 2012 x86_64 x86_64 x86_64 GNU/Linux
[root@node213 ~]# uname -r
2.6.18-348.el5
[root@node213 ~]# cat /proc/version
Linux version 2.6.18-348.el5 (mockbuild@x86-
002.build.bos.redhat.com) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-
54)) #1 SMP Wed Nov 28 21:22:00 EST 2012
To upgrade the kernel , download the kernel rpm file and install it
using rpm -ivh
command. Don’t use rpm -Uvh, because it will upgrade the existing kernel and we
won’t able to go to the previous kernel version at any point of time. If we require
to remove the old kernel, use rpm -e and also remove the entry form
/etc/grub.conf file.
mnt
runlevel 4 – unused.
runlevel 5 – Graphical.
runlevel 6 – Reboot
device to mount mount point file system type mount options dump fscheck.
Mount Options :
ro – read only, rw – read write, user – user can mount, exec – script can be
execute, noexec – script can’t be execute, noauto – partition will not mount
synchronize.
Dumping is an outdated option for backup for cases when system went down, 0 –
stands for False and 1 – stands for true. Now a days we can leave this as 0.
fsck – This parameters is for file system check . The partitions will go for fsck
based on the order given. The / partition should have value 1 and next partitions
about that file system ) and inodes ( Which contains information about each files
Metadata contains the information about the entire data (one or more pieces of
data) , ie file name, owner,creation date, location etc. whereas inode is a type of
metadata which contains the information about a regular file, directory, or other
file system object such as permission, owner and group, file size, access and
modification time, number of links etc . Linux never store the file creation time.
Superblock is a filesystem metadata which defines the file system type, size,
very critiical to the file system and thus in each file system there may be multiple
copies of superblock. Incase superblock become corrupt and at that point of time
fsck will automatically select an alternate backup of the superblock and attempt
to recover the filesystem. For the manual recovery of superblock, we can use
superblocks are existing on the first sector of a filesystem. It contains the location
of inode table.
permissions to a user to run a program/file with the permissions of the file owner
rather that the user who runs it. In simple words users will get file owner’s
file/program/command.
The first s stands for SUID and second S stands for SGID.
2) Where you don’t want to give credentials of a particular user, but want to run some
programs as the owner.
3) Where you don’t want to use SUDO command, but want to give execute permission for a
file/script etc.
To set SUID
SGID permission is similar to the SUID permission, only difference is – when the
script or command with SGID on is run, it runs as if it were a member of the same
a) CPU utilization – To check CPU performance use the following commands,
1) top – It display CPU usage, Memory usage, Swap Memory, Cache Size, Buffer
2) vmstat – To display statistics of virtual memory, kernerl threads, disks, system
3) lsof – To display list of all the open files and the processes. The open files
included are disk files, network sockets, pipes, devices and processes.
program that is used capture or filter TCP/IP packets that received or transferred
5) netstat – A command line tool for monitoring incoming and outgoing network
packets statistics as well as interface statistics.
6) iotop – monitor and display real time Disk I/O and processes. This tool is
much useful for finding the exact process and high used disk read/writes of the
processes.
7) iostat – This will collect and show system input and output storage device
monitor that passes over the network, including TCP flag information, ICMP
also gathers information of general and detaled interface statistics of TCP, UDP,
9) sar – Sar is part of the sysstat package. Using sar utility you can do two
things: 1) Monitor system real time performance (CPU, Memory, I/O, etc) 2)
10) free – Free command displays information about the physical (RAM) and
b) RAM usage – free , cat /proc/meminfo, top, can be used to monitor memory
usage.
e) Network Checking
* What is Server hardening?
results in a much more secure server operating environment. Eg, System access
etc..
* How to scan and mount newly added LUN in RHEL without reboot?
Once after a new LUN connected to a Linux box through HBA card, we can run
finished the script execution, we can able to see the new LUN as raw disk through
fdisk utility.
/usr/bin/rescan-scsi-bus.sh
sg3_utils-1.28-4.el6.x86_64
The default UNIX kernel behavior is sub-optimal out of the box because it is
difficult to anticipate what type of work or workload the operating system will be
assigned. Therefore, UNIX products provide parameters that may change the
Eg. File Handling Limit – The kernel has built-in limits on the number of files that
66034
The NRPE ( Nagios Remote Plugin Executor ) agent will send all the alerts related
CPU load, Swap, Memory usage, Online users, etc. to the nagios monitoring
The xinetd stands for Extended Internet Services.The xinetd service listens on all
determines if the client is allowed access. If the client is allowed access, xinetd
403 represent forbidden error, means if a file misses some selinux security context.
404 represent that there is a cgi script missing or web pages missing.
* What is a zombie process?
Zombie often called process is a process state when the child dies before the
parent process. In this case the structural information of the process is still in the
process table
The syslogd daemon tracks all the events of linux server and
maintain the log files.
* What are the difference between hard links and soft links.
The first one is the user name (root) . Second field stands the password, x
indicates encrypted password in the /etc/shadow file. Third field is user id (UID),
UID 0 is assigned for root user and 1 to 499 is using by other predefined
accounts. Fourth field is the group id (GID) stored in /etc/group file. Fifth field is
the user ID info location where we can add users such as users full name,phone
number etc. . The sixth field is for user home directory . The last and seventh field
First field is the user name . Second field is the password which is in
encrypted format. Third field gives the number of days since Jan 1 1970 the
password was last changed. Fourth field stands for number of minimum days
which the user can change his password, 0 stands for user can change password
at any time. Fifth fields stands for the number of days after which password must
be changed. Sixth field stands for the number of days to warn the user of an
expiring password . Seventh field stands for the number of days the after
password expires the account is disabled . Eight field stands for the number of
days the since Jan 1 1970 that an account has been disabled. The nine field is
kept reserved for future use.
Network alias in linux allows us to add additional network address of
same subnet to a single network interface. Eg . eth0:0, eth0:1, etc.
luci is a service which presents the web based cluster interface via
https at port 8084. ricci service is the underlying daemon that that helps in cluster
configuration sync and file copy , cluster service stop start etc. .It uses tcp port
11111.
root_squash – If we are putting root_squash, then it will map root UUID/ GID to
anonymous UUID/GID. So in client side the client root user will be denied for
accessing, creating file in mounted NFS partition.
* From where we can find more information associated with your CPU
A port number is part of the addressing information used to identify the senders and receivers
of messages. Port numbers are most commonly used with TCP/IP connections. Home network
routers and computer software work with ports and sometimes allow you to configure port
number settings. These port numbers allow different applications on the same computer to share
network resources simultaneously.
Port numbers have a range of 0…65535 (although often 0 has special meaning). In the original
BSD TCP implementation, only root can bind to ports 1…1023, and dynamically assigned ports
were assigned from the range 1024…5000; the others were available for unprivileged static
assignment. These days 1024…5000 is often not enough dynamic ports, and IANA has now
officially designated the range 49152..65535 for dynamic port assignment. However even that is
not enough dynamic ports for some busy servers, so the range is usually configurable (by an
administrator). On modern Linux and Solaris systems (often used as servers), the default
dynamic range now starts at 32768. Mac OS X and Windows Vista default to 49152..65535.
[root@desktop12 ~]# cat /proc/sys/net/ipv4/ip_local_port_range
32768 61000
solaris$ /usr/sbin/ndd /dev/tcp tcp_smallest_anon_port tcp_largest_anon_port
32768
65535
macosx$ sysctl net.inet.ip.portrange.first net.inet.ip.portrange.last
net.inet.ip.portrange.first: 49152
net.inet.ip.portrange.last: 65535
vista> netsh int ipv4 show dynamicport tcp
Protocol tcp Dynamic Port Range
Start Port : 49152
Number of Ports : 16384
These ports can’t be registered by IANA. This is used for custom or temporary purposes and for
automatic allocation of short-lived (or ephemeral ) ports which is used internally by
application/processes. You can see these ports by running ‘netstat’ command under “Local
address” column.
Q.What do you mean by default port? Default port is a designated port for particular well-
known server.
Ans: File2.
2. What is the command to make a file executable?
Ans: /etc/hosts
Ans: There are two common modes for transferring files via FTP, ascii and binary.
Ascii mode transfers files as ‘text’. Examples of ascii files would be .txt, .asp,
Binary mode transfers files as raw data. Examples of binary files would be .wav,
Ans: In NAT mode it gets the IP Address from Virtual LAN of Virtual BOX.
ext2, ext3 and ext4 are all filesystems created for Linux. This article explains the
following:
This was developed to overcome the limitation of the original ext file system.
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.
You can convert a ext2 file system to ext3 file system directly (without
backup/restore).
Ans: wget
Ans: ls -a
Ans: Its an Anti-Virus for Unix Based OS, but specially designed and used for scanning in
Email Servers
Ans: #!/bin/bash
machines through libvirt. It primarily targets KVM VMs, but also manages Xen and LXC
(linux containers).
Ans: mount -t ntfs /dev/sdb1 /mnt/ntfs {If the flavour of Linux supports NTFS}
#mkdir /mnt/win
#vi /etc/fstab
19. What is the command to list the server processes listening on TCP ports?
Ans: init 1 or Runlevel 1 corresponds to Single User Mode which is used for
troubleshooting
https://zenpwning.wordpress.com/tag/linux/
a) macro
b) read
c) script
a) os
b) Unix
c) kernel
d) uname
a) uname -r
b) uname -n
c) uname -t
d) kernel
a) print
b) ptr
c) lpr
a) –l
b) -o
c) –a
d) –i
a) cat
b) type
c) zcat
d print
a) cgrp
b) chgrp
c) change
d) group
a) tee
b) extract
c) exec
10. Which option of rm command is used to remove a directory with all its
subdirectories
a) –b
b) –o
c) –p
d) –r
11. Which command creates an empty file if file does not exist?
a) cat
b) touch
c) ed
d) read
a) Type
b) File
c) Finfo
d) Info
a) which
b) where
c) wexec
d) what
a) grep
b) wc
c) count
d) cut
15. Which of these commands could you use to show one page of output at a time?
a) less
b) sed
c) pause
d) grep
1:c – 2:c – 3:d – 4:a – 5:c – 6:d – 7:c – 8:b – 9:a – 10.d – 11:b – 12:b – 13:a – 14:b –
15:a –
1 Q. Which command is used to check the number of files and disk space used and the each
user’s defined quota
Repquota , it shows filesystem, no. of blocks used, soft and hard limit, no. of files used,
soft and hard limits
2 What is the name and path of the main system log
A. /var/log/messages. (Syslog)
Username, mask password, UID, GID, comment, home directory, default shell
6 Which commands are used to set a processor-intensive job to use less CPU time
nice, it is used for scheduling priority of PIDs. -20 means highest priority. 19 means
lowest priority.
Top command can also be used for this job. Press r and PID and Priority.
11 How environment variables is set so that the file permission can be automatically set to the
newly created files
Umask, umask 000 means full full permission, umask 777 means least permissions will
be assign to newly created files.
12 Which key combination can you press to suspend a running job and place it in background
Ctrl+z
13 What file would you edit in your home directory to change the default window manager
~/.xinitrc
14 Which command can split long text files into smaller ones
16 What is page in, page out, swap in, swap out
Page-ins and page-outs are pages moved in and out between RAM and Disk
swap-ins and swap-outs are processes moved in and out between RAM and Disk
page-out = The system’s free memory is less than a threhsold “lotsfree” and vhand
daemon use “LRU, Last Recently Used” algorithm to move some unused / least used
pages to the swap area.
page-in = One process which is running requested for a page that is not in the current
memory (page-fault), vhand daemon is bringing it’s pages to memory.
Page in – Page outs – They are similar in function to any other operating system. When a
particular page is requested by the main memory, but it is not present in the main
memory; a page fault occurs…and this page is “paged in” to the main memory. Similarly
pages that have been inactive for a while are “paged out” to page data sets on the
auxiliary memory(Swap).
swap-out = System is thrashing and swapper daemon has de-activated a process and it’s
memory pages are moved into the swap area.
swap-in = A deactivated process is back to work and it’s pages are being brought into the
memory.
Swapping involves the moving of a process’s entire collection data in memory to a range
of space on the backing store, often to a swapfile or swap partition. The process goes
from being in memory to swapped out entirely; there is no in-between.
Swapping occurs when whole process is transferred to disk, while paging is when some
part of process is transferred to disk while rest is still in physical memory.
It reads standard input and transfers it to standard output while storing the contents in a
separate file
sort inputfile.txt | tee outputfile.txt | cat
tee “Hello, I am output” > outputfile.txt
who | tee userlist.txt
It can also be used to write multiple files at the same time
date | tee –a file1 file2 file3
Kernel.h
DORA (Discover, Offer, Request, Accept) is the process by which a client acquires
DHCP IP Address
Virtual LAN, is a broadcast domain created by switches. With VLAN a switch can create
and broadcast domain. It separates large broadcast domains into smaller ones thus
improves performance.
27 What are hard and soft mount
Hard mount is used to mount local filesystem. The filesystem will be in the mounted state
until you unmount it manually.
Soft mount is an option that is very useful for mounting network filesystems(NFS). Soft
mount will allow automatic unmount if the filesystem is idle for a specified time period.
NFS supports two types of mounts — hard mounts and soft mounts. If a mount is a hard
mount, an NFS request affecting any part of the mounted resource is issued repeatedly
until the request is satisfied (for example, the server crashes and comes back up at a later
time). When a mount is a soft mount, an NFS request returns an error if it cannot be
satisfied (for example, the server is down), then quits.
Hard mount ensures data integrity and soft mount causes data loss if NFS server is
unreachable.
Soft mount improves performance and Hard mount improves reliability
A daemon (Disk and Execution Monitor) is a software process that runs in the
background (continuously) and provides the service to client upon request. For example
named is a daemon. When requested it will provide DNS service.
Other examples are:
* xinetd (it is a super-daemon, it is responsible for invoking other Internet servers when
they are needed)
* inetd (same as xinetd, but with limited configuration options)
* sendmail/postfix (to send/route email)
* Apache/httpd (web server)
Browser Running one daemon for each of the services could significantly increase the
load. However if you are running big site (with many user) it is advisable to use
dedicated daemon. For example web server or MySQL database server.
A server process runs one time, when called by a daemon. Once done it will stop. For
example telnetd (in.telnetd) or ftpd called from xinetd/inetd daemon. By calling server
process from daemon you can save the load and memory. Use a server process for small
services such as ftpd, telnetd
./configure
The above command makes the shell run the script named ‘ configure ‘ which exists in
the current directory. The configure script basically consists of many lines which are used
to check some details about the machine on which the software is going to be installed.
This script checks for lots of dependencies on your system. For the particular software to
work properly, it may be requiring a lot of things to exist on your machine already. When
you run the configure script you would see a lot of output on the screen , each being some
sort of question and a respective yes/no as the reply. If any of the major requirements are
missing on your system, the configure script would exit and you cannot proceed with the
installation, until you get those required things.
The main job of the configure script is to create a ‘ Makefile ‘ . This is a very important
file for the installation process. Depending on the results of the tests (checks) that the
configure script performed it would write down the various steps that need to be taken
(while compiling the software) in the file named Makefile.
If you get no errors and the configure script runs successfully (if there is any error the last
few lines of the output would glaringly be stating the error) then you can proceed with the
next command which is
make
‘make’ is actually a utility which exists on almost all Unix systems. For make utility to
work it requires a file named Makefile in the same directory in which you run make. As
we have seen the configure script’s main job was to create a file named Makefile to be
used with make utility. (Sometimes the Makefile is named as makefile also)
make would use the directions present in the Makefile and proceed with the installation.
The Makefile indicates the sequence that Linux must follow to build various
components / sub-programs of your software. The sequence depends on the way the
software is designed as well as many other factors.
The Makefile actually has a lot of labels (sort of names for different sections). Hence
depending on what needs to be done the control would be passed to the different sections
within the Makefile or it is possible that at the end of one of the section there is a
command to go to some next section.
Basically the make utility compiles all your program code and creates the executable. For
particular section of the program to complete might require some other part of the code
already ready, this is what the Makefile does. It sets the sequence for the events so that
your program does not complain about missing dependencies.
One of the labels present in the Makefile happens to be named ‘install’.
If make ran successfully then you are almost done with the installation. Only the last step
remains which is
make install
As indicated before make uses the file named Makefile in the same directory. When you
run make without any parameters, the instruction in the Makefile begin executing from
the start and as per the rules defined within the Makefile (particular sections of the code
may execute after one another.. that’s why labels are used.. to jump from one section to
another). But when you run make with install as the parameter, the make utility searches
for a label named install within the Makefile, and executes only that section of the
Makefile.
The install section happens to be only a part where the executable and other required files
created during the last step (i.e. make) are copied into the required final directories on
your machine. E.g. the executable that the user runs may be copied to the
/usr/local/apache2 so that all users are able to run the software. Similarly all the other
files are also copied to the standard directories in Linux. Remember that when you ran
make, all the executable were created in the temporary directory where you had unzipped
your original tarball. So when you run make install, these executable are copied to the
final directories.
rsync utility is used to synchronize the files and directories from one location to another
in an effective way. Backup location could be on local server or on remote server.
# rsync options <source> <destination>
ii) -a archive (recursive, preserve symbolic links, permissions, timestamps, owner and group)
v) -v verbose
xi) –delete to delete the files not present at source but present at destination
i) # ssh-keygen
i) GROUP=100
ii) HOME=/home
iii) INACTIVE=-1
iv) EXPIRE=
v) SHELL=/bin/bash
vi) SKEL=/etc/skel
vii) CREATE_MAIL_SPOOL=yes
i) GROUP=100
ii) HOME=/home
iii) INACTIVE=-1
iv) EXPIRE=
v) SHELL=/bin/ksh
vi) SKEL=/etc/skel
vii) CREATE_MAIL_SPOOL=yes
i) -s = shell
Adduser command
# adduser <username>
Creating n number of users
# newusers <file containing list of users>
/etc/login.defs file contains defaults for a new user. Various options in login.defs file are
iii) PASS_MIN_DAYS 0
iv) PASS_MIN_LEN 5
v) PASS_WARN_AGE 7
ex.
ii) Data is broken into equal size chunks and distributed over all disks
iii) Performance is improved because of simultaneous read and write disk operations
vii) Two 80G disk = 160×1 = 160G available disk in RAID 0 (Space efficiency =1)
RAID 1 = Mirroring
vii) Two 80G disk = 160×1/2 = 80G available disk in RAID 0 (Space efficiency = 1/n = 1/2)
ii) Data is broken into stripes and distributed over two disks
iii) Parity bit is stored only in third disk i.e. Parity Disk
vii) 3x80G disk = 240×2/3 = 160G available disk in RAID 4 (Space efficiency = 1-1/n = 1-1/3
= 2/3)
ii) Data is broken into stripes and distributed over three disks
iii) Parity bit is also distributed over three disks
vii) 3x80G disk = 240×2/3 = 160G available disk in RAID 5 (Space efficiency = 1-1/n = 1-1/3
= 2/3)
# last reboot
# last shutdown
# who –b
# uptime
# lvextend –L 2G <LVNAME>
# resize2fs <LVNAME>
dmesg
/var/log/messages
dmidecode –t system
IML (Integrated Management Logs) – An iLO console feature
hpacucli – To check RAID array status
use grep or less commands on
/var/log/messages and /var/log/warn
/var/log/mcelog
# dmidecode –type 0
dmidecode is a tool for dumping a computer’s DMI (some say SMBIOS) table contents
in a human-readable format. This table contains a description of the system’s hardware
components, as well as other useful pieces of information such as serial numbers and
BIOS revision. Thanks to this table, you can retrieve this information without having to
probe for the actual hardware.
# uname –a
# arch
# cat /proc/sys/kernel/panic
# sysctl –a | grep kernel.panic
i) Kernel.panic = 0
i) Kernel.panic = 10
51 What are the general causes of kernel panic
ii) Only half of the paths are used at a time for I/O
Improved Performance
World Wide Identifier is a unique and unchanging name of every multipath device
i) comment out the default blacklist (it blacklists all devices)
i) blacklist {
iii) }
You can also black list device by its Device Name and Device Type
# multipath –F à Removes all multipath devices
# multipath –f < device > à Removes the given device
# multipath –v2 à verbosity = 2
# multipath –l à Displays info from sysfs and device mapper
# multipath –ll à Also displays variable components of the system
# cat /var/lib/multipath/binding
59 How to add devices to multipath database
i) devices {
ii) device {
vi) }
vii) }
DMSetup command is used to find out Device Mapper entries match the Multipathed
device
# dmsetup ls
# multipathd –k
ii) reconfigure
iv) CTRL+D
# mkfs.ext3 /dev/mapper/mpath0p1
# mount /dev/mapper/mpath0p1 /mnt/san
Kpartx creates device maps from partition tables
We must use fdisk command on underlying device /dev/sda
i) # multipath –l
Resize the file system (if there is no LVM configured upon mpath0)
If LVM resides over mpath0 then we should not resize it. We should resize LVM
i) # pvscan
ii) # vgscan
# ls –l /sys/block/*/device
ii) # rpm –ivh kernel kernel-smp à SMP is multi core or multi CPU
67 Where are the Kernel Modules (Device Drivers in Windows terminology) stored
/lib/modules/kernel-version
/lib/modules/$(uname –r)
# lsmod
# less /proc/modules
# modinfo ipv6
If you want to load cdrom module in kernel upon next boot, modify modules.conf [old
method]
i) # vi /etc/modules.conf
ii) ide-cd
iii) ide-core
iv) cdrom
Or we can use rc.modules file. We should use rc.modules file and not rc.local for loading
kernel modules because rc.modules file is read much eary in boot sequence
73 How to find information about your Hard Disk from Linux Command
i) Timing cached reads: 9460 MB in 2.00 seconds = 4737.22 MB/sec
ii) Timing buffered disk reads: 708 MB in 7.57 seconds = 93.49 MB/sec
i) S: Sleeping,
iv) Z: Zombie,
v) T: Stopped process (either by a job control signal or because it is being traced)
PID: Process ID
PPID: Parent process ID
USER: User name who initiated process
GROUP: Group name from whom user belong/currently launched the job
RSS: The resident set size of the process, in kilobytes.
VSZ:The total size of the process in virtual memory, in kilobytes.
%CPU: Total % of CPU taken by this process
%MEM: Total % of Memory taken by this process
TIME: the cumulative CPU time of the process in the form
ELAPSED: Total time elapsed since this process is live
TT: Terminal ID
COMMAND: Command/daemon/process with args
# ps -eo s,pid,ppid,user,group,rss,vsz,pcpu,pmem,time,etime,tty,args
# ps L à to see list of format codes like above
i) Kernel
ii) Hardware
Important files under proc are: cpuinfo, mdstat, meminfo, modules, mounts, partitions,
net, version, /proc/sys/kernel/hostname, /proc/sys/net/ipv4/ip_forward
Open system-config-date, Network Management Tab and add NTP Server’s name/IP
Click OK
Run command ntpq –p to check available NTP servers
i) # ntpq –p
Run ntpstat to see if Time is updated (synchronous) and what is Time lag (seconds
behind)
i) # ntpstat
# umount /dev/sda1
# fuser –m /dev/sda1 à identify which pid is using resource
# lsof | grep /dev/sda1 à identify which pid is using resource
# kill -9 <PID> à Kill the pid
# umount /dev/sda1
81 What is Network Bonding? What are the steps for Network Bonding?
Bonding is creation of a single bonded interface by combining 2 or more ethernet
interfaces. This helps in high availability and performance improvement.
Step 1:
Create the file ifcfg-bond0 with the IP address, netmask and gateway.
ii) DEVICE=bond0
vi) USERCTL=no à Only root can control services (say no to other users)
Step 2:
Modify eth0, eth1 and eth2 configuration as shown below. Comment out, or remove the
ip address, netmask, gateway and hardware address from each one of these files, since
settings should only come from the ifcfg-bond0 file above.
ii) DEVICE=eth0
iii) BOOTPROTO=none
iv) ONBOOT=yes
v) MASTER=bond0
vi) SLAVE=yes
viii) DEVICE=eth1
ix) BOOTPROTO=none
x) ONBOOT=yes
xi) USERCTL=no
xii) MASTER=bond0
xiii) SLAVE=yes
xv) DEVICE=eth2
xvi) BOOTPROTO=none
xvii) ONBOOT=yes
xviii) MASTER=bond0
xix) SLAVE=yes
Step 3:
Set the parameters for bond0 bonding kernel module. Add the following lines
to/etc/modprobe. conf
Step 5:
Restart the network, or restart the computer.
Look at ifconfig -a and check that your bond0 interface is active. You are done!
RHEL bonding supports 7 possible “modes” for bonded interfaces. These modes
determine the way in which traffic sent out of the bonded interface is actually dispersed
over the real interfaces. Modes 0, 1, and 2 are by far the most commonly used among
them.
·* Mode 0 (balance-rr)
This mode transmits packets in a sequential order from the first available slave through
the last. If two real interfaces are slaves in the bond and two packets arrive destined out
of the bonded interface the first will be transmitted on the first slave and the second frame
will be transmitted on the second slave. The third packet will be sent on the first and so
on. This provides load balancing and fault tolerance.
* Mode 1 (active-backup)
This mode places one of the interfaces into a backup state and will only make it active if
the link is lost by the active interface. Only one slave in the bond is active at an instance
of time. A different slave becomes active only when the active slave fails. This mode
provides fault tolerance.
* Mode 2 (balance-xor)
Transmits based on XOR formula. (Source MAC address is XOR’d with destination
MAC address) modula slave count. This selects the same slave for each destination MAC
address and provides load balancing and fault tolerance.
* Mode 3 (broadcast)
This mode transmits everything on all slave interfaces. This mode is least used (only for
specific purpose) and provides only fault tolerance.
* Mode 4 (802.3ad)
This mode is known as Dynamic Link Aggregation mode. It creates aggregation groups
that share the same speed and duplex settings. This mode requires a switch that supports
IEEE 802.3ad Dynamic link.
* Mode 5 (balance-tlb)
This is called as Adaptive transmit load balancing. The outgoing traffic is distributed
according to the current load and queue on each slave interface. Incoming traffic is
received by the current slave.
* Mode 6 (balance-alb)
This is Adaptive load balancing mode. This includes balance-tlb + receive load balancing
(rlb) for IPV4 traffic. The receive load balancing is achieved by ARP negotiation. The
bonding driver intercepts the ARP Replies sent by the server on their way out and
overwrites the src hw address with the unique hw address of one of the slaves in the bond
such that different clients use different hw addresses for the server.
First login to mysql and lock all tables. This will ensure that no update operations are
performed on LVM mount point
ii) OR
iv) # cd /mnt
vi) # cd
It is a feature of Linux which creates virtual image of a device. This image will then keep
track of the changes being made to the origin.
Example, If you have 1000mb data logical volume out of which 800mb is already used.
Now you take a lvm-snapshot of this volume with size 1000mb. Then this snapshot will
be able to keep a track of changes made to origin data volume till next 200mb. After
200mb usage on data volume, our snapshot will become INVALID.
The size of snapshot need to be chosen by admin looking at the amount of expected level
of changes in data (origin)
Cluster Administration
1 What is a Cluster
A cluster is two or more computers (called as nodes or members) that works together to
perform a taks.
Storage
High Availability
Load Balancing
High Performance
It is a condition where two instances of the same cluster are running and trying to access
same resource at the same time, resulting in corrupted cluster integrity
Cluster must maintain quorum to prevent split-brain issues
In case of a 2 node cluster, quorum disk acts as a tie-breaker and prevents split-brain issue
If a node has access to network and quorum disk, it is active
If a node has lost access to network or quorum disk, it is inactive and can be fenced
A Quorum disk, known as a qdisk is small partition on SAN storage used to enhance quorum.
It generally carries enough votes to allow even a single node to take quorum during a cluster
partition. It does this by using configured heuristics, that is custom tests, to decided which which
node or partition is best suited for providing clustered services during a cluster reconfiguration.
RGManager manages and provides failover capabilities for collections of cluster resources
called services, resource groups, or resource trees.
In the event of a node failure, RGManager will relocate the clustered service to another node
with minimal service disruption. You can also restrict services to certain nodes, such as restricting
httpd to one group of nodes while mysql can be restricted to a separate set of nodes.
When the cluster membership changes, openais tells the cluster that it needs to recheck it’s
resources. This causes rgmanager, the resource group manager, to run. It will examine what
changed and then will start, stop, migrate or recover cluster resources as needed.
Within rgmanager, one or more resources are brought together as a service. This service is
then optionally assigned to a failover domain, an subset of nodes that can have preferential
ordering.
Fencing is the disconnection of a node from the cluster’s shared storage. Fencing cuts off I/O
from shared storage, thus ensuring data integrity. The cluster infrastructure performs fencing
through the fence daemon, fenced.
Power fencing — A fencing method that uses a power controller to power off an inoperable
node.
storage fencing — A fencing method that disables the Fibre Channel port that connects storage
to an inoperable node.
Other fencing — Several other fencing methods that disable I/O or power of an inoperable
node, including IBM Bladecenters, PAP, DRAC/MC, HP ILO, IPMI, IBM RSA II, and others.
# fence_ack_manual –n <node2>
10 How to see shared IP address (Cluster Resource) if ipconfig doesn’t show it
# ip addr list
A lock manager is a traffic cop who controls access to resources in the cluster
As implied in its name, DLM is a distributed lock manager and runs in each cluster node; lock
management is distributed across all nodes in the cluster. GFS2 and CLVM use locks from the lock
manager.
This is a comprehensive user interface for installing, configuring, and managing Red Hat High
Availability Add-On.
Luci — This is the application server that provides the user interface for Conga. It allows users
to manage cluster services. It can be run from outside cluster environment.
Ricci — This is a service daemon that manages distribution of the cluster configuration. Users
pass configuration details using the Luci interface, and the configuration is loaded in to corosync for
distribution to cluster nodes. Luci is accessible only among cluster members.
OpenAIS is the heart of the cluster. All other computers operate though this component, and
no cluster component can work without it. Further, it is shared between both Pacemaker and RHCS
clusters.
In Red Hat clusters, openais is configured via the central cluster.conf file. In Pacemaker
clusters, it is configured directly in openais.conf.
The totem protocol defines message passing within the cluster and it is used by openais. A
token is passed around all the nodes in the cluster, and the timeout in fencing is actually a token
timeout. The counter, then, is the number of lost tokens that are allowed before a node is considered
dead.
The totem protocol supports something called ‘rrp’, Redundant Ring Protocol. Through rrp, you
can add a second backup ring on a separate network to take over in the event of a failure in the first
ring. In RHCS, these rings are known as “ring 0” and “ring 1”.
CLVM is ideal in that by using DLM, the distributed lock manager, it won’t allow access to
cluster members outside of openais’s closed process group, which, in turn, requires quorum.
It is ideal because it can take one or more raw devices, known as “physical volumes”, or
simple as PVs, and combine their raw space into one or more “volume groups”, known as VGs. These
volume groups then act just like a typical hard drive and can be “partitioned” into one or more
“logical volumes”, known as LVs. These LVs are where Xen’s domU virtual machines will exist and
where we will create our GFS2 clustered file system.
It works much like standard filesystem, with user-land tools like mkfs.gfs2, fsck.gfs2 and so
on. The major difference is that it and clvmd use the cluster’s distributed locking mechanism
provided by the dlm_controld daemon. Once formatted, the GFS2-formatted partition can be
mounted and used by any node in the cluster’s closed process group. All nodes can then safely read
from and write to the data on the partition simultaneously.
One of the major roles of a cluster is to provide distributed locking on clustered storage. In
fact, storage software can not be clustered without using DLM, as provided by the dlm_controld
daemon and using openais’s virtual synchrony via CPG.
Through DLM, all nodes accessing clustered storage are guaranteed to get POSIX locks, called
plocks, in the same order across all nodes. Both CLVM and GFS2 rely on DLM, though other clustered
storage, like OCFS2, use it as well.
we can use ccs_tool, the “cluster configuration system (tool)”, to push the new cluster.conf to
the other node and upgrade the cluster’s version in one shot.
ccs_tool update /etc/cluster/cluster.conf
It is a Cluster Manger tool, it can be used to view nodes and status of cluster
Cman_tool nodes
Cman_tool status
20 What is clusstat
This command is run to create Luci Admin user and set password for it
Service luci start, chckconfig luci on
Default port for Luci web server is 8084
Programs that provide application services via the network are called network daemons . A
daemon is a program that opens a port, most commonly a well-known service port, and waits for
incoming connections on it. If one occurs, the daemon creates a child process that accepts the
connection, while the parent continues to listen for further requests. This mechanism works well,
but has a few disadvantages; at least one instance of every possible service you wish to provide
must be active in memory at all times. In addition, the software routines that do the listening and
port handling must be replicated in every network daemon.
To overcome these inefficiencies, most Unix installations run a special network daemon, what
you might consider a “super server.” This daemon creates sockets on behalf of a number of
services and listens on all of them simultaneously. When an incoming connection is received on
any of these sockets, the super server accepts the connection and spawns the server specified for
this port, passing the socket across to the child to manage. The server then returns to listening.
The most common super server is called inetd , the Internet Daemon. It is started at system boot
time and takes the list of services it is to manage from a startup file named /etc/inetd.conf . In
addition to those servers, there are a number of trivial services performed by inetd itself called
internal services . They include chargen , which simply generates a string of characters,
and daytime , which returns the system’s idea of the time of day.
Services managed by inetd daemon are ftp, tftp, chargen, daytime, finger, etc
This command will run TOP in –b(batch) mode, with a delay (-d) of 10 seconds and 3(-n) times.
This will send output of ps command to multiple files at the same time use TEE Command
iostat -x 10 10
vmstat -x 10 10
proc:
Memory:
Swapd: Shows how many blocks (1KB) are swapped out(paged) to disk
SWAP:
So: Blocks per sec swapped out (From memory(RAM) to swap area(disk))
IO:
Bi: Blocks per sec received from block device – Read Hard Disk
Bo: Blocks per sec sent to block device – Write Hard Disk
System:
Cs: No. of context switches per sec (storing and restoring state of CPU. This enables multiple
processes to share a single CPU)
CPU:
Us: % of CPU used for running non-kernel code (user process)
Sys: % of CPU used for running kernel code (system time, network, I/O, clock etc)
ldd /bin/ls
This command will list all the dependent missing libraries for ls command
lsof
lsof –p <pid>
lsof –u <name>
lsof –i4
lsof +d /mnt/nas
This is extremely useful in unmounting a directory when it shows message ‘device is busy’
Uptime
Top
Vmstat
Free
IOTop
HTop
aTOP
Using TOP
z – Color display
k – Kill a process
q – quit
Load average is an extensive topic and to understand its inner workings can be daunting. The
simplest of definitions states that load average is the cpu utilization over a period of time. A load
average of 1 means your cpu is being fully utilized and processes are not having to wait to use a
CPU. A load average above 1 indicates that processes need to wait and your system will be less
responsive. If your load average is consistently above 3 and your system is running slow you
may want to upgrade to more CPU’s or a faster CPU.
Shows CPU utilization details. “9.5%us” user processes are using 9.5%; “31.2%sy” system
processes are using 31.2%; “27.0%id” percentage of available cpu; “7.6%wa” time CPU is
waiting for IO.
When first analyzing the Cpu(s) line in top look at the %id to see how much cpu is available. If
%id is low then focus on %us, %sy, and %wa to determine what is using the CPU.
Describes the memory usage. These numbers can be misleading. “255592k total” is total
memory in the system; “167568K used” is the part of the RAM that currently contains
information; “88024k free” is the part of RAM that contains no information; “25068K buffers
and 85724k cached” is the buffered and cached data for IO.
So what is the actual amount of free RAM available for programs to use ?
Top will display the process using the most CPU usage in descending order. Lets describe each
column that represents a process.
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
3166 apache 15 0 29444 6112 1524 S 6.6 2.4 0:00.79 httpd
NI – Nice value of the process (higher value indicates lower priority, -20 is highest, 19 is lowest)
S – State of the task. Values are S (sleeping), D (uninterruptible sleep), R (running), Z(zombies),
or T (stopped or traced)
Using Free
Free –m
Using Fuser
It gives information about file user or the process that is currently using the file/directory
fuser –v /etc/init.d/httpd
/etc/init.d/httpd:
fuser –v –k -i /etc/init.d/httpd
TAR
GNU cpio is a tool for creating and extracting archives, or copying files from one place to
another. It handles a number of cpio formats as well as reading and writing tar files. cpio
command works just like tar, only better. It can read input from the “find” command.
# cpio -i -F perl-files.tar
# cpio -i -F /dev/nst0
Install package:
Reinstall package:
aptitude update
aptitude upgrade
aptitude dist-upgrade
Install package:
Remove package:
yum remove PACKAGENAME
Update package:
Update system:
yum update
yum upgrade
Show package:
yum grouplist
o i = restore mode
o d = create directories wherever necessary
o m = retain time stamps
o v = verbose mode
How to build RPM from tar
o rpmbuild –ta abc.tar
o rpm –ivh /usr/src/redhat/RPMS/[arch]/abc.xxx.[arch].rpm
How to build RPM from spec
o rpmbuild –ba package.spec
o Install rpmbuild if ‘command not found’ by ‘yum install rpm-build’ command
What’s that about SUID, SGID, and the sticky bit (oh my!)? Once again, a table seems
appropriate…
This probably isn’t intuitive, so we’ll go over it in a bit more detail. First, the sticky bit. One
place the sticky bit is commonly used on Unix-like systems is the /tmp directory. This directory
needs to be world-writable, but you don’t want anyone going around and deleting everyone
else’s files. The sticky bit offers exactly this protection.
The Sticky Bit is a permission bit that can be set on either a file or a directory.
If it is set on a file, then that file will remain in memory after execution, thus sticking in memory.
This is useful when running a multi-user program (such as a bulletin board system that I ran
once) to make the program execute faster for the next user. This was a common programming
tactic earlier in the history of computer programming when speed and disk space were at a
premium. This feature is UNIX specific. This feature is not used in LINUX. Sticky Bit used
on a file is USELESS in LINUX. It was useful when fast disk access and memory access
technologies were not around. So in today’s age concept of Sticky Bit is obsolete.
If the sticky bit is set on a directory, only the owner of files in that directory will be able to
modify or delete files in that directory – even if the permissions set on those files would
otherwise allow it.
rsync -e ‘ssh -p 30000’ -avl –delete –stats –progress –-exclude ‘source’ –exclude ‘source/file.txt’
–exclude-from ‘/root/exclude.txt’ [email protected]:/home/demo /backup
-e ‘ssh –p 30000’ à This ensures rsync uses the SSH protocol and sets the port to 30000
-v à Verbose mode
-l à Preserves links
–delete à Delete files from destination folder that have been deleted from source folder
–progress à Progress of each file transfer, useful for rysncing large files
Logs on Linux
Some of the common log files and directories you might see in /var/log:
Filename(s) Purpose
auth.log Authentication logs
boot.log Boot logs
btmp Invalid login attempts
cron Cron logs
daemon.log Logs for specific services (daemons)
dmesg Kernel boot messages
httpd/ Apache logs
kern.log Kernel logs
mail* Mail server logs
messages General/all logs
mysql* MySQL logs
secure Security/authentication logs
syslog All system logs
wtmp User logins and logouts
Server 1
Server 2
Server 1
/usr/sbin/openvpn –remote 10.100.1.50 –dev tun1 –ifconfig 172.16.1.1 172.16.1.2 –secret key
Server 2
/usr/sbin/openvpn –remote 10.100.1.20 –dev tun1 –ifconfig 172.16.1.2 172.16.1.1 –secret key
<VirtualHost *:80>
ProxyRequests off
ServerName domain.com
<Proxy balancer://mycluster>
# WebHead1
BalancerMember http://10.176.42.144:80
# WebHead2
BalancerMember http://10.176.42.148:80
# chages
Order Deny,Allow
# of the load.
ProxySet lbmethod=byrequests
</Proxy>
# balancer-manager
# web interface.
<Location /balancer-manager>
SetHandler balancer-manager
# your office
Order deny,allow
</Location>
# Point of Balance
ProxyPass /balancer-manager !
ProxyPass / balancer://mycluster/
</VirtualHost>
Behind the scenes there are actually two versions of the MySQL server, “mysqld” and
“mysqld_safe”. Both read the same config sections. The main difference is that mysqld_safe
launches with a few more safety features enabled to make it easier to recover from a crash or
other problem.
Both mysqld and mysqld_safe will read config entries in the “mysqld” section. If you include a
“mysqld_safe” section, then only mysqld_safe will read those values in.
To LOCK and UNLOCK all tables in MySQL (Useful for backup/LVM Snapshot)
Q3.WHAT IS BASH?
BASH is short for Bourne Again SHell. It was written by Steve Bourne as a
replacement to the original Bourne Shell (represented by /bin/sh). It combines
all the features from the original version of Bourne Shell, plus additional
functions to make it easier and more convenient to use. It has since been
adapted as the default shell for most systems running Linux.
Q12.WHAT IS CLI?
CLI is short for Command Line Interface. This interface allows user to type
declarative commands to instruct the computer to perform operations. CLI offers
an advantage in that there is greater flexibility. However, other users who are
already accustom with using GUI find it difficult to remember commands
including attributes that come with it.
Q15.HOW CAN YOU FIND OUT HOW MUCH MEMORY LINUX IS USING?
From a command shell, use the “concatenate” command: cat /proc/meminfo for
memory usage information. You should see a line starting something like: Mem:
64655360, etc. This is the total memory Linux thinks it has available to use.
Here is the list of 35 complex and tricky unix interview questions and answers. A lot of complex unix
commands which are asked in unix interviews are SED, AWK, DU, HEAD, TAIL, WATCH, GREP, CUT,
PS, ZIP, UNZIP etc. A lot of tips and tricks are asked about these unix commands during interview.
Following questions and unix commands might help you in your unix interview.
By using lsof command in UNIX. It will list down PID of all the processes which are using a particular file.
2. How do you find which remote hosts are connecting to your host on a particular port say
10123?
For example: execute netstat -a | grep "port" and it will list the entire hosts which are connected to this
host on port 10123.
You can list down all the running processes using [ps] command. Then you can “grep” your user name or
process name to see if the process is running.
Ephemeral ports are port used by Operating system for client sockets. There is a specific range on which
OS can open any port specified by ephemeral port range.
Normally [ls –lt] command lists down file/folder list sorted by modified time. If you want to list then
alphabetically, then you should simply specify: [ls –l]
6. If one process is inserting data into your MySQL database? How will you check how many rows
inserted into every second?
8. You have a tab separated file which contains Name, Address and Phone Number. List down all
Phone Number without their name and addresses?
To check the status of last executed command in UNIX, you can check the value of an inbuilt bash
variable [$?]. See the below example:
$> echo $?
The standard command to see this is [ps]. But [ps] only shows you the snapshot of the processes at that
instance. If you need to monitor the processes for a certain period of time and need to refresh the results
in each interval, consider using the [top] command.
$> ps –ef
If you wish to see the % of memory usage and CPU usage, then consider the below switches:
$> ps aux
If you wish to use this command inside some shell script, or if you want to customize the output of [ps]
command, you may use “-o” switch like below. By using “-o” switch, you can specify the columns that you
want [ps] to print out.
$>ps -e -o stime,user,pid,args,%mem,%cpu
11 Your application home directory is full? How will you find which directory is taking how much
space?
For example du –sh . | grep G will list down all the directories which have GIGS in Size.
12. How do you find for how many days your Server is up?
Using command, we can do it in many ways. Based on what we have learnt so far, we can make use of
[ls] and [$?] command to do this. See below:
If the file exists, the [ls] command will be successful. Hence [echo $?] will print 0. If the file does not exist,
then [ls] command will fail and hence [echo $?] will print 1.
14. You have an IP address in your network. How will you find hostname and vice versa?
In a bash shell, you can access the command line arguments using $0, $1, $2, … variables, where $0
prints the command name, $1 prints the first input parameter of the command, $2 the second input
parameter of the command and so on.
Just put an [exit] command in the shell script with return value other than 0. This is because the exit code
of successful Unix program is zero. So, suppose if you write exit -1 inside your program, then your
program will throw an error and exit immediately.
There are many ways to do this. However the easiest way to display the first line of a file is using the
[head] command.
If you specify [head -2] then it would print first 2 records of the file.
Another way can be by using [sed] command. [Sed] is a very powerful text editor which can be used for
various text manipulation purposes like this.
How does the above command work? The 'd' parameter basically tells [sed] to delete all the records from
display from line 2 to last line of the file (last line is represented by $ symbol). Of course it does not
actually delete those lines from the file, it just does not display those lines in standard output screen. So
you only see the remaining line which is the 1st line.]
If you want to do it using [sed] command, here is what you should write:
From our previous answer, we already know that '$' stands for the last line of the file. So '$ p' basically
prints (p for print) the last line in standard output screen. '-n' switch takes [sed] to silent mode so that [sed]
does not print anything else in the output.
The easiest way to do it will be by using [sed]. Based on what we already know about [sed] from our
previous examples, we can quickly deduce this command:
You need to replace <n> with the actual line number. So if you want to print the 4th line, the command will
be
Of course you can do it by using [head] and [tail] command as well like below:
You need to replace <n> with the actual line number. So if you want to print the 4th line, the command will
be
We already know how [sed] can be used to delete a certain line from the output – by using the'd' switch.
So if we want to delete the first line the command should be:
$> sed '1 d' file.txt
But the issue with the above command is, it just prints out all the lines except the first line of the file on the
standard output. It does not really change the file in-place. So if you want to delete the first line from the
file itself, you have two options.
Either you can redirect the output of the file to some other file and then rename it back to original file like
below:
Or, you can use an inbuilt [sed] switch '–i' which changes the file in-place. See below:
22. How to remove the last line/ trailer from a file in Unix script?
Always remember that [sed] switch '$' refers to the last line. So using this knowledge we can deduce the
below command:
If you want to remove line <m> to line <n> from a given file, you can accomplish the task in the similar
method shown above. Here is an example:
The above command will delete line 5 to line 7 from the file file.txt
$> sed –i '96,100 d' file.txt # alternative to command [head -95 file.txt]
But not always you will know the number of lines present in the file (the file may be generated
dynamically, etc.) In that case there are many different ways to solve the problem. There are some ways
which are quite complex and fancy. But let's first do it in a way that we can understand easily and
remember easily. Here is how it goes:
$> tt=`wc -l file.txt | cut -f1 -d' '`;sed –i "`expr $tt - 4`,$tt d" test
As you can see there are two commands. The first one (before the semi-colon) calculates the total
number of lines present in the file and stores it in a variable called “tt”. The second command (after the
semi-colon), uses the variable and works in the exact way as shown in the previous example.
We already know how to print one line from a file which is this:
Where <n> is to be replaced by the actual line number that you want to print. Now once you know it, it is
easy to print out the length of this line by using [wc] command with '-c' switch.
The above command will print the length of 35th line in the file.txt.
Assuming the words in the line are separated by space, we can use the [cut] command. [cut] is a very
powerful and useful command and it's real easy. All you have to do to get the n-th word from the line is
issue the following command:
$> echo “A quick brown fox jumped over the lazy cat” | cut –f4 –d' '
xinu
28. How to get the last word from a line in Unix file?
We will make use of two commands that we learnt above to solve this. The commands are [rev] and [cut].
Here we go.
Let's imagine the line is: “C for Cat”. We need “Cat”. First we reverse the line. We get “taC rof C”. Then
we cut the first word, we get 'taC'. And then we reverse it again.
$>echo "C for Cat" | rev | cut -f1 -d' ' | rev
Cat
29. How to get the n-th field from a Unix command output?
We know we can do it by [cut]. Like below command extracts the first field from the output of [wc –c]
command
In the action space, we have asked [awk] to take the action of printing the first column ($1).
30. How to replace the n-th line in a file with a new line in Unix?
This can be done in two steps. The first step is to remove the n-th line. And the second step is to insert a
new line in n-th line position. Here we go.
$>sed -i'' '10 i This is the new line' file.txt # i stands for insert
Open the file in VI editor. Go to VI command mode by pressing [Escape] and then [:]. Then type [set list].
This will show you all the non-printable characters, e.g. Ctrl-M characters (^M) etc., in the file.
32. How to zip a file in Linux?
In order to know the file type of a particular file use the [file] command like below:
If you want to know the technical MIME type of the file, use “-i” switch.
$>file -i file.txt
file.txt: text/plain; charset=us-ascii
Following is the collection of some of the interesting unix commands which you should know. These unix
commands are based on network connections, SVN, find, list, history, lsof, sudo, until, git and cat. If you
know some extra unix commands like following, please share them. Here goes the list of unix commands
which I thought I must share.
3. How to delete all .svn folders from current directory using unix command?
4. How to list all network connections (including which app they belong to)?
lsof -i -nP
sudo !!
7. How to display summary of git commit ids and messages for a given branch?
9. How to get your top 10 commands with number of times you have used it?
10. How to generate list of usernames from an svn logs (Run from top level of the svn project)?
svn log | grep -E "r[0-9]+ \| .+ \|" | awk -F"|" '{print $2}' | sort | uniq > ~/authors.txt
Following is the list of unix basic commands interview questions and answers. These are very basic unix
commands and you must know these commands if you are going to appear in a unix interview. I have
listed down 31 unix interview questions with answers which cover basic unix commands like ls, banner,
cat, date, tee, who, man, head, pg, cmp, diff, grep, kill, echo, su etc. So lets have a look on following unix
interview questions and commands.
1. Output of who should be displayed on the screen with value of total number of users who have logged
in displayed at the bottom of the list.
2. Output of ls should be displayed on the screen and from this output the lines containing the word
‘poem’ should be counted and the count should be stored in a file.
3. Contents of file1 and file2 should be displayed on the screen and this output should be appended in a
file. From output of ls the lines containing ‘poem’ should be displayed on the screen along with the count.
4. Name of cities should be accepted from the keyboard . This list should be combined with the list
present in a file. This combined list should be sorted and the sorted list should be stored in a file ‘newcity’.
5. All files present in a directory dir1 should be deleted any error while deleting should be stored in a file
‘errorlog’.
$ ls > file1
$ banner hi-fi > message
$ cat par.3 par.4 par.5 >> report
$ cat file1>file1
$ date ; who
$ date ; who > logfile
$ (date ; who) > logfile
It reads the standard input and sends it to the standard output while redirecting a copy of what it has read
to the file specified by the user.
4. What does the command “ $who | sort –logfile > newfile” do?
The input from a pipe can be combined with the input from a file . The trick is to use the special symbol “-“
(a hyphen) for those commands that recognize the hyphen as std input. In the above command the output
from who becomes the std input to sort , meanwhile sort opens the file logfile, the contents of this file is
sorted together with the output of who (rep by the hyphen) and the sorted output is redirected to the file
newfile.
ls becomes the input to wc which counts the number of lines it receives as input and instead of displaying
this count , the value is stored in file1.
6. Which of the following commands is not a filter man , (b) cat , (c) pg , (d) head
Ans: man
A filter is a program which can receive a flow of data from std input, process (or filter) it and send the
result to the std output.
7. How is the command “$cat file2 “ different from “$cat >file2 and >> redirection operators?
After the command line is terminated by the key, the shell goes ahead with processing the command line
in one or more passes. The sequence is well defined and assumes the following order.
Parsing: The shell first breaks up the command line into words, using spaces and the delimiters, unless
quoted. All consecutive occurrences of a space or tab are replaced here with a single space.
Variable evaluation: All words preceded by a $ are avaluated as variables, unless quoted or escaped.
Command substitution: Any command surrounded by backquotes is executed by the shell which then
replaces the standard output of the command into the command line.
Wild-card interpretation: The shell finally scans the command line for wild-cards (the characters *, ?,
[, ]). Any word containing a wild-card is replaced by a sorted list of filenames that match the pattern. The
list of these filenames then forms the arguments to the command.
PATH evaluation: It finally looks for the PATH variable to determine the sequence of directories it has to
search in order to hunt for the command.
cmp - Compares two files byte by byte and displays the first mismatch
diff - tells the changes to be made to make the files identical
‘grep’ is a pattern search command. It searches for the pattern, specified in the command line with
appropriate option, in a file(s).
Syntax : grep
Example : grep 99mx mcafile
Cat displays file contents. If the file is large the contents scroll off the screen before we view it. So
command 'more' is like a pager which displays the contents page by page.
Kill $!
14. Which command is used to delete all files in the current directory and all its sub-directories?
rm -r *
$ echo *
It is similar to 'ls' command and displays all the files in the current directory.
Yes, it stands for ‘disk usage’. With the help of this command you can find the disk capacity and free
space of the disk.
‘inode’, each file has a separate inode and a unique inode number.
24. How does the kernel differentiate device files and ordinary files?
Use ‘su’ command. The system asks for password and when valid entry is made the user gains super
user (admin) privileges.
Shell variables are special variables, a name-value pair created and maintained by the shell.
Example: PATH, HOME, MAIL and TERM
Directing the flow of data to the file or from the file for input or output.
Example : ls > wc
28. How to terminate a process which is running and the specialty on command kill 0?
A pipe is two or more commands separated by pipe char '|'. That tells the shell to arrange for the output
of the preceding command to be passed as input to the following command.
Example : ls -l | pr
‘kill()’ returns 0. This implies that a process exists with the given PID, and the system would allow you to
send signals to it. It is system-dependent whether the process could be a zombie.
‘kill()’ returns -1, ‘errno == ESRCH’ either no process exists with the given PID, or security
enhancements are causing the system to deny its existence. (On some systems, the process could be a
zombie.)
‘kill()’ returns -1, ‘errno == EPERM’ the system would not allow you to kill the specified process. This
means that either the process exists (again, it could be a zombie) or draconian security enhancements
are present
‘kill()’ returns -1, with some other value of ‘errno’ you are in trouble! The most-used technique is to
assume that success or failure with ‘EPERM’ implies that the process exists, and any other error implies
that it
doesn't.
An alternative exists, if you are writing specifically for a system (or all those systems) that provide a ‘/proc’
filesystem: checking for the existence of ‘/proc/PID’ may work.
I have listed down 10 basic Linux networking and monitoring commands which each Linux user should
know. These Linux basic networking and monitoring commands like hostname, ping, ifconfig, iwconfig,
netstat, nslookup, traceroute, finger, telnet, ethtool are used for viewing the IP address of the Linux
server, managing Linux server network adapter configuration, making network connections among Linux
servers over telnet and ethernet, Linux server information etc. Lets have a look on the following Linux
networking and monitoring commands.
1. hostname
2. ping
ping sends packets of information to the user-defined source. If the packets are received, the destination
device sends packets back. ping can be used for two purposes
3. ifconfig
View network configuration, it displays the current network adapter configuration. It is handy to determine
if you are getting transmit (TX) or receive (RX) errors.
4. iwconfig
The iwconfig tool is like ifconfig and ethtool for wireless cards. You can view and set the basic Wi-Fi
network details, such as the SSID, channel, and encryption. There's also many advanced settings you
can view and change, including receive sensitivity, RTS/CTS, fragmentation, and retries.
5. nslookup
If you know the IP address it will display hostname. To find all the IP addresses for a given domain name,
the command nslookup is used. You must have a connection to the internet for this utility to be useful.
You can also use nslookup to convert hostname to IP Address and from IP Address from hostname.
6. traceroute
A handy utility to view the number of hops and response time to get to a remote system or web site is
traceroute. Again you need an internet connection to make use of this tool.
7. finger
View user information, displays a user’s login name, real name, terminal name and write status. this is
pretty old unix command and rarely used now days.
8. telnet
Connects destination host via telnet protocol, if telnet connection establish on any port means connectivity
between two hosts is working fine.
telnet hostname port - will telnet hostname with the port specified. Normally it is used to see whether host
is alive and network connection is fine or not.
9. ethtool
Ethtool lets you view and change many different settings for ethernet adapters (which does not include
Wi-Fi cards). You can manage many different advanced settings, including tx/rx, checksumming, and
wake-on-LAN settings. However, here are more basic commands you might be interested in:
Display the driver information for a specific network adapter, great when checking for software
compatibility.
ethtool -i
Initiate an adapter-specific action, usually blinking the LED lights on the adapter, to help you identify
between multiple adapters or interface names:
ethtool -p
Display network statistics:
ethtool -s
10. netstat
Most useful and very versatile Linux command for finding connection to and from the host. You can find
out all the multicast groups (network) subscribed by this host by issuing "netstat -g"
netstat -nap | grep port will display process id of application which is using that port
netstat -a or netstat –all will display all connections including TCP and UDP
netstat --tcp or netstat –t will display only TCP connection
netstat --udp or netstat –u will display only UDP connection
netstat -g will display all multicast network subscribed by this host.
Linux Server Monitoring and Networking Commands for Linux Server Administrators - Part 2
I have complied a list Linux server monitoring and networking commands for Linux server administrators.
These are the very basic monitoring and networking commands which each Linux server administrator
should know. I had also compiled a list of basic Linux Networking and Monitoring commands in my
previous article. I will talk about iostat, meminfo, free, mpstat, netstat, nmon, pmap, ps, pstree, sar,
strace, tcpdump, top, uptime, vmstat, wireshark Linux server monitoring and networking commands for
Linux server administrators. These networking and monitoring Linux server commands helps Linux server
administrators to identify input/output problems on your Linux server, memory management of Linux
server, performance of Linux server, CPU usage, socket usage, routing, interface, protocol, network
statistics and lot more.
1. iostat
The iostat command shows in detail what your storage subsystem is up to. You usually use iostat to
monitor how well your storage sub-systems are working in general and to spot slow input/output problems
before your clients notice that the server is running slowly.
Meminfo gives you a detailed list of what's going on in memory. Typically you access meminfo's data by
using another program such as cat or grep. For example,
cat /proc/meminfo
gives you the details of what's going on in your server’s memory at any given moment.
For a quick “just the facts” look at memory, you can use the free command. In short, free gives you the
overview; meminfo gives you the details.
3. mpstat
The mpstat command reports on the activities of each of the available CPUs on a multi-processor server.
These days, thanks to multi-core processors, that’s almost all servers. mpstat also reports on the average
activities of all your server's CPUs. It enables you to display overall CPU statistics per system or per
processor. This overview can alert you to possible application problems before they get to the point of
annoying users.
4. netstat
Netstat, like ps, is a Linux tool that administrators use every day. It displays a lot of network related
information, such as socket usage, routing, interface, protocol, network statistics, and more. Some of the
most commonly used options are:
5. nmon
Nmon, short for Nigel's Monitor, is a popular open-source tool to monitor Linux systems performance.
Nmon watches the performance information for several subsystems, such as processor utilization,
memory utilization, run queue information, disk I/O statistics, network I/O statistics, paging activity, and
process metrics. You can then view nmon's real-time system measurements via its curses “graphical”
interface.
To run nmon, you start the tool from the shell. Once up, you select the subsystems to monitor by typing in
its one-key commands. For example, to get CPU, memory, and disk statistics, you type c, m, and d. You
can also use nmon with the -f flag to save performance statistics to a CSV file for later analysis.
For day to day server monitoring I find nmon to be the single most useful program in my Linux system
management tool-kit.
6. pmap
The pmap command reports the amount of memory that your server's processes are using. You can use
this tool to determine which processes on the server are being allocated memory and whether any of
these processes are being piggy with RAM.
7. ps and pstree
The ps and pstree commands are two of the Linux administrator’s best friends. They both provide a list of
all currently running processes. Ps tells you how much memory and processor time the server’s programs
are using. Pstree shows less information, but highlights which processes are the children of other
processes. Armed with this information, you can spot out–of-control processes and kill them off with
Linux's “take no prisoners” kill command.
8. sar
The sar program is a Swiss-army knife of a system monitoring tool. The sar command is actually made up
of three programs: sar, which displays the data, and sa1 and sa2, which collect and store it. Once
installed, sar creates a detailed overview of CPU utilization, memory paging, network I/O and transfer
statistics, process creation activity, and storage device activity. The big difference between sar and nmon
is that the former is better at long-term system monitoring, while I find nmon to be better at giving me a
quick read on my server's status.
9. strace
strace is often thought of a programmer's debugging tool, but it's more than that. It intercepts and records
the system calls that are called by a process. This makes it a useful diagnostic, instructional, and
debugging tool. For example, you can use strace to find out which configuration file a program is actually
using when it starts up.
Strace does have one flaw though. When it's checking out a specific process, that process' performance
will fall through the floor. Thus, I only use strace when I already have a darned good reason to think that
that program is causing trouble.
10. tcpdump
Tcpdump is a simple, robust network monitoring utility. Its basic protocol analyzing capability enables you
to get a rough view of what is happening on your network. To really dig into what's going on with your
network however, you'll want to use Wireshark.
11. top
The top command shows what's going on with your active processes. By default, it displays the most
CPU-intensive tasks running on the server and updates the list every five seconds. You can sort the
processes by PID (Process ID); age, newest first; time, by cumulative time; and resident memory usage
and total time it's been using the CPU since startup. I find this a fast and easy way to see if any process is
starting to go out of control and about to get into trouble.
12. uptime
Use uptime to see how long the server has been running and how many users are logged on. It also gives
you an overview of the average server load. The optimal value of the load is 1 or less, which means that
each process has immediate access to the CPU and there are no CPU cycles lost.
14. vmstat
For the most part, you use vmstat to monitor what's going on with virtual memory. Linux constantly uses
virtual memory to get the best possible storage performance.
If your applications are taking up too much memory you get excessive page-outs — programs moving
from RAM to your system's swap space, which is on the hard drive. Your server can reach a point where
it's spending more time managing memory paging than running your applications, a condition called
thrashing. When your computer is thrashing, its performance falls through the floor.
Vmstat, which can display either average data or actual samples, can help you spot memory pig
programs and processes before they bring your server to a crawl.
15. Wireshark
Wireshark, formerly known as Ethereal (and still often referred to that way), is tcpdump's big brother,
though it is more sophisticated and with far more advanced protocol analyzing and reporting. Wireshark
has both a GUI interface and a shell interface.
If you can master these commands, you'll be well on your way to being a good Linux system
administrator.
Ans:- The rsync command is incremental copy(check the files with destination and copies rest of
the part).
Ans:- In RAID 5 , if one disk is corrupted , we can replace that effective drive without any
downtime. But here the scenario is two disks are corrupted , in this case we don’t have much
option left. Need to replace all the effective disks and rebuild the OS. If we kept two spare hard
disk while creating RAID , the situation will be different.
Ans. Hard mount:
— If the NFS file system is hard mounted, the NFS daemons will try repeatedly to contact the
server. The NFS daemon retries will not time out, will affect system performance, and you
cannot interrupt them.
Soft mount
— If the NFS file system is soft mounted, NFS will try repeatedly to contact the server until
either:
A connection is established
When one of these events occurs, control returns to the calling program.
Ans. procfs (or the proc file system is a special file system in UNIX-like operating systems that
presents information about processes and other system information in a hierarchical file-like
structure, providing a more convenient and standardized method for dynamically accessing
process data held in the kernel than traditional tracing methods or direct access to kernel
memory.
Ans. syslogd
7.what is difference between raid 0 and raid 1?
RAID 1, Redundancy
Ans. A kernel panic is an action taken by an operating system upon detecting an internal fatal
error from which it cannot safely recover. The term is largely specific to Unix and Unix-like
systems; for Microsoft Windows operating systems the equivalent term is “bug check” (or “Blue
Screen of Death”).
10.what is the last service started by init before logging screen appears?
Ans. /etc/rc.local which are the last commands run in initialization process or even booting
process
Ans. LILO, Linux Loader, on kernel versions < 2.4,It does’nt support booting from n/w.
Grub, Grand unified boot loader. on Kernel versions >= 2.6, supports booting from network.
Ans.6 stages.
1. BIOS
2. MBR
3. GRUB
4. Kernel
5. Init
6. Runlevels
13.when two machines are there, one machine MAC & IP address is known, another machine
MAC address is there, how to find IP of another machine using command?
14.while ‘ping’ cmd is used the system not receiving any o/p?
Ans. ping cmd is blocked in kernel parameters
15.Issue is there with hard drives ,dont know which drive is fault. how to check which drive is
fault?
Ans. If it is HP and IBM Servers, it will show amber color for faulty HDD. otherwise we can
see the status of the hard disks in ILO (Integrated Lights Out)configuration for HP servers and
the same remote accessing feature also available for IBM. other wise you can check in dmesg .
16.In production server one drive got failed,how to replace new drive?
Ans. plug and play devices, in raid -1 mirror is used machine can run with one hard disk . we can
replace
Ans. N/w Bonding will configure on the servers for redundancy. It requires minimum 2 Ethernet
Ports/Cards.
19. MI means?
Ans. crazy question, i will say /bin/mount., But it is mount command full form. I heared
guestmount commnad also there to mount a disk …but didn’t used yet.
List available cpus and their caracteristics , Not available on older distribution
Command: lshal
Require HAL (Hardware Abstraction Layer) to be installed . List all hardware visible by HAL
Command: lshw
Available on Debian and Ubuntu based distributions by default .Available in the Fedora
repositories .Uses many inputs to detect all hardware: Kernel, HAL, DMI, etc. use ‘-html’
switch that generates hardware reports
Command: lspci
Standard command ,List all hardware connected to the PCI bus as detected by the kernel
Command: lsusb
Standard command. List all hardware connected to the USB buses as detected by the kernel
Command: dmidecode
Standard command, Get the source information from the DMI (a kind of BIOS interface) .List all
hardware as reported by the DMI interface
/dev/sda1
28. Newly attached hard drive is not recognizing how to make it active ?
Ans. After building server with 2 hard disks, again if we attach any hdd, server wont recognizes
it. if the server want to recognize it, we need to reboot it and create RIAD fo that HDD also.
If we replaced Faulty hard disk with new one, Server will take 1 hr time to synchronize the data
(RIAD 1 and RAID 5).
Ans. raid 0, raid1, raid1+0, raid 1+0, raid3, raid 5, raid50, raid6.
30.file system is full? user need some space to run his work ?
Ans. 1. If it is configured with ‘lvm’ we can extend it, or else we can make use of reserved
blocks.
Ans. rpm -qa | grep <package name>, it will gives package name and version, if it installed,
returns empty screen if not installed.
Ans. vi /etc/sysconfig/network-scripts/ifcfg-route0
35.what is GRUB?
Ans. Grand unified Boot loader. Its boot loader in linux. (kernel versions >=2.6)
Ans. df or mount
37.How to increase physical memory in steps?
Ans. Hardware job, Its requires a down time form the users/customers , to upgrade memory
modules . (memory size should be match with old memory modules.)
41.I am sharing a directory through samba , everything is accessible apart from soft link files
,how to share those soft links shares?
Ans. The ext4 file system can support volumes with sizes up to 1 exbibyte (EiB) and files with
sizes up to 16 tebibytes (TiB). However, Red Hat recommends using XFS instead of ext4 for
volumes larger than 100 TB.
43.scenerio
# df -h
#ls -l
# rm -f filename
#df -h
#ls -l
Ans.
If it’s safe to do so, take the pid from the lsof command, and do:
Code:
Otherwise the space will be freed when the application using it closes, or the system restarts.
Reasons: Check it , by logging as a root. might be normal user not having the permissions to
view it.
we will get these type of messages, if the directory or file is unmounted or deleted.
Ans.
Iostat without any argument displays information about the CPU usage, and I/O statistics about
all the partitions on the system as shown below.
#iostat
vmstat : vmstat by default will display the memory usage (including swap) as shown below.
#vmstat
IO – bi: Blocks in. i.e blocks received from device (for every second)
IO – bo: Blocks out. i.e blocks sent to the device (for every second)
CPU – us, sy, id, wa, st: CPU user time, system time, idle time, wait time
Ans. initrd stands for Initial RAM Disk. initrd is used by kernel as temporary root file system
until kernel is booted and the real root file system is mounted. It also contains necessary drivers
compiled inside, which helps it to access the hard drive partitions, and other hardware parts of
the server.
Ans. Linux systems store all data as files. Most users are familiar with the two primary types of
files: text and binary. But the /proc/ directory contains another type of file called a virtual file. As
such, /proc/ is often referred to as a virtual file system.
Ans. Tmpfs is a file system which keeps all files in virtual memory. Everything in tmpfs is
temporary in the sense that no files will be created on your hard drive. If you unmount a tmpfs
instance, everything stored therein is lost. tmpfs lives completely in the page cache and on swap,
all tmpfs pages currently in memory will show up as cached
51.Daemons in nfs?
53.why UMASK is used, where to change its value to be effective on entire OS?
Ans. When user create a file or directory under Linux or UNIX, it creates with a default set of
permissions. In most case the system defaults may be open or relaxed for file sharing purpose.
For example, if a text file has 666 permissions, it grants read and write permission to everyone.
Similarly a directory with 777 permissions, grants read, write, and execute permission to
everyone.
You can setup umask in /etc/bashrc or /etc/profile file for all users. By default most Linux
machines set it to 0022 (022) or 0002 (002).
# vi /etc/profile
OR
# vi ~/.bashrc
umask 022
Save and close the file. Changes will take effect after next login. All UNIX users can override
the system umask defaults in their /etc/profile file, ~/.profile (Korn / Bourne shell) ~/.cshrc file
(C shells), ~/.bash_profile (Bash shell) or ~/.login file (defines the user’s environment at login).
55.what is SFTP?
Ans.secure file transfer protocol, a network protocol for secure file transfer over a secure shell.
Ans. vmstat
Ans.crontab -l
58.what is MTA?
59.while install rpm package, progress reports already use , but no package name doesn’t exist
in rpm list ?
Errors:—
I got this error message while Logging (doing ssh) into one production server. Please do the
Following things to fix it. It doesn’t requires any reboot and it wont effect to production.
It is a character file, The permissions should be 666 for this one. So , change the permission to
666. after that you wont see that message.
(OR)
You can delete it and recreate the /dev/null file. But first solution is little bit faster.
To Remove it..
#rm -f /dev/null
#mknod /dev/null c 1 3
This creates the /dev/null special file that is a special character file with the major device number
1 and the minor device number 3.
# /etc/init.d/sshd start
# /etc/init.d/sshd status
LVM stands for Logical Volume Manager. It is used to resize the file system online.
3. What is umask?
umask stands for “user file creation mask”. It is used to determine those settings of a mask that control file
permission data and directory data.
4. In the context of Linux, what does
POSIX stand for?
POSIX stands for Portable Operating System Interface for Computer Environments. It is the de facto standard
for ensuring compatibility between UNIX versions.
The kernel that Linux uses resembles that of UNIX but does not require UNIX code.
GPL stands for General Public License. It was originally created to protect the GNU project.
GNU is a project that was initiated by Richard Stallman in 1983 at MIT. The project began with the idea of
providing control and freedom to the users in using software. As part of the GNU project, users are free to
use, run, copy and share software.
8. How do you turn a Linux system
into a proxy server?
Using the Squid service, you can turn a Linux system into a proxy server.
LILO is a boot loader for Linux. It is used for loading the Linux operating system into the main system
memory before beginning operations.
1 0 . D e fi n e B I O S , M B R a n d G R U B .
BIOS stands for Basic Input/Output System. MBR is Master Boot Record and GRUB is Graand Unified
Bootloader.
1 1 . W h a t i s t h e d i ff e r e n c e b e t w e e n
home directory and working
directory?
Home directory is the default directory when a user logs in whereas working directory is the user’s current
working directory.
12. In Linux, how do you track
system events?
We should first block the suspicious IP by integrating tcp_wrapper. Next, we need to enable the
“tcp_wrapper=YES” parameter in the configuration file at ‘/etc/vsftpd.conf’. Final step – include the
suspicious IP in the ‘host.deny’ file in ‘/etc/host.deny’.
Both Telnet and SSH are communication protocols that are used to manage systems remotely. While SSH
requires exchange of keys, Telnet transmits data in plain text. Hence, SSH is said to be more secure than
Telnet.
1 5 . S t a t e t h e d i ff e r e n c e b e t w e e n t h e
locate and slocate commands.
Locate searches for a file with the latest entries while slocate searches for files that users have accessed
most recently.
16. How many partitions do you need
to install Linux?
By using the dmesg command. Dmesg will pull out boot messages stored in the kernel ring buffer.
Symbolic links are “shortcut keys” in Linux. These links point to specific programs, files or directories.
Hard links point directly to the physical file located on the disk, and not on the path name.