I want to copy all files (included sub-folders) from $HOME directory to Desktop in bash. And as you know the Desktop is in $HOME. So, when I copy all files I get the message like this:

cannot copy a directory, '/home/adminuser/Desktop', into itself, '/home/adminuser/Desktop/'.

And I don't know the suitable code to exclude the folder Desktop. I use this: cp -r $HOME/* ~/Desktop/

Does anybody know a code for it or can anybody help me?

  • Do you actually mean copy, or do you mean move? Just asking because it's more common to want to move files around rather than duplicating them...
    – Kusalananda
    Commented Jan 13, 2017 at 19:07
  • 1
    Possibly related: Exclude one pattern from glob match Commented Jan 13, 2017 at 19:21
  • Yes, i mean copy
    – A guest
    Commented Jan 14, 2017 at 13:24

2 Answers 2


You could do this using rsync:

rsync -avWxP --exclude Desktop /home/user/ /home/user/Desktop/

Use rsync

rsync -av --progress $HOME/* $HOME/Desktop --exclude 'Desktop/'
  • This would also exclude hidden files
    – SYN
    Commented Jan 13, 2017 at 19:24
  • Done. Now it will exclude only dirs called Desktop/
    – user34720
    Commented Jan 13, 2017 at 19:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .