Home > Enterprise >  How can I create two files of identical size and date modified?
How can I create two files of identical size and date modified?

Time:08-01

We are using some backup tooling that copies files from source to destination. Part of this is MD5 checking the files to see if the contents have changed.

How can I create two identical sized and date created files on my machine with different contents? Is there a script or online service I can use? I'd like to use these for a test scenario e.g.

  1. files same size different timestamp = sync files to backup
  2. files same size different content same timestamp = sync files to backup

Bash or Python is okay script wise. We are looking to use rsync --checksum in combination with aws s3 sync at the moment but need to test specific scenarios to be sure these tools do what we want.

Thanks

CodePudding user response:

You can create a file with a specified size and arbitrary content using head --bytes=NUM < /dev/urandom >newfile, where NUM is the filesize in bytes and also accepts a multiplier suffix such as MB or GB (check the manual of head). You can run this command twice to make two files of the same size and different content, or just run it once and then copy the file to get files with the same size and content.

Timestamps can be manipulated with touch --date=STRING. Either touch both using the same date string, or touch them with different date strings to give them different timestamps.

  • Related