LinuxQuestions.org
Visit Jeremy's Blog.
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-30-2023, 04:52 AM   #16
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 Racho View Post
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 ...)
The formats might be anything, but are mostly HTML. More specifically, they're mostly downloaded news articles. The publication date is the date you see at the top of most articles, along with the author.

Other file formats are mostly PDF, and in this case the publication date is determined by what's in the PDF. It might be a book with only a year for the date, a report where the publication date might be anywhere or not even included, a government document, etc. All have different text formats and locations for the date, so automating the search for it is out of the question.

I tried writing a software program to do this with HTML files in Visual Studio for Windows. I learned that it's not easy to automate the process of looking for the right date and being sure you get the right one, even just with HTML, so the files have to be viewed manually. That I can accept. But having to use the touch command in bash to edit the file's date requires too much work when dealing with a lot of files, since I would have to look at each HTML file in a browser, then cut/paste the file name and add the proper date in bash for the touch command. Many HTML files have encrypted text, including the date of publication of the article, so that's another problem that has to be considered if you think you can automate this with a script.

A simple date changing utility that works in Gnome's file manager is all I really need. Anyone in this forum for software who suggests using some bash script is off-topic, in my opinion. It won't work anyway. I only mentioned the touch command because that's the only way I currently know how to do it, but it's not really something for bash to handle. It's not even easy to automate with a programming language.

Like I said in my OP, I'll need to open each file in a directory to see the publication dates before changing their modification dates.
 
Old 07-30-2023, 06:09 AM   #17
Racho
Member
 
Registered: Oct 2021
Posts: 59

Rep: Reputation: Disabled
The gnome's default file manager has not an option nor an extension to change the file's timestamps. But it has the capability to integrate scripts.

So you either install a file manager that can do that (we suggested filecommander and doublecommander) or make a script for the file manager "files" to cover this feature (help here).

I can't see any other option for you.
 
Old 07-30-2023, 09:22 AM   #18
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,813

Rep: Reputation: 5958Reputation: 5958Reputation: 5958Reputation: 5958Reputation: 5958Reputation: 5958Reputation: 5958Reputation: 5958Reputation: 5958Reputation: 5958Reputation: 5958
Quote:
A simple date changing utility that works in Gnome's file manager is all I really need. Anyone in this forum for software who suggests using some bash script is off-topic, in my opinion. It won't work anyway.
Not off topic at all. A right click menu that runs a bash script fits your simple date changing utility requirements. I've expanded it a bit to include a simple date verification and uses current time.
Code:
#!/bin/bash
cfile=$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS
mtime=$(date '+%H%M')
newdate=$(zenity --entry --title="Change MOD date for file" --text="File to change "$cfile" \n change date YYYY/MM/DD")
if [ $? = 0 ] # check if the user click ok on the zenity form
then
    echo "New date =$newdate"
    if ! [[ $newdate =~ ^[0-9]{4}/[0-9]{2}/[0-9]{2}$ ]]; then
       echo "bad date"
       exit
    fi 
    mdate=$(echo $newdate | sed 's;/;;g')
    touch -m -t "$mdate$mtime" $cfile
else
    echo "Cancel button was pressed"
fi

Last edited by michaelk; 07-30-2023 at 09:39 AM.
 
Old 07-30-2023, 09:33 AM   #19
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,643

Rep: Reputation: 2561Reputation: 2561Reputation: 2561Reputation: 2561Reputation: 2561Reputation: 2561Reputation: 2561Reputation: 2561Reputation: 2561Reputation: 2561Reputation: 2561
Quote:
Originally Posted by anthonyforwood View Post
It's not even easy to automate with a programming language.
Easy is relative - none of the problems you've raised are insurmountable.

Still, if we pretend they are, there's remains a straight-forward solution:

1. Export the file names and modified dates to a tab-separated text file, and open it in suitable software (e.g. LibreOffice Calc)
2. Manually view relevant files and add copy-paste publish dates in a third column, then afterwards ensure each one is accepted as a date and reformatted to a suitable format.
3. Save the result as tab separated file, then write a Bash script to while/read loop through and touch the files.


Last edited by boughtonp; 07-30-2023 at 09:34 AM.
 
Old 07-30-2023, 09:57 AM   #20
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,157
Blog Entries: 6

Rep: Reputation: 1836Reputation: 1836Reputation: 1836Reputation: 1836Reputation: 1836Reputation: 1836Reputation: 1836Reputation: 1836Reputation: 1836Reputation: 1836Reputation: 1836
Quote:
The formats might be anything, but are mostly HTML.
This can be done any number of ways, easily. Loop through the files that you want to change. Doesn't matter what type of file it is.

Another example:
Code:
agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/114.0"

url="https://www.linuxquestions.org/questions/linux-software-2/is-there-an-app-to-both-\
open-and-change-file-modification-times-for-each-file-in-a-folder-4175727443/page2.html"

curl -A "$agent" "$url" -o test.html

stat test.html
  File: test.html
  Size: 62552           Blocks: 128        IO Block: 4096   regular file
Device: 8,2     Inode: 17326087    Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/   me)   Gid: ( 1000/   me)
Access: 2023-07-30 09:40:47.093853081 -0500
Modify: 2023-07-30 09:40:46.480519718 -0500
Change: 2023-07-30 09:40:46.480519718 -0500
 Birth: 2023-07-30 09:40:46.467186386 -0500
 
clock_time="jan 10 12:34 2018"

Time_sec=$(date -d "$clock_time")

echo "$Time_sec"
Wed Jan 10 12:34:00 PM CST 2018

touch -d "$Time_sec" test.html

stat test.html
  File: test.html
  Size: 62552           Blocks: 128        IO Block: 4096   regular file
Device: 8,2     Inode: 17326087    Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/   me)   Gid: ( 1000/   me)
Access: 2023-07-30 09:53:59.650559110 -0500
Modify: 2018-01-10 12:34:00.000000000 -0600
Change: 2023-07-30 09:53:59.143892418 -0500
 Birth: 2023-07-30 09:40:46.467186386 -0500
File loop:
Code:
f=(*)
for i in "${f[@]}"; do
    echo "$i"
    sleep 1
done
 
Old 07-31-2023, 12:20 AM   #21
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 boughtonp View Post
Easy is relative - none of the problems you've raised are insurmountable.

Still, if we pretend they are, there's remains a straight-forward solution:

1. Export the file names and modified dates to a tab-separated text file, and open it in suitable software (e.g. LibreOffice Calc)
2. Manually view relevant files and add copy-paste publish dates in a third column, then afterwards ensure each one is accepted as a date and reformatted to a suitable format.
3. Save the result as tab separated file, then write a Bash script to while/read loop through and touch the files.
Do you think that's a straightforward solution? That would require at least as much work as using touch in bash.

I'm trying to minimize the steps needed to perform the task. I posted in the software forum because I thought there might be a software package out there that someone knows about.

Having actual experience in trying to solve a problem is more enlightening than imagining that you can solve it.
 
Old 07-31-2023, 12:54 AM   #22
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 teckk View Post
This can be done any number of ways, easily. Loop through the files that you want to change. Doesn't matter what type of file it is.

Another example:
Code:
agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/114.0"

url="https://www.linuxquestions.org/questions/linux-software-2/is-there-an-app-to-both-\
open-and-change-file-modification-times-for-each-file-in-a-folder-4175727443/page2.html"

curl -A "$agent" "$url" -o test.html

stat test.html
  File: test.html
  Size: 62552           Blocks: 128        IO Block: 4096   regular file
Device: 8,2     Inode: 17326087    Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/   me)   Gid: ( 1000/   me)
Access: 2023-07-30 09:40:47.093853081 -0500
Modify: 2023-07-30 09:40:46.480519718 -0500
Change: 2023-07-30 09:40:46.480519718 -0500
 Birth: 2023-07-30 09:40:46.467186386 -0500
 
clock_time="jan 10 12:34 2018"

Time_sec=$(date -d "$clock_time")

echo "$Time_sec"
Wed Jan 10 12:34:00 PM CST 2018

touch -d "$Time_sec" test.html

stat test.html
  File: test.html
  Size: 62552           Blocks: 128        IO Block: 4096   regular file
Device: 8,2     Inode: 17326087    Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/   me)   Gid: ( 1000/   me)
Access: 2023-07-30 09:53:59.650559110 -0500
Modify: 2018-01-10 12:34:00.000000000 -0600
Change: 2023-07-30 09:53:59.143892418 -0500
 Birth: 2023-07-30 09:40:46.467186386 -0500
File loop:
Code:
f=(*)
for i in "${f[@]}"; do
    echo "$i"
    sleep 1
done
I have little knowledge of what that's doing and there aren't any comments to explain it, but it looks like overkill on the data it produces and doesn't seem to take into account the fact that I need to look inside each file to get the proper publication date before I can change it.
 
  


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 06:03 PM.

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