0

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?

3
  • 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
    Jan 13, 2017 at 19:07
  • 1
    Possibly related: Exclude one pattern from glob match Jan 13, 2017 at 19:21
  • Yes, i mean copy
    – A guest
    Jan 14, 2017 at 13:24

2 Answers 2

1

You could do this using rsync:

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

Use rsync

rsync -av --progress $HOME/* $HOME/Desktop --exclude 'Desktop/'
2
  • This would also exclude hidden files
    – SYN
    Jan 13, 2017 at 19:24
  • Done. Now it will exclude only dirs called Desktop/
    – user34720
    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 .