Wednesday 11 September 2013

Time Stamp of a file in Linux


Every Linux file is associated with timestamps, which specifies the last access time, last modification time and last change time.

To get the timestamp of a file "ls -l" and "stat".

1. Use -c option to avoid creating new files, but will change the timestamp by present time.

stat tgs.txt

  File: `tgs.txt'
  Size: 0               Blocks: 0          IO Block: 4096   regular empty file
Device: 802h/2050d      Inode: 525402      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2012-10-18 23:42:12.000000000 -0700
Modify: 2012-10-18 23:42:12.000000000 -0700
Change: 2013-09-11 08:49:16.509859887 -0700

touch -c tgs.txt

stat tgs.txt

  File: `tgs.txt'
  Size: 0               Blocks: 0          IO Block: 4096   regular empty file
Device: 802h/2050d      Inode: 525402      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2013-09-11 08:49:25.685239864 -0700
Modify: 2013-09-11 08:49:25.685239864 -0700
Change: 2013-09-11 08:49:25.685239864 -0700

2. Change File’s Access Time using -a.

stat tgs.txt

  File: `tgs.txt'
  Size: 0               Blocks: 0          IO Block: 4096   regular empty file
Device: 802h/2050d      Inode: 525402      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2013-09-11 08:10:44.783796541 -0700
Modify: 2013-09-11 08:10:44.783796541 -0700
Change: 2013-09-11 08:10:44.783796541 -0700

touch -a tgs.txt

stat tgs.txt

  File: `tgs.txt'
  Size: 0               Blocks: 0          IO Block: 4096   regular empty file
Device: 802h/2050d      Inode: 525402      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2013-09-11 08:13:14.824798981 -0700
Modify: 2013-09-11 08:10:44.783796541 -0700
Change: 2013-09-11 08:13:14.824798981 -0700

3. Change File’s Modification Time using -m.

touch -m *.o

stat tgs.txt

  File: `tgs.txt'
  Size: 0               Blocks: 0          IO Block: 4096   regular empty file
Device: 802h/2050d      Inode: 525402      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2013-09-11 08:13:14.824798981 -0700
Modify: 2013-09-11 08:10:44.783796541 -0700
Change: 2013-09-11 08:13:14.824798981 -0700

touch -m tgs.txt

stat tgs.txt

  File: `tgs.txt'
  Size: 0               Blocks: 0          IO Block: 4096   regular empty file
Device: 802h/2050d      Inode: 525402      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2013-09-11 08:13:14.824798981 -0700
Modify: 2013-09-11 08:16:36.600236392 -0700
Change: 2013-09-11 08:16:36.600236392 -0700

4. Modification time using -t and -d.

touch -t [CCYYMMDDHHMM.SS] filename

touch -t 201212312359.59 tgs.txt 
touch -a -m -t 201212312359.59 tgs.txt 

stat tgs.txt

  File: `tgs.txt'
  Size: 0               Blocks: 0          IO Block: 4096   regular empty file
Device: 802h/2050d      Inode: 525402      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2012-12-31 23:59:59.000000000 -0800
Modify: 2012-12-31 23:59:59.000000000 -0800
Change: 2013-09-11 08:30:24.706252619 -0700

touch -d "2012-10-19 12:12:12.000000000 +0530" tgs.txt

stat tgs.txt

  File: `tgs.txt'
  Size: 0               Blocks: 0          IO Block: 4096   regular empty file
Device: 802h/2050d      Inode: 525402      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2012-10-18 23:42:12.000000000 -0700
Modify: 2012-10-18 23:42:12.000000000 -0700
Change: 2013-09-11 08:37:51.182799786 -0700

5. Copy the Time-stamp from Another File using -r.

ls -l
-rw-r--r--. 1 root root 0 Sep 11 08:43 test.txt
-rw-r--r--. 1 root root 0 Oct 19  2012 tgs.txt

touch test.txt -r tgs.txt

ls -l

-rw-r--r--. 1 root root 0 Oct 19  2012 test.txt
-rw-r--r--. 1 root root 0 Oct 19  2012 tgs.txt

ref: http://www.thegeekstuff.com/2012/11/linux-touch-command/

Executing Background Jobs in Linux

Manage Background Jobs in Linux

when you execute a find command that might take a lot time to execute, you can put it in the background as shown below.

Appending an ampersand ( & ) to the command runs the job in the background.

     find / -type f -mtime -1000 >> /root/filelist.log &

Sending the current foreground job to the background using Ctrl + Z.

     find / -type f -mtime -1000 >> /root/filelist.log
     Ctrl + Z
     bg

Taking a job from the background to the foreground.

     fg
     find / -type f -mtime -1000 >> /root/filelist.log
     Ctrl + Z

View all the background jobs.

     jobs

     [1]+  Stopped    find / -type f -mtime -1000 >> /root/filelist.log

Kill a specific background job.

     fg %1
     kill %1

ref: http://www.thegeekstuff.com/2010/05/unix-background-job/


Ganglia Monitoring System

Ganglia

Ganglia is a scalable distributed monitoring system for high-performance computing systems such as clusters and Grids.

Ganglia Installation and Configuration

yum -y install ganglia*

Edit gmetad.conf

vi /etc/ganglia/gmetad.conf

data_source "my cluster" localhost 192.168.1.100:8089

Edit ganglia.conf

vi /etc/httpd/conf.d/ganglia.conf

 Alias /ganglia /usr/share/ganglia
  <Location /ganglia>
     AllowOverride All
     DirectoryIndex index.php
  </Location>

Restart the services

/etc/init.d/httpd restart
/etc/init.d/gmetad restart
/etc/init.d/gmond restart

URL

 http://192.168.1.100/ganglia

ref: http://ganglia.sourceforge.net/