Time travel - how to edit PDFs from the past (on Mac)
Nov 22, 2021
If you want to modify a file so it looks like it was created or modified on a specific date, you've come to the right place.
For this example, I'll be using SmallPDF's example PDF.
touch -mt 202101310100 file.pdf
command to change a file's created and modified dates (timestamp is in format YYYYMMDDHHSS
). But watch out if your file is a PDF - you may need to clear the PDF's version history too (more on this below).⏰ Changing a file's created and modified timestamps
If I open up my pdf-from-past
folder in Finder, this is what I see:
sample.pdf
was created and modified today (November 2021). Let's change it to January 2021.
Find your file in Terminal
- Open up Terminal (open Applications and launch
Terminal.app
)
- Enter the folder where your file lives, using the
cd
(change directory) command. For example, I'm entering mypdf-from-past
folder with the command:
cd Downloads/blog-samples/pdf-from-past
- Use the
ls
command to list files & directories in your current folder - your target file should be in there (mine is calledsample.pdf
):
Use "touch" to change the file's timestamps
Change the file's created and modified dates with the touch -mt TIMESTAMP FILE
command. For example, set sample.pdf
's dates to 31 January 2021 at 0100:
touch -mt 202101310100 sample.pdf
The timestamp is in format YYYYMMDDHHSS
. The result:
If you want to change the file's modified date, run the command again with a new timestamp. For example, change its modified date to 3 February 2021 at 0400:
touch -mt 202102030400 sample.pdf
The result:
And you're done! Time travel complete... unless your file is a PDF. 🤔
🚮 Clearing version history for PDFs
The Preview app on Mac supports version history for PDFs. Even after you've edited the PDF's metadata, the file's version history might reveal when it was actually edited.
Check if your PDF contains any previous versions
- Open your PDF using Preview on Mac
- Go to File > Revert To
- Does the list contain anything except "Browse All Versions..."?
My PDF contains one previous version:
Compress the PDF to wipe the file's version history
I couldn't figure out an easy way to clear a PDF's version history in Preview (please email me if you figure it out!) so I figured out a workaround: compress the PDF.
If your PDF contains sensitive data, compress it locally using a tool like Ghostscript.
For non-sensitive files, I just use SmallPDF because it's a bit easier.
- Upload your file
- Compress the file using "Basic compression"
- Download the compressed file
Now open the compressed file in Preview and check File > Revert To:
The versions list is empty! Nice!
However... our compressed file's timestamps are wrong. We need to change them again.
We can re-use the same commands from before and just tweak the filename to use the new file:
touch -mt 202101310100 sample-compressed.pdf
touch -mt 202102030400 sample-compressed.pdf
Done! The new sample-compressed.pdf
file is smaller, doesn't have a version history, and has the correct created and modified dates! ⚡