Linux Interview Notes
Linux Interview Notes
1. BIOS
▪ BIOS stands for Basic Input/Output System
▪ Performs some system integrity checks
▪ Searches, loads, and executes the boot loader program.
▪ It looks for boot loader in floppy, cd-rom, or hard drive. You can press a key
(typically F12 of F2, but it depends on your system) during the BIOS startup to
change the boot sequence.
▪ Once the boot loader program is detected and loaded into the memory, BIOS gives
the control to it.
▪ So, in simple terms BIOS loads and executes the MBR boot loader.
2. MBR
▪ MBR stands for Master Boot Record.
▪ It is located in the 1st sector of the bootable disk. Typically /dev/hda, or /dev/sda
▪ MBR is less than 512 bytes in size. This has three components 1) primary boot loader
info in 1st 446 bytes 2) partition table info in next 64 bytes 3) mbr validation check
in last 2 bytes.
▪ It contains information about GRUB (or LILO in old systems).
▪ So, in simple terms MBR loads and executes the GRUB boot loader.
3. GRUB
▪ GRUB stands for Grand Unified Bootloader.
▪ If you have multiple kernel images installed on your system, you can choose which
one to be executed.
▪ GRUB displays a splash screen, waits for few seconds, if you don’t enter anything, it
selects the default kernel image as specified in the grub configuration file.
▪ GRUB has the knowledge of the filesystem (the older Linux loader LILO didn’t
understand filesystem).
▪ Grub configuration file is /boot/grub/grub.conf (/etc/grub.conf is a link to this).
The following is sample grub.conf of CentOS.
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/boot/grub/splash.xpm.gz
hiddenmenu
root (hd0,0)
initrd /boot/initrd-2.6.18-194.el5PAE.img
▪ As you notice from the above info, it contains kernel and initrd image.
▪ So, in simple terms GRUB just loads and executes Kernel and initrd images.
4. Kernel
▪ Mounts the root file system as specified in the “root=” in grub.conf
▪ Kernel executes the /sbin/init program
▪ Since init was the 1st program to be executed by Linux Kernel, it has the process id
(PID) of 1. Do a ‘ps -ef | grep init’ and check the pid.
▪ 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.
5. Init
▪ Looks at the /etc/inittab file to decide the Linux run level.
▪ Following are the available run levels
▪ 0 – halt
▪ 1 – Single user mode
▪ 2 – Multiuser, without NFS
▪ 3 – Full multiuser mode
▪ 4 – unused
▪ 5 – X11
▪ 6 – reboot
▪ Init identifies the default initlevel from /etc/inittab and uses that to load all
appropriate program.
▪ Execute ‘grep initdefault /etc/inittab’ on your system to identify the default run level
▪ If you want to get into trouble, you can set the default run level to 0 or 6. Since you
know what 0 and 6 means, probably you might not do that.
▪ Typically you would set the default run level to either 3 or 5.
6. Runlevel programs
▪ When the Linux system is booting up, you might see various services getting started.
For example, it might say “starting sendmail …. OK”. Those are the runlevel
programs, executed from the run level directory as defined by your run level.
▪ Depending on your default init level setting, the system will execute the programs
from one of the following directories.
▪ Run level 0 – /etc/rc.d/rc0.d/
▪ Run level 1 – /etc/rc.d/rc1.d/
▪ Run level 2 – /etc/rc.d/rc2.d/
▪ Run level 3 – /etc/rc.d/rc3.d/
▪ Run level 4 – /etc/rc.d/rc4.d/
▪ Run level 5 – /etc/rc.d/rc5.d/
▪ Run level 6 – /etc/rc.d/rc6.d/
▪ Please note that there are also symbolic links available for these directory under /etc
directly. So, /etc/rc0.d is linked to /etc/rc.d/rc0.d.
▪ Under the /etc/rc.d/rc*.d/ directories, you would see programs that start with S and
K.
▪ Programs starts with S are used during startup. S for startup.
▪ Programs starts with K are used during shutdown. K for kill.
▪ There are numbers right next to S and K in the program names. Those are the
sequence number in which the programs should be started or killed.
▪ For example, S12syslog is to start the syslog deamon, which has the sequence
number of 12. S80sendmail is to start the sendmail daemon, which has the sequence
number of 80. So, syslog program will be started before sendmail.
There you have it. That is what happens during the Linux boot process.
If you have a Linux server and a Linux client, those two should share data
via NFS rather than Samba/CIFS.
What is Samba/CIFS?
Samba is a file sharing utility using the CIFS protocol, specifically aimed at
allowing Windows and Linux servers to access the same file systems. The normal setup
is to have the data drives mounted on a Linux server and shared out
using Samba and NFS. The Windows clients can then mount those drives using
a Samba client and the Linux clients can mount them with NFS.
What is a Firewall?
A firewall is simply a utility that manages network traffic access to and from a machine,
whether a server or a desktop. Windows users will be familiar with the proprietary
firewalls available, such as Symantec, Norton or Kaspersky which are vital for stopping
unwanted processes getting access to their machine. The standard Linux firewall
package is called iptables (-aka netfilter).
[A firewall] allows you to define rules which specify which traffic to allow or disallow.
There are three types of traffic that you can add a rule for-
• Inbound: traffic coming from the network and destined for your computer. This
is the category to use to control external attacks and is therefore the most
common category where controls are applied
• Outbound: traffic coming from your computer and destined for somewhere on
the network. This is the category to use to control the resources that users on this
computer can access (-normally used for things like stopping users of a PC
connecting to various external services - e.g. a network printer or server
containing sensitive data)
• Forward: traffic coming from outside your computer and destined for somewhere
on the network, but passing through your PC. This is only really relevant if your
machine is set up as a network router.
ISCSI is an Internet Protocol (IP)-based storage networking standard for linking data
storage facilities. By carrying SCSI commands over IP networks, iSCSI is used to
facilitate data transfers over intranets and to manage storage over long distances. iSCSI
can be used to transmit data over local area networks (LANs), wide area networks
(WANs), or the Internet, and can enable location-independent data storage and
retrieval.
iSCSI allows clients (called Initiators) to send SCSI commands (CDBs) to SCSI storage
devices (LinuxIOs) on remote servers. It is a popular SAN protocol, allowing
organizations to consolidate storage into data center storage arrays while providing
hosts (such as database and web servers) with the illusion of locally-attached disks.
Unlike traditional Fibre Channel, which requires special-purpose cabling, iSCSI can be
run over long distances using existing network infrastructure.
df command - Shows the amount of disk space used and available on Linux file
systems.
du command - Display the amount of disk space used by the specified files and
for each subdirectory.
The top command provides dynamic view of CPU utilization. It displays system
information as well as list of tasks currently managed by kernel. It also displays uptime,
average load, physical and swap memory utilization.
Commands to check the Linux Version, Release name & Kernel version.
cat /proc/version
cat /etc/issue
cat /etc/redhat-release
tail /etc/redhat-release
uptime gives a one line display of the following information. The current time, how
long the system has been running, how many users are currently logged on, and the
system load averages for the past 1, 5, and 15 minutes.
Clearly from the behaviour above SIGTERM is the default and safest way to kill a
process. SIGHUP is less secure way of killing a process as SIGTERM. SIGKILL is
the most unsafe way among the above three, to kill a process which terminates a
process without saving.
pidof mysqld
pgrep mysq
Sample Output
3139
To kill the above process PID, use the kill command as shown.
kill -9 3139
• Creating logical volumes from the volume groups and assign the logical volumes
mount points.
What is DNS?
Short for Domain Name System (or Service or Server), an Internet service that translates domain
names into IP addresses. Because domain names are alphabetic, they're easier to remember. The
Internet however, is really based on IP addresses. Every time you use a domain name, therefore,
a DNS service must translate the name into the corresponding IP address. For example, the
domain name www.example.com might translate to 198.105.232.4.
What is IP tables?
Iptables is a Linux command line firewall that allows system administrators to manage incoming
and outgoing traffic via a set of configurable table rules.
Iptables uses a set of tables which have chains that contain set of built-in or user defined
rules. Thanks to them a system administrator can properly filter the network traffic of his system.
FILTER – this is the default table, which contains the built in chains for:
NAT – a table that is consulted when a packet tries to create a new connection. It has the
following built-in:
Daemon Description
nfsd The NFS daemon which services requests from NFS clients.
mountd The NFS mount daemon which carries out requests received from nfsd.
rpcbind This daemon allows NFS clients to discover which port the NFS server is using.
A daemon (also known as background processes) is a Linux or UNIX program that runs in the
background. Almost all daemons have names that end with the letter "d". For example, httpd the
daemon that handles the Apache server, or, sshd which handles SSH remote access connections.
Linux often start daemons at boot time. Shell scripts stored in /etc/init.d directory are used to
start and stop daemons.
They are the processes which run in the background and are not interactive. They have no
controlling terminal.
service --status-all
Normally, we can easily check the state of a network interface card like whether the cable
plugged in to the slot or the network card is up or down in Graphical mode. What if you have
only command line mode? Ofcourse, you can turn around the system and check for the cable is
properly plugged in, or you can do the same easily from your Terminal. Here is how to do that.
This method is almost same for Debian and RPM based systems.
I have two Ethernet cards on my laptop. One, eth0 is wired, and another, wlan0, is wireless.
cat /sys/class/net/eth0/carrier
Sample output:
cat /sys/class/net/eth0/operstate
Sample output:
down
One of the issue is, you may not know the names of the interfaces. In that case, run the following
command. It will show all the installed interfaces, they generally follow the rule that wired
interfaces start with the letter “e” and wireless start with a letter “w”.
ls /sys/class/net/
How do I display all available network interfaces names under Linux operating systems using
bash shell prompt?
$ ip link show
Sample outputs:
$ 1: lo: mtu 16436 qdisc noqueue state UNKNOWN
link/ppp
Where,
1. lo – Loopback interface.
2. eth0 – First Ethernet network interface.
3. wlan0 – First Wireless network interface.
4. ppp0 – First Point to Point Protocol network interface which can be used by dial up
modem, PPTP vpn connection, or 3G wireless USB modem./li>
5. vboxnet0, vmnet1, vmnet8 – Virtual machine interface working in bridge mode or NAT
mode.
$ netstat –i
Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-
DRP TX-OVR Flg
vmnet8 1500 0 0 0 0 0 49 0
0 0 BMRU
$ /sbin/ifconfig –a
Sample outputs:
collisions:0 txqueuelen:1000
Interrupt:17
collisions:0 txqueuelen:0
collisions:0 txqueuelen:3
collisions:0 txqueuelen:1000
Collisions: 0 txqueuelen:1000
To check inode number of file use following command. The first field in
output is an inode number of the file.
ls -il myfile.txt
You can also search file with an inode number using find command.
For example:
/home/rahul/myfile.txt
Methods to Check Number of CPU Cores in Linux
Let’s check if the system is using swap space with free command
# free
total used free shared buff/cache available
Mem: 3742792 2421060 433696 287376 888036
967000
Swap: 0 0 0
What is LDAP?
slapd.conf
ldap.conf
date –d “+60days”
chage –d 0 shashank
/home/anuj
LSOF command
As we all know Linux/Unix considers everything as a files
(pipes, sockets, directories, devices etc). One of the reason to use lsof command is when a disk
cannot be unmounted as it says the files are being used. With the help of this command we can
easily identify the files which are in use.
Sections and it’s values are self-explanatory. However, we’ll review FD & TYPE columns more
precisely.
FD – stands for File descriptor and may seen some of the values as:
1. cwd current working directory
2. rtd root directory
3. txt program text (code and data)
4. mem memory-mapped file
# lsof -u tecmint
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
sshd 1838 tecmint cwd DIR 253,0 4096 2 /
sshd 1838 tecmint rtd DIR 253,0 4096 2 /
sshd 1838 tecmint txt REG 253,0 532336 188129 /usr/sbin/sshd
sshd 1838 tecmint mem REG 253,0 19784 190237 /lib/libdl-
2.12.so
sshd 1838 tecmint mem REG 253,0 122436 190247
/lib/libselinux.so.1
sshd 1838 tecmint mem REG 253,0 255968 190256
/lib/libgssapi_krb5.so.2.2
sshd 1838 tecmint mem REG 253,0 874580 190255
/lib/libkrb5.so.3.3
Find Processes running on Specific Port
# lsof -i TCP:22
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
sshd 1471 root 3u IPv4 12683 0t0 TCP *:ssh (LISTEN)
sshd 1471 root 4u IPv6 12685 0t0 TCP *:ssh (LISTEN)
9. Search by PID
The below example only shows whose PID is 1 [One].
# lsof -p 1
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
init 1 root cwd DIR 253,0 4096 2 /
init 1 root rtd DIR 253,0 4096 2 /
init 1 root txt REG 253,0 145180 147164 /sbin/init
init 1 root mem REG 253,0 1889704 190149 /lib/libc-2.12.so
init 1 root mem REG 253,0 142472 189970 /lib/ld-2.12.so
10. Kill all Activity of Particular User
Sometimes you may have to kill all the processes for a specific user. Below
command will kills all the processes of tecmint user.
# kill -9 `lsof -t -u tecmint`
• Symbolic values
• Octal values
As I said earlier, if the default settings are not changed, files are created with the access mode 666
and directories with 777. In this example:
1. The default umask 002 used for normal user. With this mask default directory permissions are
775 and default file permissions are 664.
2. The default umask for the root user is 022 result into default directory permissions are 755
and default file permissions are 644.
3. For directories, the base permissions are (rwxrwxrwx) 0777 and for files they are 0666 (rw-rw-
rw).
In short,
1. A umask of 022 allows only you to write data, but anyone can read data.
2. A umask of 077 is good for a completely private system. No other user can read or write your
data if umask is set to 077.
3. A umask of 002 is good when you share data with other users in the same group. Members of
your group can create and modify data files; those outside your group can read data file, but
cannot modify it. Set your umask to 007 to completely exclude users who are not group
members.
The octal umasks are calculated via the bitwise AND of the unary complement of the argument using
bitwise NOT. The octal notations are as follows:
Now, you can use above table to calculate file permission. For example, if umask is set to 077, the
permission can be calculated as follows:
7 Group No permissions
7 Others No permissions
To set the umask 077 type the following command at shell prompt:
$ umask 077
$ mkdir dir1
$ touch file
$ ls -ld dir1 file
Sample outputs:
What is NAT?
A. Network Address Translation (NAT) is designed for IP address conservation. It enables private IP networks
that use unregistered IP addresses to connect to the Internet. NAT operates on a router, usually connecting two
networks together, and translates the private (not globally unique) addresses in the internal network into legal
addresses, before packets are forwarded to another network.
As part of this capability, NAT can be configured to advertise only one address for the entire network to the
outside world. This provides additional security by effectively hiding the entire internal network behind that
address. NAT offers the dual functions of security and address conservation and is typically implemented in
remote-access environments.
A public IP address is an IP address that can be accessed over the Internet. Like postal address used to deliver
a postal mail to your home, a public IP address is the globally unique IP address assigned to a computing
device. Your public IP address can be found at What is my IP Address page. Private IP address, on the other
hand, is used to assign computers within your private space without letting them directly expose to the
Internet. For example, if you have multiple computers within your home you may want to use private IP
addresses to address each computer within your home. In this scenario, your router gets the public IP address,
and each of the computers, tablets and smartphones connected to your router (via wired or wifi) gets a private
IP address from your router via DHCP protocol.
Reboot
Any of the following commands will reboot the system from the command line.
# reboot
# shutdown -r now
# init 6
Shutdown
# shutdown -h now
# init 0
Cd command in linux-
avi@tecmint:/usr/local/lib/python3.4/dist-packages$ cd
../../../../../home/avi/Desktop/
avi@tecmint:~/Desktop$
/etc/sysconfig/network
/etc/sysconfig/network-scripts/ifcfg-eth0
NETWORKING=yes
HOSTNAME=node01.tecmint.com
GATEWAY=192.168.0.1
NETWORKING_IPV6=no
IPV6INIT=no
Next open:
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
Make sure to open the file corresponding to your network interface. You
can find your network interface name with ifconfig -a command.
DEVICE="eth0"
BOOTPROTO="static"
DNS1="8.8.8.8"
DNS2="4.4.4.4"
GATEWAY="192.168.0.1"
HOSTNAME="node01.tecmint.com"
HWADDR="00:19:99:A4:46:AB"
IPADDR="192.68.0.100"
NETMASK="255.255.255.0"
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Ethernet"
UUID="8105c095-799b-4f5a-a445-c6d7c3681f07"
For installing an rpm software package, use the following command with -
i option. For example, to install an rpm package called pidgin-2.7.9-
5.el6.2.i686.rpm
httpd-tools-2.2.15-15.el6.centos.1.i686
URL : http://vsftpd.beasts.org/
What's CPU Socket: CPU socket or CPU slot is the connector on the
motherboard that allows a computer processor to be connected to a
motherboard. It’s called a physical CPU (central processing unit).
What's CPU Core: Originally, CPUs had a single core but manufacturers
added additional cores in to that to increase performance, that’s why core
came to picture. For example, a dual-core CPU has two central processing
units, so it appears to the operating system as two CPUs.
like that, a quad-core CPU has four central processing units and an octa-
core CPU has eight central processing units.
CPU(s): 32
On-line CPU(s) list: 0-31
Thread(s) per core: 2
Core(s) per socket: 8
Socket(s): 2
The calculation is below: CPUs = Threads per core X cores per socket X
sockets.
2 x 8 x 2 = 32
Using Variables
With awk, you can process text files. Awk assigns some variables for each
data field found:
$0 for the whole line.
$1 for the first field.
$2 for the second field.
$n for the nth field
The first command makes the $2 field equals Adam. The second command
prints the entire line.
Awk Preprocessing
awk 'BEGIN {print "The File Contents:"} {print $0}' myfile.txt
Awk Postprocessing
To run a script after processing the data, use the END keyword:
$ awk 'BEGIN {print "The File Contents:"}
{print $0}
BEGIN {
FS=":"
END {
First, the top section is created using BEGIN keyword. Then we define the
FS and print the footer at the end.
But these are not the only variables, there are more built-in variables.
You can use bash variables without ENVIRON variables like this:
$ echo | awk -v home=$HOME '{print "My home is " home}'
The NF variable specifies the last field in the record without knowing its
position:
$ awk 'BEGIN{FS=":"; OFS=":"} {print $1,$NF}' /etc/passwd
String Functions
There are many string functions, you can check the list, but we will
examine one of them as an example and the rest is the same:
Shell Scripting
The parameters are not restricted to numbers, they could be strings like
this:
#!/bin/bash
echo Hello $1, how do you do
Getting user input using the read command
#!/bin/bash
read name
https://likegeeks.com/awk-command/
https://likegeeks.com/linux-bash-scripting-awesome-guide-part3/
# ntpq –p
# date -R
NTP service uses UDP port 123 on OSI transport layer (layer 4). It is
designed particularly to resist the effects of variable latency (jitter). To
open this port on RHEL/CentOS 7 run the following commands against Firewalld
service.
CPU utilization by
#!/bin/bash
echo "Enter filename to remove"
read fn
rm -i $fn
#!/bin/bash
filename=$1
if [ -f "$filename" ]; then
echo "File exists"
else
echo "File does not exist"
fi
#!/bin/bash
Year=`date +%Y`
Month=`date +%m`
Day=`date +%d`
Hour=`date +%H`
Minute=`date +%M`
Second=`date +%S`
echo `date`
echo "Current Date is: $Day-$Month-$Year"
echo "Current Time is: $Hour:$Minute:$Second"
https://ma.ttias.be/linux-date-format-change-the-date-output-for-scripts-or-
commands/
To display your date and time with UTC format, use -u parameter
$ date –u
Thu 6 Dec 17:34:11 UTC 2018
$ date +"%T"
21:55:16
$ date +"%Y-%m-%d"
2015-12-30
date +"%Y/%m/%d"
2018/12/06
Or a more complete example which follows the Apache log format of displaying
dates (ie: [30/Dec/2015:21:48:45 +0100]).
date +"%d:%b:%Y"
06:Dec:2018
The date command also allows you pretty easy manipulation of the "current
date". By default, date refers to "NOW". It'll show the current time or date
when you execute the command. With the –d parameter you can also let it jump
back & forth and show you a different date.
$ date +"%Y-%m-%d"
2015-12-30
$ date +"%Y-%m-%d" -d "8 days ago"
2015-12-22
$ date +"%Y-%m-%d" -d "next Sunday"
2016-01-03
$ date +"%Y-%m-%d" -d "last Friday"
2015-12-25
date +%D
12/06/18
The “../” means to move the folder up one level. If you're buried deeper, say
~/Downloads/today/, you can still easily move that file with:
mv testfile ../../
Applications of fc command
fc command is the best way to edit the previously entered commands in the
case of a minor mistake without re-writing the entire command syntax and
argument again.
It can also be used to list the previously entered commands in the terminal
which can be helpful in case you are working with some new commands.
fc command in a way lets you know the command history.
Using first and last : Suppose you want to just edit a particular set of
commands, in that case you can use first and last arguments as shown below :
• init 6
• shutdown -r now
• reboot
How to check the current run-level?
Check current runlevel: runlevel
A runlevel of "5" will boot the system into GUI mode using XDM and X-Windows. Booting to runlevel "3"
(often called console mode) is often used by servers which do not need a graphical user interface.
$ who -b
system boot 2013-08-01 17:56
Past reboots
If you're interested in seeing a more extensive list of previous reboots you can use
the last command.
You can use dmesg command to find out your duplex mode:
# dmesg | grep -i duplex
Touch -- -abc.txt
File based on special characters(-).
Now we want to open this –abc.txt file using vim it will not open for that
purpose we need to open the file using below option-
Vim -- -abc.txt
Find all files ending with extension .txt and delete them at the same time.
find . -name '*.txt' –delete
If you hit only find command then it will display the path names of all the
files in the current directory and subdirectories also.
Now if we want to search the directory here then we need to enter below
command.
Find . –type d –name abc
Find / –type d –name abc >> This command will find the directory abc in the
entire system.
Find / -mmin 1
Find all the files modified in last one minute.
Find all the files which are modified more than 10 days back and less than 20
days
Find / -mtime +10 –mtime -20
WC command
l for number of lines.
w for number of words
C for couting number of characters.
read –p examples
#!/bin/bash
#
read -p "Please Enter some words followed by ENTER: " vara varb varc
echo "vara contains $vara"
echo "varb contains $varb"
echo "varc contains any remaining words $varc"
#!/bin/bash
read -p " Enter your full name:" Firstname Middlename Lastname
echo "Your Name is $Firstname $Middlename $Lastname"
Arguments
#!/bin/bash
rm -rf *.txt
This command will delete all the files in a folder ending with .txt
extension.
Save it as ak.sh
You can instruct AWK to print only certain columns from the input field. The
following example demonstrates this −
Physics 80
Maths 90
Biology 87
English 85
History 89
Output
2) Rahul Maths 90
3) Shyam Biology 87
4) Kedar English 85
5) Hari History 89
Now if we want to know the marks of Rahul only then hit below command
2) Rahul Maths 90
Let us see an example where you can count and print the number of lines for
which a pattern match succeeded.
Now if you want to install RHEL7 in your machine, RedHat recommends minimum 5
GB of disk space to install this release of RHEL series for all supported
architectures.
.Hostname lookup and setup
In rhel5 and rhel6 versions, we can edit file /etc/sysconfig/network to set
hostname but in rhel7 we can directly change the hostname using below
commands.
hostnamectl
nmtui
nmcli
Example:
in RHEL6 #hostname
in RHEL7 #hostnamectl status and #hostname
Few More notable changes in RHEL 7.
Netstat and ifconfig commands also disappeared from RHEL7 but it can be used
by installing net-tools.
The move from sysvinit to systemd is one of most important change that has
been made and which is a matter of concerned.
Command tail -n is replaced by journalctl -n
Command tail -f is replaced by journalctl -f
For displaying kernel messages instead of dmesg now in RHEL7 we
use journalctl –k
A port in Linux is nothing but a logical connection place. The TCP/IP use
port for communication across the LAN, WAN, and Internet. Typically, a server
program such as Apache (httpd) listens on TCP port 80 or 443. A client
program such as a web browser connects to TCP port 80 to request web page.
You can find preassigned port numbers in /etc/services files with the help
of cat command or grep command/egrep command linux command. For example:
$ cat /etc/services
$ grep -w 80/tcp /etc/services
$ grep -w 443/tcp /etc/services
$ egrep -w '(80|22|443)/tcp' /etc/services
This last one will use rFile as a reference to set permission on file.
When completed, the permission of file will be exactly as they are
for rFile.
chmod --reference=/path/to/rFile /path/to/file
chmod u=rwx,o=r test1.txt
chmod u=rwx,o-x data1/
chmod --reference=data1 data2/
getfacl <folder-name>
Now you will see the output of getfacl as something like the following:
# file: file-name
# owner:
# group:
user::rwx
user:x:---
user:y:r--
group::r--
mask::rw-
other::---
Thus from the output of getfacl we will be able to see the access
permissions of a file. In the above example, when we type getfacl <file-
name>
the output will be shown as in the above format. It displays the owner of
the file, the group which has access to it and also its various users and
their access rights. In the above case the users are x and y, where the
user 'x' is having no permission on this file and therefore it is shown
with --- symbol indicating no read/write/execute permissions for the user
x. Now considering the other user 'y’, it is having the permission r--
which means read-only rights. The default umask is set to rw- (read/write
permissions).
Consider an example of copying the ACL of the directory named "x" to "y". For this, firstly
we should know the ACL of the directory named "x". To obtain this type the command
getfacl x
This will display the ACL of the directory named "x" in the above mentioned format:
# file: x
# owner:
# group:
user::rwx
user:x:---
user:y:r--
group::r--
mask::rw-
other::---
To copy the ACL of one directory to the other we use the setfacl command. That is
setfacl --setfile =- y
As mentioned we want to copy the ACL of "x" to "y", for this we have to type the command
Here "getfacl x" will get the ACL of the directory named "x" and this output is given to the
setfacl command using pipe. Thus getfacl will give the ACL of the directory "x" and
setfacl -R –setfile = -y
will set that ACL to the directory named "y". "-R" is used to set this ACL recursively.
How to inherit the ACL of parent directory to its child?
To copy the ACL of the parent directory to its child, use the following command
The "getfacl ." will get the ACL of the parent directory and setfacl will set that ACL to its sub-
directories. Now for verification, type:
getfacl subdirectory_name
and also
getfacl directory_name
If both are same then the ACL of the sub-directory is same as the ACL of the parent.
rsync command
Copy/Sync a Directory on Local Computer
The following command will transfer or sync all the files of from one
directory to a different directory in the same machine. Here in this
example, /root/rpmpkgs contains some rpm package files and you want that
directory to be copied inside /tmp/backups/ folder.
rpmpkgs/
rpmpkgs/httpd-2.2.3-82.el5.centos.i386.rpm
rpmpkgs/mod_ssl-2.2.3-82.el5.centos.i386.rpm
rpmpkgs/nagios-3.5.0.tar.gz
rpmpkgs/nagios-plugins-1.4.16.tar.gz
root@192.168.0.101's password:
./
httpd-2.2.3-82.el5.centos.i386.rpm
mod_ssl-2.2.3-82.el5.centos.i386.rpm
nagios-3.5.0.tar.gz
nagios-plugins-1.4.16.tar.gz
root@192.168.0.101's password:
./
httpd-2.2.3-82.el5.centos.i386.rpm
mod_ssl-2.2.3-82.el5.centos.i386.rpm
nagios-3.5.0.tar.gz
nagios-plugins-1.4.16.tar.gz
root@192.168.0.100's password:
rpmpkgs/
rpmpkgs/httpd-2.2.3-82.el5.centos.i386.rpm
rpmpkgs/mod_ssl-2.2.3-82.el5.centos.i386.rpm
rpmpkgs/nagios-3.5.0.tar.gz
rpmpkgs/nagios-plugins-1.4.16.tar.gz
backup.tar
[root@tecmint]# ll backup.tar
Use of this option will not make any changes only do a dry run of the
command and shows the output of the command, if the output shows exactly
same you want to do then you can remove ‘–dry-run‘ option from your
command and run on the terminal.
backup.tar
Vim extended
Or you can force vim to discard your changes and edit the new file, using
the force (!) character:
:edit! foo.txt
In vim we can execute external commands as well. For Unix, this should
work. These commands are done from within vim:
:!mkdir Shashank
This command will make a directory with the name of shashank in the
current location.
Choosing Colors
vim guesses the background color that you are using. If it is black (or
another dark color) it will use light colors for text. If it is white (or
another light color) it will use dark colors for text. If vim guessed
wrong the text will be hard to read. To solve this, set the 'background'
option. For a dark background:
:set background=dark
If you have unsaved changes in the current file, you will get an error
message and the ":next" will not work. This is the same problem as with
":edit" mentioned in the previous section. To abandon the changes:
:next!
But mostly you want to save the changes and move on to the next file.
There is a special command for this:
:wnext
Backup Files
Usually vim does not produce a backup file. If you want to have one, all
you need to do is execute the following command:
:set backup
The name of the backup file is the original file with a tilde ("~") added
to the end. If your file is named data.txt, for example, the backup file
name is data.txt~. If you do not like the fact that the backup files end
with ~, you can change the extension:
:set backupext=.bak
A clever way to start editing a new file is by using an existing file that
contains most of what you need. For example, you start writing a new
program to move a file. You know that you already have a program that
copies a file, thus you start with:
:edit copy.c
You can delete the stuff you don't need. Now you need to save the file
under a new name. The ":saveas" command can be used for this:
vim will write the file under the given name, and edit that file. Thus the
next time you do ":write", it will write "move.c". "copy.c" remains
unmodified.