Copy a Directory Along With Its Relative Path

How to copy a directory from path A to path B, preserving its relative path?

For example, if the directory is found at:


and we want to copy it to


We want the result look like this:


The trick is to use the –parents flag of the “cp” command. So this command will do the job:

cp -r --parents old/path/to/dir new/place/.

And we’re done.

How To Print With Color In Linux Terminal

The proper (and slower ?) way to do this is using ncurses or similar libraries. Here We’ll talk about a “quick and dirty” method using control characters.

There are special characters, referred to as “control characters“, which, when read by the the console, make it change the way it displays text.

The general format of these control characters is:



Continue reading →