Recursively copying between two directories including hidden files

Sometimes we need to override large structure of directories and subdirectories with newer files.

There are two ways of copying all the files in one directory including subdirectories and hidden files to another directory:

cd /orig/dir
tar cvf - . | (cd /dest/dir; tar xvf -)

which tars up the current directory to stdout then pipes it to a subshell that first cd's to the destination directory before untarring stdin.

The second way of doing this is using cp:

yes | cp -rT /orig/dir /dest/dir 2> /dev/null

Note there are no trailing slashes in the end of directories. Also we send output to null, because cp is too noisy.

Add new comment

Filtered HTML

  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <pre>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.