I am trying to learn how to copy a from one folder to other using command prompt using 'cp' command,file is getting copied from "home" folder to "documents" folder but i am unable to copy from "documents" folder to "home" folder.Can someone explain why?
104 Answers
That depends on what your command actually looks like.
The following would work:
cp /home/$USER/Documents/file /home/$USEROr as @kos suggested:
cp ~/Documents/file ~/ 5 First go to the location from where the file is to copied using the cd command.Then:
cp "foldername" -R ~/"foldername" 2 You can't copy documents into the /home folder without sudo rights. To do that, use this command
sudo cp /home/$USER/Documents/file_name /homeor to save the permissions (thx @kos)
sudo cp --preserve=mode,ownership /home/$USER/Documents/file_name /homeIf you meant your home folder, than use
cp /home/$USER/Documents/file_name ~or
cp /home/$USER/Documents/file_name /home/$USER/ 2 To copy from your documents folder try:
cp filenameHere /home/$USERFor example, assuming I am located at the Documents folder:
/home/$USER/DocumentsAnd I want to copy the file: foo.txt to my home folder:
cp foo.txt /home/$USERIf you are not currently on the Documents foler, you must cd to it first:
cd /home/$USER/DocumentsThen you can do ls to list your files, remember, the terminal and linux commands are case sensitive:
lsAfter the files are listed, use the cp command to copy to the location you want.