LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-26-2011, 01:21 PM   #1
qwyrp
LQ Newbie
 
Registered: Nov 2011
Posts: 5

Rep: Reputation: Disabled
Change datestamp of maps according to datestamp of the files inside


The datestamping of my maps are corrupted during moving but the datestamp of the files in that directory are correct. How can I change the datestamps of the maps with the datestamp of a file in that directory

Here in a figure:
MAP[20110404] - file [20090312] <=> MAP[20090312] -- file [20090312]
 
Old 11-26-2011, 01:52 PM   #2
SecretCode
Member
 
Registered: Apr 2011
Location: UK
Distribution: Kubuntu 11.10
Posts: 562

Rep: Reputation: 102Reputation: 102
I'm not what you mean by maps (symbol table maps? Regular files?) but this should be fairly straightforward with touch, if you can clearly identify the files involved.

If your correctly dated file is ~/dir/file.txt you can fix the date of some other file ~/dir/file.map using
Code:
touch -r ~/dir/file.txt ~/dir/file.map
If you need more help please give exact specifications of the files/directories you need to fix, and say whether there are lots or just a few.
 
Old 11-26-2011, 02:41 PM   #3
qwyrp
LQ Newbie
 
Registered: Nov 2011
Posts: 5

Original Poster
Rep: Reputation: Disabled
Sorry wrong translation, with maps I mean FOLDERS
Each folder contains files with all kind of different names

Last edited by qwyrp; 11-26-2011 at 02:43 PM.
 
Old 11-26-2011, 03:32 PM   #4
SecretCode
Member
 
Registered: Apr 2011
Location: UK
Distribution: Kubuntu 11.10
Posts: 562

Rep: Reputation: 102Reputation: 102
So you want to set the timestamp of a bunch of directories to be the same as one of the files in the directory? A particular one? The most recent?
 
Old 11-26-2011, 05:10 PM   #5
qwyrp
LQ Newbie
 
Registered: Nov 2011
Posts: 5

Original Poster
Rep: Reputation: Disabled
No, it's just okay if one of the folder-datestamps equals to one of a file
 
Old 11-26-2011, 06:16 PM   #6
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Quote:
Originally Posted by qwyrp View Post
The datestamping of my maps are corrupted during moving but the datestamp of the files in that directory are correct. How can I change the datestamps of the maps with the datestamp of a file in that directory

Here in a figure:
MAP[20110404] - file [20090312] <=> MAP[20090312] -- file [20090312]
Perhaps the best way is to avoid corrupting things in the first place. Using the '-a' switch on the cp command may help you. Creating a tarball, moving and unrolling the tarball should preserve everything as well.

--- rod.
 
Old 11-27-2011, 12:05 AM   #7
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948
Here is how to change directory timestamps to match the latest file modification timestamp in that directory (or subdirectory timestamp if there are no files in the directory), for current working directory and all subdirectories.
Code:
find . -depth -type d -print0 | while read -rd "" dir ; do
    last=$(find "$dir" -maxdepth 1 -type f -printf '%TY%Tm%Td%TH%TM-%TS\n' | sed -e 's|\..*$||g' -e 's|-|.|' | sort -rg | sed -ne '1 p')
    [ -n "$last" ] || last=$(find "$dir" -maxdepth 1 -printf '%TY%Tm%Td%TH%TM-%TS\n' | sed -e 's|\..*$||g' -e 's|-|.|' | sort -rg | sed -ne '1 p')
    [ -n "$last" ] && echo touch -t "$last" "$dir"
done
If you run the above, it will only show the touch commands it would run; it will not actually run them. It is a good idea to check first. As it uses ASCII NUL (zero byte) as a separator, it will work correctly for all possible file and directory names in Linux, including those that contain spaces, newlines, or control characters.

If you use UTF-8, and some of your file names contain invalid UTF-8 sequences (are for example in some other character set), run
Code:
export LANG=C LC_ALL=C
before running the snippet above, to make sure character set issues are ignored. (This selects the POSIX locale. Some tools will abort when they see invalid UTF-8 sequences; using the POSIX locale tells them to only consider ASCII letters, and not try to parse UTF-8 sequences at all, just keep them intact.)

When the scriptlet works for you, just drop the echo and rerun it to apply the time stamp changes.

The script was tested using GNU find 4.4.2, GNU sed 4.2.1, sort and touch from GNU coreutils 8.5, and Bash 4.1.5.
 
Old 11-27-2011, 05:02 AM   #8
qwyrp
LQ Newbie
 
Registered: Nov 2011
Posts: 5

Original Poster
Rep: Reputation: Disabled
Sadly, this ain't working for me.
My testfolder is : Aanleg voortuin
The files in it are dated 14 may 2011

But the result of the script is: touch -t 201111271148.10 ./Aanleg voortuin
and the folder is set to nov 27th (= today) and current time instead of may 14th
 
Old 11-27-2011, 08:27 AM   #9
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948
What does
Code:
find . -maxdepth 1 -type f -printf '%TY%Tm%Td%TH%TM-%TS %p\n' | sort -rg
when run in that test folder? I bet the first file has todays time stamp.
 
Old 11-27-2011, 09:05 AM   #10
qwyrp
LQ Newbie
 
Registered: Nov 2011
Posts: 5

Original Poster
Rep: Reputation: Disabled
Wow you're so right ! There is a thumbds.db file dated today when I remove that files it all went wel !!
Thank your very much !

There's only one issue left:
The folder-name is Aanleg Tuin where there's a space between Aanleg and Tuin.
When I use the output as command i.e. touch -t 201105141618.30 ./Aanleg voortuin there are two new created folders named Aanleg and voortuin (with a correct datestamp). When I use touch -t 201105141618.30 ./Aanleg\ voortuin it worked well. Hopefully you know solution to this problem too?

Last edited by qwyrp; 11-27-2011 at 09:07 AM.
 
Old 11-27-2011, 02:18 PM   #11
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948
Use the script, omitting the echo . The script uses the proper form of quoting. You can safely run it multiple times.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Kwrite's datestamp/timestamp function newbiesforever Linux - Software 2 07-13-2011 12:38 AM
timestamp/datestamp in Leafpad? newbiesforever Linux - Software 0 05-22-2009 02:18 PM
Is there a way to refresh or change datestamp on a process ginda Linux - Newbie 1 01-22-2009 04:33 AM
Moving files with certain datestamp? ginda Programming 4 03-28-2008 04:27 PM
Remove Files by Datestamp seanloftus Linux - General 1 07-28-2003 05:04 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:46 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration