Copy a directory and its contents in Unix

We would like to add the following files/folders to your Desktop directory.

blah/
  dexter/
    creepy.txt
  person.txt

Enter the Unix commands that can make these files and folders:

Desktop $ mkdir -p blah/dexter
Desktop $ touch blah/person.txt
Desktop $ touch blah/dexter/creepy.txt

To copy the contents of the blah/ directory into a directory called copy/, run the following command:

$ mkdir copy/ && cp -r blah/* copy/

This will make the copy/ directory and recursively iterate over the contents of the blah/ directory to add them in the copy/ directory.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s