To move files found using the find command to another directory while maintaining the source directory structure, you can use the cp (copy) command along with the --parents option and then rm (remove) to delete the original files. Here's an example:
find /path/to/search -type f -name "*.txt" -exec sh -c 'cp --parents "{}" /path/to/destination/ && rm "{}"' \;
In this command:
- /path/to/search is the directory where you want to start the search.
- -type f specifies that you are looking for files (not directories).
- -name "*.txt" specifies the pattern to match for file names (replace with your desired file extension or pattern).
- -exec sh -c 'cp --parents "{}" /path/to/destination/ && rm "{}"' \; executes a shell command for each file found. This command copies the file to the destination directory while preserving the directory structure using --parents and then removes the original file.
No comments:
Post a Comment
Thank you for Commenting Will reply soon ......