Combining Commands
Learn different approaches to combine two commands.
We'll cover the following
Using semicolon
We already know how to combine Bash commands with pipelines and logical operators. However, there is a third way to do that. We can put a semicolon (;
) as a delimiter between commands. In this case, Bash executes them one by one, from left to right, without any conditions. We get the linear sequence algorithm, in this case.
We’ll go through an example. Let’s suppose that we want to copy two directories to different target paths. A single cp
call cannot do it. However, we can combine two calls into one command like this:
cp -R ~/docs ~/docs-backup ; cp -R ~/photo ~/photo-backup
Run the commands discussed in this lesson in the terminal below.
Get hands-on with 1400+ tech skills courses.