Move files in directories in bulk

Asked 2 years ago, Updated 2 years ago, 37 views

Is it possible to move thousands of files in a directory with a specific file extension to a different directory?For example, there are .cpp and .hpp directories. Move all .hpp files in the .cpp directory to the .hpp directory.mv**/*. If you try to use hpp/path/to/single/target/directory, you will not be able to handle many files.

linux

2022-09-30 10:50

2 Answers

The -exec option of the find command is available.However, please note that the behavior is not obvious when trying to move to a subdirectory.

find<Searching Directory >-type f-name "*.hpp" -exec mv{}<Move to Directory >\;

Alternatively, the GNU version of mv can be written as follows:

find<Searching Directory >-type f-name "*.hpp" -exec mv --target-directory=<Traveling Directory >{}+


2022-09-30 10:50

find cpp-name "*.hpp"-print | xargs-I@mv@hpp


2022-09-30 10:50

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.