Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Possible Duplicate:
Why does this compound command report errors when copying directories?

if one executes the following two commands in one line, as follows,

rm -rf dir ; cp -r dir2 dir

it may complain that cp can not create directory dir/subdir: File exists

but if these two commands are executed in two lines, no errors will be thrown. I am just wandering what is the difference? and more importantly, how to execute two commands in one line, with the effect exactly the same as by two lines...

PS: what is in dir or dir2 is hugh, typically 4gb

share|improve this question

marked as duplicate by xenoterracide Jul 20 '12 at 23:35

This question was marked as an exact duplicate of an existing question.

You can use '&&' to concatenate commands. It runs the next command if the first was succesful.

rm -rf dir && cp -r dir2 dir

share|improve this answer

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