Skip to content

Instantly share code, notes, and snippets.

@rolfen
Last active February 4, 2021 20:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rolfen/e6c39d77a0bba581b9826d2d633eb7f5 to your computer and use it in GitHub Desktop.
Save rolfen/e6c39d77a0bba581b9826d2d633eb7f5 to your computer and use it in GitHub Desktop.
MyArchive

Warning These are for educative purposes (examples, tips, etc.). Do not blindly execute them.

Fix double separator in hash-file (double or more space -> single space)

cat meta/hash-file.list | sed -E 's/^(\S+)\s{2,}(\S.+)$/\1 \2/'

Fix windows newlines in file

cat meta/hash-file.list | tr -s '\r\n' '\n'

Extract files from hash-file list

cat meta/hash-file.list | sed -E 's/^\S+\s+//' > meta/previous.file.list

List current files

find -type f -not -path "./meta/*" > meta/file.list

List changes (files which were either added or removed)

cat meta/previous.file.list meta/file.list |sort |uniq -u > meta/diff.file.list

List duplicates

cat hash-file.list |grep -f <(cat hash-file.list |cut -d ' ' -f 1|sort |uniq -d)

List deletions

cat meta/previous.file.list meta/diff.file.list |sort |uniq -d > meta/deleted.file.list

List additions

cat meta/file.list meta/diff.file.list |sort |uniq -d > meta/added.file.list

Alternative:

comm -13 <(cat hash-file.list |sed -E 's/^\S+\s+//' |sort) <(cd '/var/run/media/rolf/Heavy Pink/Archive/photo/'; find . -type f |sort;) 

Update lists for deletions

cat meta/hash-file.list |grep -F -f meta/deleted.file.list > meta/deleted.hash-file.list
cat meta/hash-file.list |grep -vF -f meta/deleted.hash-file.list  > meta/tmp.hash-file.list
cat meta/deleted.hash-file.list | cut -d ' ' -f 1  >> meta/every-deleted.hash.list
mv -f meta/tmp.hash-file.list meta/hash-file.list
rm meta/deleted.hash-file.list

Update lists for additions

md5deep -f meta/added.file.list >> meta/hash-file.list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment