DEV Community

Discussion on: How to write Bash one-liners for cloning and managing GitHub and GitLab repositories

Collapse
flrichar profile image
Fred Richards • Edited on

This reminds me of something I perform all of the time... not pure bash, but helpful nonetheless.

I have about ~50 git repos I'm pulling down and tracking (others' projects, not mine), so this gnu parallel command says "enter each git repo in the current dir and perform a git pull".

cd path-to-git-repos
parallel cd {}\; git pull ::: `ls`

Best part ... it runs in parallel. So I have 4 cpus and the git repos have nothing to do with each other... it runs four pulls at once.

Collapse
victoria profile image
Victoria Drake Author

That’s awesome!

Would you explain the ::: part? I haven’t seen this syntax before. All I can find is that : means true or something like that.

Collapse
flrichar profile image
Fred Richards • Edited on

It uses the output of the command as an input source. $(ls) would have done the same thing... I like to think of it as performing the operation on a current set.

It doesn't look familiar because its a specific parallel command option, not a general bash option.

Another silly example of a clock-counter ... the -k flag says keep the order (so things don't happen out of order). Perform an echo operation on three sets.

parallel -k echo {1} {2} {3} ::: {0..12} ::: {0..5} ::: {0..9}