I would like to copy files from the current directory which are divided into different subdirectories. The files I want to copy should only have
False as their parents.
True directory files should be copied in
False directory files should be in
I haven't been able to figure out how to automate the copying process:
I thought I could use the
find . -maxdepth digitbut I don't know what the exact depth is.
The files should only be
*.txtfiles, and even though some names may be duplicated, their contents are different, so I need either of them in the destination folder, but
cpwould overwrite them.
Falseintermediate parent directories could exist, but my intended files are generated in the last parent directory.
In addition, directory space is about
200GiB, so it takes a while to search through it.
I'm not sure about escape characters in directory and files so I don't really want to break the copying process.
sample working space:
``` __ current dir |__ path_1 |__ True |__ 00000.txt |__ 020.txt |__ p_x |__ 100 |__ True |__ 00000.txt |__ 020.txt |__ 10.txt |__ False |__ 1.txt |__ 2.txt |__ 200.txt |__ x |__ True |__ 00000.txt |__ 020.txt |__ False |__ 1.txt |__ 2.txt |__ True |__ path_2 |__ True |__ 1.txt |__ x_p |__ ... |__ ... . . .
__ dst |__ report |__ 1 |__ 00000.txt |__ 020.txt |__ 00000_1.txt |__ 020_1.txt |__ 10.txt |__ 1.txt |__ 2 |__ 1.txt |__ 2.txt |__ 200.txt |__ 1_1.txt |__ 2_2.txt
As @muru answered cp could be handful but there is a constraint in number of argument it can handle through bash (
shopt -s globstar cp --backup=numbered **/True/*.txt dst/report/1/ cp --backup=numbered **/False/*.txt dst/report/2/
So back then, after executing these commands, was getting
-bash: /bin/cp: Argument list too long in return.
Again as @muru mentioned in comments, it could be possible to solve this issue via
xargs (assuming GNU xargs and cp).
printf "%s\0" **/True/*.txt | xargs -0 cp --backup=numbered -t dst/report/1/
In case of duplicate files with number extension (e.g; bar.txt.~1~, etc)
rename would be useful.
prename 's/(.txt).~(\d+)~$/-$2$1/' dst/report/*/*,