Sponsored Content
Full Discussion: get a file date/timestamp
Top Forums UNIX for Dummies Questions & Answers get a file date/timestamp Post 93712 by jim mcnamara on Wednesday 21st of December 2005 01:40:12 PM
Old 12-21-2005
Code:
#!/usr/bin/perl

#^ PROGRAM DESCRIPTION
#^ -------------------
#^ This program prints the modification times and names of files.
#^ It uses the following format:  inodetime.pl filename
#^ It will accept:  inodetime.pl filename1 filename2 filename3
#^                  inodetime.pl /tmp/file*
#^ The format of the output is: YYYYMMDDhhmmss filename
#^ example:
#^           $ inodetime.pl /tmp/t*
#^           19961115105425 /tmp/test.sql
#^           19970116113616 /tmp/tststat.pl
#^
#^###################################################################

# Get the (next) input from the command line
while ($curfile = $ARGV[0])
{
# Do following code block only if $curfile exists
   if (-e $curfile)
   {
# stat structure into variables
      ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
      $atime,$mtime,$ctime,$blksize,$blocks) = stat("$curfile");
# time structure into variables
      local($sec,$min,$hr,$day,$mon,$yr,$wday,@dntcare) = localtime($mtime);
      $yr = ($yr>=70) ? $yr+1900 : $yr+2000;
      $yr="$yr";
      $mon = (++$mon < 10) ? "0$mon" : "$mon";
      $day = ($day < 10) ? "0$day" : "$day";
      $hr  = ($hr < 10) ? "0$hr" : "$hr";
      $min = ($min < 10) ? "0$min" : "$min";
      $sec = ($sec < 10) ? "0$sec" : "$sec";
# Rearrange in the YYYYMMDDhhmmss format and assign to $dte variable
      $dte = join('',$yr,$mon,$day,$hr,$min,$sec);
      # Print modification date and filename
      print ("$dte $curfile\n");
   }
# Shift to next position in command line
   shift (@ARGV);
}

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Creating file with date/timestamp in it

I need to create a file through a c-shell script which contains only the date and time that the file was created. Does anyone know a simple way to do this? Thank you, Paula (7 Replies)
Discussion started by: ccpjr29
7 Replies

2. Shell Programming and Scripting

File renaming with date timestamp

Hi, This is my script: #! /usr/bin/ksh cd /app/chdata/workflow/suppl/esoutput/spd/testing for file in /app/chdata/workflow/suppl/esoutput/spd/testing do sort *.txt | awk '{ file=substr($0,1,2)".txt"; print >> file }' ... (3 Replies)
Discussion started by: Sunitha_edi82
3 Replies

3. AIX

how to grep and compare timestamp in a file with the current date

I want to read a log file from a particular location.In the logfile , lines contains timestamp.I need to compare the timestamp in the logfile with the current date.If the timpestamp in the log file is less than 4 hours then i need to read the file from that location.Below is the file format.Please... (1 Reply)
Discussion started by: achu
1 Replies

4. AIX

how to grep and compare timestamp in a file with the current date

I want to read a log file from a particular location.In the log file each line starts with timestamp.I need to compare the timestamp in the logfile with the current date.If the timpestamp in the log file is less than 4 hours then i need to read the file from that location.Below is the file... (1 Reply)
Discussion started by: achu
1 Replies

5. Shell Programming and Scripting

Compare file timestamp with current date. Diff must be 1 hour.

Hello, I've created the script below to compare the content of two files with a delay of an hour. After an hour, the lines that exist in both files, will be printed and executed. The script now uses a counter to countdown 50 minutes. But what I would prefer is to check the file timestamp of... (3 Replies)
Discussion started by: taipan
3 Replies

6. Shell Programming and Scripting

To get max/min Date/Timestamp from a file

I want to get maximum/minimum date/timestamp from a data file ? Sample Input File ============= rec#,order_dt,ext_ts 1,2010-12-01,2010-12-01 17:55:23.222222 2,2011-11-05,2010-12-01 19:55:23.222222 3,2009-10-01,2010-12-01 18:55:23.222222 for above file Maximum Order_dt = 2011-11-05... (5 Replies)
Discussion started by: vikanna
5 Replies

7. Shell Programming and Scripting

Check if a date field has date or timestamp or date&timestamp

Hi, In a field, I should receive the date with time stamp in a particular field. But sometimes the vendor sends just the date or the timestamp or correctl the date&timestamp. I have to figure out the the data is a date or time stamp or date&timestamp. If it is date then append "<space>00:00:00"... (1 Reply)
Discussion started by: machomaddy
1 Replies

8. Shell Programming and Scripting

File Timestamp and date comparsion

Hi, I have many files in the source directory but I need to process with the latest timestamp file. I am using linux operating system. i want extract the file created timestamp( Ext_File_create_date=) With this format YYYYMMDD- i have searched the relevent command in the unix forms but did... (5 Replies)
Discussion started by: onesuri
5 Replies

9. UNIX for Dummies Questions & Answers

Move Multiple Files adding date timestamp before file type

There are files in a directory and I have to move multiple files adding datetimestamp before the file type. /Data/ abc.csv def.csv ghi.csv I have to move this files to archive directory adding datatimestamp before .csv /archive/ abc_YYYYMMDDHHMMSS.csv def_YYYYMMDDHHMMSS.csv... (7 Replies)
Discussion started by: eskay
7 Replies

10. Shell Programming and Scripting

Replacing Date in the file with Create date and timestamp

Hello, I have files that with a naming convention as shown below. Some of the files have dates in the file name and some of them don't have dates in the file name. imap-hp-import-20150917.txt imap-dell-gec-import-20150901.txt imap-cvs-import-20150915.txt imap-gec-import.txt... (8 Replies)
Discussion started by: Saanvi1
8 Replies
TCAL(1) 						      General Commands Manual							   TCAL(1)

NAME
Tcal - runs the Gcal program with the date of tomorrow's day. SYNOPSIS
tcal [--help | --version] | [--shift=[+|-]number] [Argument...] DESCRIPTION
Tcal is a program which runs gcal with a date set one day ahead (equivalent the --shift=1 option). All given arguments are passed unmodi- fied to the Gcal program. If the Gcal program shall be called with another date than tomorrow's date, this desired date can be selected by using the --shift=[+|-]number option, in which [+|-]number is the distance of days the desired date is distant from the actual date (works only for Gregorian years). The --shift option must be given before all other arguments which are passed to the Gcal program. An exit status of 0 means all processing is successfully done, any other value means an error has occured. OPTIONS
--help Print a usage message listing all available options, then exit successfully. --version Print the version number, then exit successfully. --shift=[+|-]number Define the displacement in [+|-]number days the desired date is distant from the actual date. ENVIRONMENT
GCALPROG The GCALPROG environment variable contains the file name of the executable Gcal program, which is used by Tcal to call Gcal. This takes precedence over the file name `gcal', which is burned-in during the compilation step of tcal. COPYRIGHT
Tcal Copyright (c) 1995, 96, 1997, 2000 Thomas Esken This software doesn't claim completeness, correctness or usability. On principle I will not be liable for any damages or losses (implicit or explicit), which result from using or handling my software. If you use this software, you agree without any exception to this agree- ment, which binds you LEGALLY !! Tcal is free software and distributed under the terms of the `GNU General Public License'; published by the `Free Software Foundation'; version 2 or (at your option) any later version. Any suggestions, improvements, extensions, bug reports, donations, proposals for contract work, and so forth are welcome! If you like this tool, I'd appreciate a postcard from you! Enjoy it =8^) AUTHOR
------------------------oOO \\_''/ OOo--------------------------- Thomas Esken O (/o-o) O eMail: esken@gmx.net Im Hagenfeld 84 (( ^ )) Phone: +49 251 232585 D-48147 Muenster; Germany \____) ~ (____/ MotD : 2old2live, 2young2die SEE ALSO
gcal(1), txt2gcal(1), gcal2txt(1). June 14, 2000 TCAL(1)
All times are GMT -4. The time now is 05:46 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy