Sponsored Content
Top Forums Shell Programming and Scripting Time take between first and last file creation Post 302838943 by krishmaths on Wednesday 31st of July 2013 01:16:24 AM
Old 07-31-2013
Do you have control over the process that creates those multiple files? If yes then you can add something like this in the code.

At the start of the script:
Code:
startsec=$(date +%s)


At the end of the script:
Code:
 endsec=$(date +%s)
 duration=$(expr $endsec - $startsec)
 echo $duration

---------- Post updated at 10:46 AM ---------- Previous update was at 10:16 AM ----------

In case you need to find the difference between first file and last file in a directory, below script can be used.

Code:
DIR=/your/directory

first_ts=$(ls -lt $DIR | tail -1 | awk '{print $8}')
last_ts=$(ls -ltr $DIR | tail -1 | awk '{print $8}')

first_mm=$(echo $first_ts | cut -d":" -f 1)
first_ss=$(echo $first_ts | cut -d":" -f 2)
last_mm=$(echo $last_ts | cut -d":" -f 1)
last_ss=$(echo $last_ts | cut -d":" -f 2)

first_totsec=$(expr $first_mm \* 60 + $first_ss)
last_totsec=$(expr $last_mm \* 60 + $last_ss)

duration=$(expr $last_totsec - $first_totsec)

if [ $duration -gt 60 ]
then
  echo "\n" Diff between first and last file mtime: $(echo $duration | awk '{printf("%2d min %2d sec",$1/60,$1%60)}') "\n"
else
  echo "\n Diff between first and last file mtime: $duration seconds.\n"
fi

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

file creation time

i have to delete some files that were created on a particular date. is there any way to do that without affecting the files that were modified on the same date? (1 Reply)
Discussion started by: sskb
1 Replies

2. UNIX for Dummies Questions & Answers

file creation date & time

Hi All, I have some files which are creates every day using a script. I want to create a log files which does write "filename,creation day and time" how can I do this ?? Alice (3 Replies)
Discussion started by: alisevA3
3 Replies

3. Shell Programming and Scripting

Unix File creation time

IS there any command to find the file creation time in Unix. (2 Replies)
Discussion started by: tinivt
2 Replies

4. Programming

File creation time

Hi Everybody, Is their any functions to find out the file creation time in 'C' (2 Replies)
Discussion started by: mr_manii
2 Replies

5. Shell Programming and Scripting

File creation time in seconds

Hi All, Cany any one help me in solving this.. Problem statement: I have a requirement to find the time from which there are no files created in a given directory. For this I am assuming that I need to get the file creation time in seconds, then the current time in seconds using `date +%s`.... (7 Replies)
Discussion started by: chary
7 Replies

6. Shell Programming and Scripting

find file creation time

Hello folks, I have a file, but it change every seconds, i use stats command to check its creation time, but it shows access,modify and change time same. Is there any other way to see the file creation date/time? Thanks (2 Replies)
Discussion started by: learnbash
2 Replies

7. UNIX for Dummies Questions & Answers

About Unix File creation time

Hello, I registered and recreated this thread because everywhere we can see "It's not possible to get the file creation time in UNIX fs". This is not true any more with Ext4! Unfortunately, there is not user-level tools that allow you to read those information. You have to use a low level tool... (4 Replies)
Discussion started by: gaellafond
4 Replies

8. Red Hat

File creation time

Hi Everybody, I would like to know file creation date and time in linux. I went throgh google and forums got some information but from that i am not sure for my question. Please check the following information. "ls -l" ==> but it is just gives the last modified time and date of the file.... (2 Replies)
Discussion started by: mastansaheb
2 Replies

9. UNIX for Dummies Questions & Answers

File creation time in UNIX

Hi All, Can any one help how to long list today's files in unix.i.e files which are have been created today should be able to "ls -ltr" .I should be able to apply the "ls -ltr" command on today's files(should not include all the files which were there in the directory). Thanks in advance!!! (3 Replies)
Discussion started by: Balasankar
3 Replies

10. UNIX for Beginners Questions & Answers

Sftp file creation time

Hi Team, Could you please let me know ,how to find the file creation date time in SFTP server. i tred like , ls -ltr command only availble and not available like ls --full-time test.txt please help? Thanks (7 Replies)
Discussion started by: bmk123
7 Replies
rmf(1mh)																  rmf(1mh)

Name
       rmf - remove folder

Syntax
       rmf [ +folder ] [ -help ] [ -[no]interactive ]

Description
       The  command  removes all of the messages within the current folder, and then removes the folder itself.  If there are any files within the
       folder which are not part of MH, they are not removed, and an error message is displayed.

       You can specify a folder other than the current folder by using the +folder argument.  If you do not specify a folder, and cannot find  the
       current folder, asks you whether you want to delete instead.

       If the current folder is removed, it makes current.

       Note that the command irreversibly deletes messages that do not have other links, so use it with caution.

       If  the folder being removed is a sub-folder, the parent folder becomes the new current folder, and tells you that this has happened.  This
       provides an easy mechanism for selecting a set of messages, operating on the list, then removing the list  and  returning  to  the  current
       folder from which the list was extracted.

       Using to delete a read-only folder deletes the private sequence and current message information from the file, without affecting the folder
       itself.	If you have sub-folders within a folder, you must delete all the sub-folders before you can delete the folder itself.

Options
       -help	 Prints a list of the valid options to this command.

       -interactive
       -nointeractive
		 Asks for confirmation before deleting a folder.  By default, deletes a folder and its messages without asking	for  confirmation.
		 If  you  specify  the	-interactive option, asks if you are sure before deleting the folder.  You are advised to use this option,
		 since when deletes a folder its contents are lost irretrievably.

Examples
       This example shows how asks for confirmation when the -interactive option is used:
       % rmf -interactive +test
       Remove folder "test"? y

Profile Components
       Path:   To determine the user's Mail directory

Files
       The user profile.

See Also
       rmm(1mh)

																	  rmf(1mh)
All times are GMT -4. The time now is 07:36 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy