Change date time stamp of existing file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Change date time stamp of existing file
# 8  
Old 07-28-2016
You have not followed the suggestion, so I'm not surprised.

As a quick test, can you do the following?:-
Code:
date -d"1 week ago"

If you get an error then we will know you haven't got that function available.



Robin
# 9  
Old 07-28-2016
Quote:
Originally Posted by mohtashims
Does not work.
Please see the output:
Code:
touch -t date -d"1 week ago" +%y%m%d%H%m hello.txt
touch: bad time specification

Hello mohtashims,

Seems to be that previous GNU date command is not working in Sun/Solaris OS, could you please try following and let me know if this works for you.
Code:
touch -t $(perl -e '@T=localtime(time-86400);printf("%02d%02d%02d%02d%02d\n",$T[5]+1900,$T[4]+1,$T[3]-6,$T[2],$T[1])')  Input_file
OR
touch -t $(perl -e '@T=localtime(time);printf("%02d%02d%02d%02d%02d\n",$T[5]+1900,$T[4]+1,$T[3]-7,$T[2],$T[1])')    Input_file

Thanks,
R. Singh

Last edited by RavinderSingh13; 07-28-2016 at 08:04 AM.. Reason: Added one more solution on same now.
This User Gave Thanks to RavinderSingh13 For This Post:
# 10  
Old 07-28-2016
Thank you but i don't use perl.

I need a non-perl solution.

If we do not have a non-perl solution for my operating system do let me know, so i dont invest more time with this.

Last edited by mohtashims; 07-28-2016 at 02:36 PM..
# 11  
Old 07-28-2016
I note that when Ravinder suggested using:
Code:
+%y%m%d%H%M

as a date format when using the GNU date utility, you not only decided to ignore the fact that you would have to specify the pathname for the GNU date utility, you also decided to change that format to:
Code:
+%y%m%d%H%m

and, of course, it didn't work.

There is no way for us to know whether or not you have installed the GNU core utilities on your system or not, and if so, where you installed them. You might see if gdate would work with your default path or if /usr/gnu/bin/date would work.

Or, if you use ksh93 as your shell on a Solaris 11 system, the following should work for you:
Code:
touch -t $(printf '%(%Y%m%d%H%M)T' "7 days ago") hello.txt

If you choose to change the date format I specified, I don't want to hear about how you didn't get the right time.

If you choose to change 7 days ago to 1 week ago, I don't want to hear about how you got Monday a week ago instead of the current day a week ago.

If you choose to try the above command using some shell other than ksh93 to run that command, I don't want to hear about how it didn't work for you.

Last edited by Don Cragun; 07-28-2016 at 03:51 PM.. Reason: Fix typo: s/touch -T/touch -t/
This User Gave Thanks to Don Cragun For This Post:
# 12  
Old 07-28-2016
This worked !!

Code:
touch -t $(printf '%(%Y%m%d%H%M)T' "7 days ago") hello.txt

@Don Cragun -> Not to take anything away from anyone but you are amazing !!
# 13  
Old 10-13-2016
If that is a new request, please be aware that
- it is usually preferred to open a new thread of its own with new questions
- the better (i.e. more precise/detailed) the specification, the better the results or proposals

What did you try to adapt the solutions presented before to solve your request?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Add current time stamp column in existing csv file

Hi , I want to add a new column 'current_time stamp' in my existing csv file with current time stamp for all the records.I tried something this but this is printing 0 with date & time and printed date one line above header.Please help awk -F "," 'BEGIN{ OFS="," } {$6=system("date... (5 Replies)
Discussion started by: netdbaind
5 Replies

2. Shell Programming and Scripting

How to extract latest file by looking at date time stamp from a directory?

hi, i have a Archive directory in which files are archived or stored with date and time stamp to prevent over writing. example: there are 5 files s1.txt s2.txt s3.txt s4.txt s5.txt while moving these files to archive directory, date and time stamp is added. of format `date... (9 Replies)
Discussion started by: Little
9 Replies

3. Shell Programming and Scripting

If(Condition) Rename a file with (Date+Time) Stamp

Hi! Please see our current script: #!/usr/bin/ksh if (egrep "This string is found in the log" /a01/bpm.log) then mailx -s "Error from log" me@email.com, him@email.com </a01/bpm.log fi To the above existing script, we need to add the following change: 1) After finding the string,... (7 Replies)
Discussion started by: atechcorp
7 Replies

4. Shell Programming and Scripting

Set date and time stamp of one file to another

Hi I use "touch -t xxxxxxxx" command to set date/time stamp of a file. My requirement is to read the date/time stamp of a file and apply it to another file. Is there anyway to do it simple instead of manually taking date/stamp of first file? TIA Prvn (2 Replies)
Discussion started by: prvnrk
2 Replies

5. UNIX for Dummies Questions & Answers

ls -ltr for a future date/time stamp file

Hi When i do ls -ltr <file1> then it shows me the date and time of the file if - for whatever reason file has future date/time stamp then ls -ltr is not showing the time, it just shows only date part ... even if time is ahead by 2 hr than current time. suppose a file was copied from INDIA... (3 Replies)
Discussion started by: reldb
3 Replies

6. Shell Programming and Scripting

Change time stamp of a file

Hi, As i know , we can change the time stamp of a file by touch command, i did change in a file and it is looking as given # ls -l abcd -rw-r--r-- 1 batsoqa sicusers 0 Feb 17 2010 abcd actually i want to see the output like this -rw-r--r-- 1 batsoqa sicusers ... (3 Replies)
Discussion started by: apskaushik
3 Replies

7. Shell Programming and Scripting

change the time stamp of file

can we change the timestamp of a file to old date. -rwxrwxrwx 1 root other 330 Jul 1 16:03 abc.txt it shows creation time is 16.03 can i change it to previous time :) (2 Replies)
Discussion started by: anish19
2 Replies

8. UNIX for Dummies Questions & Answers

how can i change the date of an existing file

Hi, Plz suggest me how can i change the date of a file. Suppose my file has been created in some date and i want to give it present date. How can i do this???? (2 Replies)
Discussion started by: adityam
2 Replies

9. UNIX for Dummies Questions & Answers

Inserting Date&Time Stamp In Existing Log File

I am trying to insert a line with a date stamp in a file that is used to monitor activity in one of our directories. By doing this, I want to grep that file each day and go to the last entry for each time a error occurred and pull all errors generated if any exist. If error exists I want that error... (3 Replies)
Discussion started by: shephardfamily
3 Replies

10. UNIX for Dummies Questions & Answers

File date and time stamp

I have to capture the creation date and time stamp for a file. The ls command doesn't list all the required information. I need year, month, day, hour, minute and second. Any ideas... (1 Reply)
Discussion started by: Xenon
1 Replies
Login or Register to Ask a Question