Thursday, March 29, 2012

lsof command with examples

lsof command with examples

lsof stands for list open files. Which will list information about files opened by processes.


Command to show all opened Internet sockets
#lsof -i

Command to print all tcp connections
#lsof -i tcp

Command to print all udp connections
#lsof -i udp

Command to find who are the users using the folder right now
#lsof +D /tmp

Command to print who and what are the files using in /dev/sda5 partitions
#lsof /dev/sda5

Command to list all the files associated with process ID 2665
#lsof +p 2665

Command to listing of files for processes executing the command that begins with vmstat
#lsof -c vmstat

Listing of files for processes executing the command that begins with character a
#lsof -c a

Command to print all the files opened by the user rajkumar
#lsof -u rajkumar

Scenario:
========

Suppose consider that you are usnig nfs to transfer files between multiple systems in you local LAN. Assume that the folder which shares for NFS is /sharing, if you what to find out who all are the user’s using the folder means use the below command

#lsof +D /sharing

The above command will display who all the user’s using the folder right now.

Monday, January 9, 2012

How to Exclude a specific package not to update in RHEL

# vim /etc/yum.conf

Append below line at the end of a file.

exclude=httpd-2.2.17-1.fc14.
i686

Or

exclude=httpd*

Save and exit the file.tt

Now update your system using yum. YUM will exclude httpd package updates.

Mount remote machine file system on local machine through ssh

SSH (Secure Shell) is a network protocol that allows secure communication between two network devices. Normally, we use ssh to access Linux and Unix based system shell remotely. But we can also use ssh to mount remote machine file system on local machine. For that you need to install SSHFS packaged on your machine. SSHFS is a filesystem client based on the SSH File Transfer Protocol.
Install sshfs via YUM,

# yum install sshfs -y

 
Or install sshfs via APT,

# apt-get install sshfs

 
If you want to mount /root partition of 192.168.0.1 server then,
First create a mount point


# mkdir /mnt/root

 
Then run sshfs as,


# sshfs root@192.168.0.1:/root /mnt/root

 

How to extract a specific file From RPM Without installing:-

By mistake If u have deleted /sbin/poweroff file from system.
How to find the RPM has this /sbin/poweroff

# yum whatprovides /sbin/poweroff

systemd-sysvinit-10-2.fc14.1.
i686 contains /sbin/poweroff in Fedora 14.

Now, if you try to install that package using yum, we will get “Package systemd-sysvinit-10-2.fc14.1.
i686 already installed and latest version”.

To restore /sbin/poweroff, all we need is systemd-sysvinit-10-2.fc14.1.
i686.rpm and rpm2cpio, this is bundled with rpm-x.x.x…i386.rpm.

# rpm -ql rpm | grep rpm2cpio
/usr/bin/rpm2cpio

/usr/lib/rpm/rpm2cpio.sh

/usr/share/man/ja/man8/
rpm2cpio.8.gz

/usr/share/man/ko/man8/
rpm2cpio.8.gz

/usr/share/man/man8/rpm2cpio.
8.gz

/usr/share/man/pl/man8/
rpm2cpio.8.gz

/usr/share/man/ru/man8/
rpm2cpio.8.gz

# rpm2cpio systemd-sysvinit-10-2.fc14.1.
i686.rpm | cpio -idmv

# cp sbin/poweroff /sbin/

Note: There is another way to install systemd-sysvinit-10-2.fc14.1.
i686.rpm by forcefully installing it.

# rpm -ivh systemd-sysvinit-10-2.fc14.1.
i686.rpm –force