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

I need to make a copy of my home directory and place that copy in the same home directory. The exit code of the command must be 0. Currently, my home directory does not contain any other directories.

Is there a better way than the following? (pwd is the home directory)

mkdir /tmp/temp && cp * /tmp/temp && mv /tmp/temp .
share|improve this question
up vote 5 down vote accepted

Call rsync and exclude the directory where you're putting the copy.

mkdir copy
rsync -a --exclude=copy . copy

Copying * excludes dot files (files whose name begins with a .), which are common and important in a home directory.

share|improve this answer

That will neglect to copy any .* files that may exist in your home directory. I'd probably use rsync like so:

$ mkdir /tmp/temp && rsync -av . /tmp/temp/. && rsync -av /tmp/temp/ .

I'm not that thrilled about doing this as a chain of cmd1 && cmd2 && cmd3, since problems can occur, but if you're careful it should be OK.

share|improve this answer
Nice use of rsync! – Barun Dec 29 '13 at 19:18

How about creating a temporary directory in your home directory itself and then copying?

mkdir tmp
for item in *
    if [[ "$item" != tmp ]]
        cp "$item" tmp

This is an alternative, but can't say if better though.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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