Thursday, October 7, 2010

More about 'touch' command in Linux

touch” resemble like a simple command for creating empty file but it is widely used by system for changing the Time stamp of files and for Service management.

Here’s an example of touch command that change the Time stamp of a file:

[adevaraju@host01-tx xivnew_64]$ ls -l
total 3904
-rw-r--r-- 1 adevaraju domain users   52422 Nov 12  2009 sg3_utils-libs-1.25-4.el5.x86_64.rpm
[adevaraju@host01-tx xivnew_64]$


[adevaraju@host01-tx xivnew_64]$ touch sg3_utils-libs-1.25-4.el5.x86_64.rpm
[adevaraju@host01-tx xivnew_64]$ ls -l
total 3904
-rw-r--r-- 1 adevaraju domain users   52422 Sep 15 07:15 sg3_utils-libs-1.25-4.el5.x86_64.rpm                                       # Time stamp changed


[adevaraju@host01-tx xivnew_64]$ touch -t 1009240615 sg3_utils-libs-1.25-4.el5.x86_64.rpm
[adevaraju@host01-tx xivnew_64]$ ls -l sg3_utils-libs-1.25-4.el5.x86_64.rpm
Fri Nov 26 06:30:34 CST 2010           <- Time stamp advanced to 06:30 11/26/2010
[adevaraju@host01-tx xivnew_64]$


Service management:

When you get into the folder /var/lock/subsys, you could see list of empty files with service names. These files are basically created using touch command, when a service (say ntpd) is started/restarted.  Presence of these files ensures that same service willnot be started again and it gives an error message saying the service is already running. Further these files will let us know how long a particular service is being running.


[adevaraju@host01-tx xivnew_64]$ cd /var/lock/subsys
[adevaraju@host01-tx subsys]$ ls -l
total 0
-rw-r--r-- 1 root root 0 Jul 12 20:25 acpid
-rw-r--r-- 1 root root 0 Jul 12 20:25 atd
-rw-r--r-- 1 root root 0 Jul 12 20:25 auditd
-rw-r--r-- 1 root root 0 Jul 12 20:25 autofs
-rw-r--r-- 1 root root 0 Jul 12 20:25 bluetooth
-rw-r--r-- 1 root root 0 Jul 12 20:24 cpuspeed
-rw-r--r-- 1 root root 0 Jul 12 20:25 crond
-rw-r--r-- 1 root root 0 Jul 12 20:25 cups
-rw-r--r-- 1 root root 0 Jul 12 20:26 firstboot
-rw-r--r-- 1 root root 0 Sep 12 04:02 funcd
-rw-r--r-- 1 root root 0 Jul 12 20:25 gpm
-rw-r--r-- 1 root root 0 Jul 12 20:26 haldaemon
-rw-r--r-- 1 root root 0 Jul 12 20:25 hcid
-rw-r--r-- 1 root root 0 Jul 12 20:25 hidd
-rw-r--r-- 1 root root 0 Jul 12 20:25 hpiod
-rw-r--r-- 1 root root 0 Jul 12 20:25 hplip
-rw-r--r-- 1 root root 0 Jul 12 20:25 hpssd.py
-rw-r--r-- 1 root root 0 Jul 12 20:25 iscsi
-rw-r--r-- 1 root root 0 Jul 12 20:24 iscsid
-rw-r--r-- 1 root root 0 Jul 12 20:24 kudzu
-rw-r--r-- 1 root root 0 Jul 12 20:28 local
-rw-r--r-- 1 root root 0 Jul 12 20:25 messagebus
-rw-r--r-- 1 root root 0 Jul 12 20:24 microcode_ctl
-rw-r--r-- 1 root root 0 Jul 12 20:24 multipathd
-rw-r--r-- 1 root root 0 Jul 12 20:25 netfs
-rw-r--r-- 1 root root 0 Jul 12 20:25 network
-rw-r--r-- 1 root root 0 Jul 12 20:25 nfslock
-rw-r--r-- 1 root root 0 Jul 12 20:32 ntpd
-rw------- 1 root root 0 Jul 12 20:25 pcscd
-rw-r--r-- 1 root root 0 Jul 12 20:32 portmap
-rw-r--r-- 1 root root 0 Aug 13 07:44 postfix
-rw-r--r-- 1 root root 0 Jul 12 20:25 rhnsd
-rw-r--r-- 1 root root 0 Jul 12 20:25 rpcidmapd
-rw-r--r-- 1 root root 0 Jul 12 20:25 sdpd
-rw-r--r-- 1 root root 0 Aug 17 03:08 sendmail
-rw-r--r-- 1 root root 0 Jul 12 20:28 smartd
-rw-r--r-- 1 root root 0 Jul 12 20:32 smb
-rw-r--r-- 1 root root 0 Aug 17 03:08 sm-client
-rw-r--r-- 1 root root 0 Jul 12 20:25 sshd
-rw------- 1 root root 0 Jul 12 20:25 syslog
-rw-r--r-- 1 root root 0 Sep  9 14:48 winbindd   # Indicates winbind service was restarted on Sep 9th.
-rw-r--r-- 1 root root 0 Jul 12 20:25 xfs
-rw-r--r-- 1 root root 0 Jul 12 20:25 xinetd
-rw-r--r-- 1 root root 0 Jul 12 20:25 yum-updatesd
[adevaraju@host01-tx subsys]$

No comments:

Post a Comment