Skip to content

Instantly share code, notes, and snippets.

@HateFindingNames
Created February 2, 2024 10:17
Show Gist options
  • Select an option

  • Save HateFindingNames/d3fadf2ba37166775349ac6f43ae0f4b to your computer and use it in GitHub Desktop.

Select an option

Save HateFindingNames/d3fadf2ba37166775349ac6f43ae0f4b to your computer and use it in GitHub Desktop.
Find files matching PATTERN in cwd and move to DESTINATION
find . ! -type d -print | grep -i -E "PATTERN" | rsync -nhaPvv --files-from=- --exclude="*/" --no-implied-dirs . DESTINATION

find

  • ! -type d: exclude directories from results
  • -print: output to stdin

grep

  • -i: match case-insensitive
  • -E: extended regular expressions

rsync

  • -n: dry run
  • -h: output number shuman readable
  • -a: preserve timestamps and stuff
  • -P: show transfer progress
  • -vvv: the more v, the more verbose
  • --files-from=-: execute on each piped result
  • --exclude="*/": exclude directories
  • --no-implied-dirs: and exclude implizit dirs
  • --remove-source-files: remove source files after tranfser (move instead of copy)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment