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?

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/'
  • This would also exclude hidden files – SYN Jan 13 '17 at 19:24
  • Done. Now it will exclude only dirs called Desktop/ – user34720 Jan 13 '17 at 19:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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