Skip to content

Instantly share code, notes, and snippets.

@xdevs23
Last active April 9, 2017 15:36
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 xdevs23/b37510335175c7e1f03300f4247d9a74 to your computer and use it in GitHub Desktop.
Save xdevs23/b37510335175c7e1f03300f4247d9a74 to your computer and use it in GitHub Desktop.
# Copies files that have a specific extension to another directory while keeping directory structure and remove the prefix
# Example: ./dir_00000032.chk/Media/Backgrounds/Indoors/hall.jpg -> ../recov/jpg/Media/Backgrounds/Indoors/hall.jpg
# Replace the extension as you like
find -name "*.jpg" -type f -print0 | xargs -0 -i bash -c 'tt="$(echo -n '"'"'{}'"'"' | sed -e '"'"'s/[.]\/[^/]*\///g'"'"')"; mkdir -p "../recov/jpg/$(dirname '"\""'$tt'"\""')"; cp -v '"'"'{}'"'"' "../recov/jpg/$tt"'
# To remove the extension completely and just copy everything:
find -type f -print0 | xargs -0 -i bash -c 'tt="$(echo -n '"'"'{}'"'"' | sed -e '"'"'s/[.]\/[^/]*\///g'"'"')"; mkdir -p "../recov/$(dirname '"\""'$tt'"\""')"; cp -v '"'"'{}'"'"' "../recov/$tt"'
# Of course replace the things as you like
# This comes extremely useful when you have found.* folders from chkdsk which you want to extract
# files from.
# Other examples
# Copy music
find -type f \( -name "*.mp3" -o -name "*.mp2" -o -name "*.ogg" -o -name "*.flac" -o -name "*.wav" -o -name "*.aac" \) -print0 | xargs -0 -i bash -c 'tt="$(echo -n '"'"'{}'"'"' | sed -e '"'"'s/[.]\/[^/]*\///g'"'"')"; mkdir -p "../recov/music/$(dirname '"\""'$tt'"\""')"; cp -v '"'"'{}'"'"' "../recov/music/$tt"'
# Copy images
find -type f \( -name "*.png" -o -name "*.tif" -o -name "*.tiff" -o -name "*.gif" -o -name "*.tga" -o -name "*.pdn" \) -print0 | xargs -0 -i bash -c 'tt="$(echo -n '"'"'{}'"'"' | sed -e '"'"'s/[.]\/[^/]*\///g'"'"')"; mkdir -p "../recov/images/$(dirname '"\""'$tt'"\""')"; cp -v '"'"'{}'"'"' "../recov/images/$tt"'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment