LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This 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


Reply
  Search this Thread
Old 07-28-2023, 06:58 AM   #1
anthonyforwood
LQ Newbie
 
Registered: Dec 2022
Location: Vancouver, BC
Distribution: Ubuntu 22.04.03 LTS w/ Gnome 42.9 and X11
Posts: 29

Rep: Reputation: 1
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.
 
Old 07-28-2023, 12:46 PM   #2
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS, Manjaro
Posts: 5,772

Rep: Reputation: 2768Reputation: 2768Reputation: 2768Reputation: 2768Reputation: 2768Reputation: 2768Reputation: 2768Reputation: 2768Reputation: 2768Reputation: 2768Reputation: 2768
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.

Better information at this page https://www.howtogeek.com/517098/lin...ime-and-ctime/

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.

Last edited by wpeckham; 07-28-2023 at 12:52 PM.
 
Old 07-28-2023, 02:55 PM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,790

Rep: Reputation: 5951Reputation: 5951Reputation: 5951Reputation: 5951Reputation: 5951Reputation: 5951Reputation: 5951Reputation: 5951Reputation: 5951Reputation: 5951Reputation: 5951
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.
 
Old 07-28-2023, 10:08 PM   #4
mrmazda
LQ Guru
 
Registered: Aug 2016
Location: SE USA
Distribution: openSUSE 24/7; Debian, Knoppix, Mageia, Fedora, others
Posts: 5,881
Blog Entries: 1

Rep: Reputation: 2078Reputation: 2078Reputation: 2078Reputation: 2078Reputation: 2078Reputation: 2078Reputation: 2078Reputation: 2078Reputation: 2078Reputation: 2078Reputation: 2078
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.
 
1 members found this post helpful.
Old 07-29-2023, 03:33 AM   #5
anthonyforwood
LQ Newbie
 
Registered: Dec 2022
Location: Vancouver, BC
Distribution: Ubuntu 22.04.03 LTS w/ Gnome 42.9 and X11
Posts: 29

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by wpeckham View Post
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.

Better information at this page https://www.howtogeek.com/517098/lin...ime-and-ctime/

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.
 
Old 07-29-2023, 04:32 AM   #6
Racho
Member
 
Registered: Oct 2021
Posts: 59

Rep: Reputation: Disabled
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 hope that helps
 
1 members found this post helpful.
Old 07-29-2023, 04:44 AM   #7
mrmazda
LQ Guru
 
Registered: Aug 2016
Location: SE USA
Distribution: openSUSE 24/7; Debian, Knoppix, Mageia, Fedora, others
Posts: 5,881
Blog Entries: 1

Rep: Reputation: 2078Reputation: 2078Reputation: 2078Reputation: 2078Reputation: 2078Reputation: 2078Reputation: 2078Reputation: 2078Reputation: 2078Reputation: 2078Reputation: 2078
Quote:
Originally Posted by Racho View Post
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.
 
Old 07-29-2023, 06:37 AM   #8
anthonyforwood
LQ Newbie
 
Registered: Dec 2022
Location: Vancouver, BC
Distribution: Ubuntu 22.04.03 LTS w/ Gnome 42.9 and X11
Posts: 29

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by michaelk View Post
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.
 
Old 07-29-2023, 08:04 AM   #9
Racho
Member
 
Registered: Oct 2021
Posts: 59

Rep: Reputation: Disabled
Quote:
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 ...)
 
Old 07-29-2023, 01:06 PM   #10
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS, Manjaro
Posts: 5,772

Rep: Reputation: 2768Reputation: 2768Reputation: 2768Reputation: 2768Reputation: 2768Reputation: 2768Reputation: 2768Reputation: 2768Reputation: 2768Reputation: 2768Reputation: 2768
I would build a custom script for that: PERL, or BASH most likely, depending upon the file format and tools available.
 
Old 07-29-2023, 01:40 PM   #11
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,790

Rep: Reputation: 5951Reputation: 5951Reputation: 5951Reputation: 5951Reputation: 5951Reputation: 5951Reputation: 5951Reputation: 5951Reputation: 5951Reputation: 5951Reputation: 5951
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.

https://wiki.archlinux.org/title/GNOME/Files

Something like:
Code:
#!/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

Last edited by michaelk; 07-29-2023 at 02:02 PM.
 
Old 07-29-2023, 01:51 PM   #12
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,257

Rep: Reputation: 5338Reputation: 5338Reputation: 5338Reputation: 5338Reputation: 5338Reputation: 5338Reputation: 5338Reputation: 5338Reputation: 5338Reputation: 5338Reputation: 5338
Some ideas here:

https://unix.stackexchange.com/quest...o-another-file
 
Old 07-29-2023, 03:50 PM   #13
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,153
Blog Entries: 6

Rep: Reputation: 1835Reputation: 1835Reputation: 1835Reputation: 1835Reputation: 1835Reputation: 1835Reputation: 1835Reputation: 1835Reputation: 1835Reputation: 1835Reputation: 1835
Give you a shove.

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.
 
Old 07-30-2023, 01:32 AM   #14
anthonyforwood
LQ Newbie
 
Registered: Dec 2022
Location: Vancouver, BC
Distribution: Ubuntu 22.04.03 LTS w/ Gnome 42.9 and X11
Posts: 29

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by mrmazda View Post
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.
 
Old 07-30-2023, 01:39 AM   #15
mrmazda
LQ Guru
 
Registered: Aug 2016
Location: SE USA
Distribution: openSUSE 24/7; Debian, Knoppix, Mageia, Fedora, others
Posts: 5,881
Blog Entries: 1

Rep: Reputation: 2078Reputation: 2078Reputation: 2078Reputation: 2078Reputation: 2078Reputation: 2078Reputation: 2078Reputation: 2078Reputation: 2078Reputation: 2078Reputation: 2078
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.
 
  


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
[SOLVED] current 19/12/2020 file and link modification times are in the future justwantin Slackware - ARM 3 01-06-2020 01:31 PM
How to burn DVDs keeping the files modification times? stf92 Linux - Software 0 01-21-2014 12:23 AM
make multiple folder on samba linux & each folder can be access each person only Aneesh.T .S Linux - Server 1 01-31-2013 06:01 PM
[SOLVED] Better way to create a folder for each month, with another folder inside of each anon091 Linux - Newbie 9 12-03-2012 10:38 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:53 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