Create separate MD5 files recursively for each file


Toverofapover256:

I've always wanted to keep an eye on my file storage and keep an eye out for damage over time when files get damaged.

For this, I'm trying to write a bash/shell script for Linux that recurses through directories and creates an MD5 hash and file for each file, each in the same directory. I'm not a fan of a single file that contains all the hashes, as it would all tip over if a single file kept becoming corrupted or lost.

- Directory 1
    - TestFile.txt
    - TestFile.txt.md5
    - AnotherTestFile.wav
    - AnotherTestFile.wav.md5
- Directory 2
    - MyDetails.docx
    - MyDetails.docx.md5

I've tried using md5sumthe command in multiple ways, but it always wants one:

  1. Creates all hashes in one file.
  2. Each file creates a separate .md5 hash file, but the filename in the MD5 hash file contains the full file path (eg ./Documents/Directory1/TestFile.txt), not just the filename (eg TestFile.txt).

I have tools on Windows that do this( MD5Checker), but it is hashing files on my file server on the network. I'd rather think of something that can run natively on a Linux OS.

Any ideas?

My latest attempt (I know it's bad)

It creates MD5 files, but the file path in the hash and the file is the full file path, not the base file path.

#!/bin/bash

function md5_dir {
for file in $1/*;
do
        if [[ -f "$file" && ! $file == *.md5 ]];
        then
                file_basename=$(basename "$file");
                echo "$file" "$file_basename";
                md5sum "$file" > "$file.md5";
        fi;
        if [[ -d "$file" ]];
        then
                md5_dir $file
        fi;
done;
}



echo "$1"
md5_dir "$1";
other people:

findis the go-to file for what the tool does recursively:

find . -type f ! -name '*.md5' -execdir sh -c 'md5sum "$1" > "$1.md5"' _ {} \;

This picks a file (not named "*.md5") and runs a shell script with that filename given as an inline $1.

Related


Create separate MD5 files recursively for each file

Toverofapover256: I've always wanted to keep an eye on my file storage and keep an eye out for damage over time when files get damaged. For this, I'm trying to write a bash/shell script for Linux that recurses through directories and creates an MD5 hash and fi

Create separate MD5 files recursively for each file

Toverofapover256: I've always wanted to keep an eye on my file storage and keep an eye out for files that get corrupted over time. For this, I'm trying to write a bash/shell script for Linux that recurses through directories and creates an MD5 hash and file fo

Create separate MD5 files recursively for each file

Toverofapover256: I've always wanted to keep an eye on my file storage and keep an eye out for files that get corrupted over time. For this, I'm trying to write a bash/shell script for Linux that recurses through directories and creates an MD5 hash and file fo

Create separate MD5 files recursively for each file

Toverofapover256: I've always wanted to keep an eye on my file storage and keep an eye out for damage over time when files get damaged. For this, I'm trying to write a bash/shell script for Linux that recurses through directories and creates an MD5 hash and fi

Create separate MD5 files recursively for each file

Toverofapover256: I've always wanted to keep an eye on my file storage and keep an eye out for damage over time when files get damaged. For this, I'm trying to write a bash/shell script for Linux that recurses through directories and creates an MD5 hash and fi

Find md5 of files recursively in python directory

fast silver I want to find the md5sum of files that start with "10" (can be exe, doc, pdf, etc.), so don't check the file extension but only the first two digits. So far I've got a script that traverses a directory and prints out all such files, but can't get

Find md5 of files recursively in python directory

fast silver I want to find the md5sum of files that start with "10" (can be exe, doc, pdf, etc.), so don't check the file extension but only the first two digits. So far I've got a script that traverses a directory and prints out all such files, but can't get

Create a separate log file for each iteration in a for loop

Foward I just want to make a script that runs multiple files and stores their output in separate log files. So I wrote the code in such diarya way that the output is generated , but the diaryfunction is only 1 log file and the output is updated in the same log

Create a separate log file for each iteration in a for loop

Foward I just want to make a script that runs multiple files and stores their output in separate log files. So I wrote the code in such diarya way that the output is generated , but the diaryfunction is only 1 log file and the output is updated in the same log

Create a separate log file for each iteration in a for loop

Foward I just want to make a script that runs multiple files and stores their output in separate log files. So I wrote the code in such diarya way that the output is generated , but the diaryfunction is only 1 log file and the output is updated in the same log

Create a separate log file for each iteration in a for loop

Foward I just want to make a script that runs multiple files and stores their output in separate log files. So I wrote the code in such diarya way that the output is generated , but the diaryfunction is only 1 log file and the output is updated in the same log

Create a separate log file for each iteration in a for loop

Foward I just want to make a script that runs multiple files and stores their output in separate log files. So I wrote the code in such diarya way that the output is generated , but the diaryfunction is only 1 log file and the output is updated in the same log

Hash each line in text file Python MD5

kitsunesan1999 I'm trying to write a program that will open a text file and provide an md5 hash for each line of text. For example, I have a text file with: 66090001081992 66109801042010 68340016052015 68450001062015 79450001062016 Here is my code: import has

Hash each line in text file Python MD5

kitsunesan1999 I'm trying to write a program that will open a text file and provide an md5 hash for each line of text. For example, I have a text file with: 66090001081992 66109801042010 68340016052015 68450001062015 79450001062016 Here is my code: import has

Hash each line in text file Python MD5

kitsunesan1999 I'm trying to write a program that will open a text file and provide an md5 hash for each line of text. For example, I have a text file with: 66090001081992 66109801042010 68340016052015 68450001062015 79450001062016 Here is my code: import has

Hash each line in text file Python MD5

kitsunesan1999 I'm trying to write a program that will open a text file and provide an md5 hash for each line of text. For example, I have a text file with: 66090001081992 66109801042010 68340016052015 68450001062015 79450001062016 Here is my code: import has

Bat file to generate MD5 checksums only for files

lock load I've been looking for a way to create a bat file to generate an MD5 checksum of the file. I fcivand a few others have tried , but they all generate a file with additional information like path and filename etc. I just need MD5 and nothing else. Can s

Bat file to generate MD5 checksums only for files

lock load I've been looking for a way to create a bat file to generate an MD5 checksum of the file. I fcivand a few others have tried , but they all generate a file with additional information like path and filename etc. I just need MD5 and nothing else. Can s

Bat file to generate MD5 checksums only for files

lock load I've been looking for a way to create a bat file to generate an MD5 checksum of the file. I fcivand a few others have tried , but they all generate a file with additional information like path and filename etc. I just need MD5 and nothing else. Can s

Bat file to generate MD5 checksums only for files

lock load I've been looking for a way to create a bat file to generate an MD5 checksum of the file. I fcivand a few others have tried , but they all generate a file with additional information like path and filename etc. I just need MD5 and nothing else. Can s