Is There An App To Both Open And Change File Modification Times For Each File In A Folder?
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: Ubuntu 22.04.03 LTS w/ Gnome 42.9 and X11
Posts: 29
Rep:
Is There An App To Both Open And Change File Modification Times For Each File In A Folder?
I just want to set the proper publication dates for archived files I collect, so they show up as a time-line when I set modification fate as the sort order. I'll need to open each file in a directory to see the publication dates before changing their modification dates.
Using touch in bash is to slow and tedious.
Thanks for any tips!
EDIT July 30, 2023: I'm using Ubuntu 22.04 LTS.
This is a software request, not a bash script question. Opening each file to see the proper publication date is necessary due to the various problems with the file formats I'm dealing with.
Last edited by anthonyforwood; 07-30-2023 at 04:59 AM.
Generally, in the common Linux style file systems, there are three dates kept per file. None of them actually track the creation date for the file. The access time tracks the last time the file was accessed for read or write, but #1 that changes every time you look because looking at it counts as an access and #2 since it generates a lot of extra storage traffic it is normally turned off to extend SSD live and provide better performance. Modification time is the one that is universally available and actually useful, but it only tracks the time of last change. There is also a Change time which tracks when the metadata on the file last changed.
Stat will give you the values.
For document purposes different tracking would seem useful. Personally I automated a small database to track files where knowing mattered, and for other files I have them created with the ISO standard date/time string in the file name.
As posted above I might use the date as part of the file name. It sorts automatically by filename and you do not have to worry about preserving timestamps if moving your archive around. I don't know of any GUI app specific to your needs. If these are PDF documents the publication date might be part of its metadata and you can easily parse that from a script using the pdfinfo tool. Otherwise depending on document format and type of file there might be other ways to parse for the information without having to manually open each file which can be used in a script to automate the process.
When I wish to modify apparent timestamps, which I do often, I usually use filecommander. Its menu selection quickly opens the existing data for editing a single file, or to current system data for editing tagged files.
Distribution: Ubuntu 22.04.03 LTS w/ Gnome 42.9 and X11
Posts: 29
Original Poster
Rep:
Quote:
Originally Posted by wpeckham
Generally, in the common Linux style file systems, there are three dates kept per file. None of them actually track the creation date for the file. The access time tracks the last time the file was accessed for read or write, but #1 that changes every time you look because looking at it counts as an access and #2 since it generates a lot of extra storage traffic it is normally turned off to extend SSD live and provide better performance. Modification time is the one that is universally available and actually useful, but it only tracks the time of last change. There is also a Change time which tracks when the metadata on the file last changed.
Stat will give you the values.
For document purposes different tracking would seem useful. Personally I automated a small database to track files where knowing mattered, and for other files I have them created with the ISO standard date/time string in the file name.
I think you misread what I asked. I understand the difference between the timestamps, and that's why I want to use the modification time. What I need is something like what I wrote for Windows with Visual Studio when I used that bloated virus of an OS. It was just a simple program that let me browse the directories, select a file from a directory listing to open it so I could read the publication date of the article or document, and then set the modification date of the file to reflect the publication date.
On a side note, I remember when the internet first began to be widely used and the HTML language was created, many/most/all HTML files had the file's creation date and file source URL printed at the beginning or end of the file. It was just standard practice, even in a 256K world where file transfer speeds were very slow and small file size mattered.
if you want to set the modification timestamps by hand and one by one after reading it yourself:
Googling around people say that some file managers let do it just right click etc...
I am using linux mint with cinnamon and my default file manager (nemo) doesn't let me do that but I'm happy with touch command line.
I found this post, where someone suggest double commander (In mint the is doublecmd-gtk package) and then Highlight the file, click on Files in the Menu bar (or Alt-F), then click on Change Attributes (or press the "a" key) and you get a window that lets you change the timestamp and other attributes.
I found this post, where someone suggest double commander (In mint the is doublecmd-gtk package) and then Highlight the file, click on Files in the Menu bar (or Alt-F), then click on Change Attributes (or press the "a" key) and you get a window that lets you change the timestamp and other attributes.
Same concept as filecommander. They're both OFMs, like MC and the original ancestor NC.
Distribution: Ubuntu 22.04.03 LTS w/ Gnome 42.9 and X11
Posts: 29
Original Poster
Rep:
Quote:
Originally Posted by michaelk
As posted above I might use the date as part of the file name. It sorts automatically by filename and you do not have to worry about preserving timestamps if moving your archive around. I don't know of any GUI app specific to your needs.
I should have been doing that a long time ago. But now I've got 1000s of files that I have to go through one by one. I was hoping there might be something out there to make the task a little quicker and easier. There was a program I used to use in Windows that let me change the stored dates of a file in a folder through the right-click menu. Something like that for Gnome would be useful.
Quote:
If these are PDF documents the publication date might be part of its metadata and you can easily parse that from a script using the pdfinfo tool. Otherwise depending on document format and type of file there might be other ways to parse for the information without having to manually open each file which can be used in a script to automate the process.
I'm thinking at this point that it's easier to just manually look in each file for the correct publication date than to expect there to be a program that will always be able to find it, no matter what file type is.
I should have been doing that a long time ago. But now I've got 1000s of files that I have to go through one by one. I was hoping there might be something out there to make the task a little quicker and easier. There was a program I used to use in Windows that let me change the stored dates of a file in a folder through the right-click menu. Something like that for Gnome would be useful.
If these documents are all the same format and you know a command to read the publication date, you can make a script or a program to update all the timestamps.
We can help you but first let us know some things:
What is the format of these files? Text files, pdf, odt, html....?
what do you exactly mean with "publication date"?
Where in the files can we find the publication date? (metadata, a tag, after some string ...)
Since you mentioned Gnome I assume you are using Files for the file browser. You can create a right click menu item that runs a script. Using zenity you can create a right click menu to enter the date.
#!/bin/bash
cfile=$NAUTILUS_SCRIPT_CURRENT_URI
newdate=$(zenity --entry --title="Change mod date for file" --text="File to change $cfile:")
if [ $? = 0 ]
then
# Verify valid date, execute touch command etc.
fi
This wont modify anything. Example to spit out file time stamps.
Code:
#!/usr/bin/python
import os
from datetime import datetime
path = '/whole/path/to/files'
fdpaths = [path+"/"+fd for fd in os.listdir(path)]
print("file_path " + "create_date " + "modified_date ")
for fdpath in fdpaths:
statinfo = os.stat(fdpath)
create_date = datetime.fromtimestamp(statinfo.st_ctime)
modified_date = datetime.fromtimestamp(statinfo.st_mtime)
print(fdpath, ' ', create_date, ' ', modified_date)
Now, to modify a files timestamp.
Code:
touch myfile.txt
ls -l myfile.txt
-rw-r--r-- 1 me me 0 Jul 29 15:38 myfile.txt
python
Python 3.11.3 (main, Jun 5 2023, 09:32:32) [GCC 13.1.1 20230429] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
>>> import os
>>> t = time.mktime(time.strptime('16.01.2020 00:05:30', '%d.%m.%Y %H:%M:%S'))
>>> os.utime('/path/to/myfile.txt', (t,t))
>>> quit()
ls -l myfile.txt
-rw-r--r-- 1 me me 0 Jan 16 2020 myfile.txt
I'm going to let you look at those, then write what you want. Be careful. Don't loop through all of the files and change all of their time stamps to present. Change just the ones that you want, based on the criteria that you want.
Distribution: Ubuntu 22.04.03 LTS w/ Gnome 42.9 and X11
Posts: 29
Original Poster
Rep:
Quote:
Originally Posted by mrmazda
When I wish to modify apparent timestamps, which I do often, I usually use filecommander. Its menu selection quickly opens the existing data for editing a single file, or to current system data for editing tagged files.
This one sounds good but is a pain in the ass to install, whether using 'apt-key add' to add the publix key, or by using Synaptic Package Manager, which I've installed but can't get to notice the deb file in my Download directory.
I haven't needed to install anew lately, but IIRC, I fetched with wget, installed with dpkg -i. Synaptic I haven't tried to use in many years. Filecommander I've been using since long before I knew Linux existed, since OS/2 2.0.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.