I need to copy a large amount of files into their own directories. The issue I am having is keeping them in order when I copy them with GNU parallel. For example, file_1.output gets placed in dir_19.

Here is what I have so far that is working, besides the order of files.

ls *.output > copy.list
parallel "mkdir cele_{}" ::: {1..10000}
parallel -k --link "cp {} cele_{}" :::: copy.list ::: {1..10000} 

Is there a way to do this without sacrificing parallel?

(Inspired by https://rbt.asia/g/thread/64890073/#64890111)


You can use --rpl to define your own replacement string and then use that both for mkdir and cp.

ls *.output |  parallel --rpl '{dir} s/\.output$/_dir/' 'mkdir {dir} && cp {} {dir}'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.