Deleted user content by accident I was trying to empty the trash from terminal because Xcode was stuck in it, but I accidentally removed the trash from the path and ran sudo rm -rf ~/ I thought for a moment i was changing the directory. 

The question is how do I repair the user folders and everything else, icloud and appstore won't login it says unknown error.
The first thing I would try is to log-out and log-in again. In most cases, this will fix your problem.

If not, you have to create a new user account and transfer the data which is left to this new user account. I don't recommend copying the whole Library to the new user account because it could be that your Library is damaged too. I would just copy individual folders like Application Support, Services and so on.