Tuesday, April 30, 2024
 Popular · Latest · Hot · Upcoming
4
rated 0 times [  4] [ 0]  / answers: 1 / hits: 911  / 2 Years ago, sat, december 4, 2021, 7:01:58

If i have a directory A that contain directories B , C , D I need a script that search



Directories B , C , D for .deb files and if found copy them to a location i choose .



This script should reduce effort of hand search and copy .



Any idea ?


More From » scripts

 Answers
6

If you don't need to search recursively, then a simple bash brace expansion



cp -t /location/you/choose/ /path/to/A/{B,C,D}/*.deb


should work. If you want to search all subdirectories of A recursively, then the most portable way would probably be



find /path/to/A -name '*.deb' -exec cp -t /location/you/choose/ {} +


If your shell supports it, you could also use the globstar shell option to make cp recursive without using find - type shopt or help shopt at the shell prompt for more information. If you need to exclude certain subdirectories then you could add a -prune to the find command.



As always you need to think ahead about what you want to do in case of non-unique filenames - you could add a -n or --no-clobber to the cp command, or use the --backup=numbered option. In the case of deb files it probably doesn't matter, since (barring file corruption) any non-unique filenames should correspond to exact duplicate files.


[#27740] Sunday, December 5, 2021, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ciousuntru

Total Points: 352
Total Questions: 124
Total Answers: 95

Location: Grenada
Member since Tue, Oct 12, 2021
3 Years ago
;