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?
4 Answers
That depends on what your command actually looks like.
The following would work:
cp /home/$USER/Documents/file /home/$USER
Or as @kos suggested:
cp ~/Documents/file ~/
-
This will copy the whole
~/Documents/
folder to~/
; also maybe use the shorthandedcp ~/Documents/file ~/
, this way the command will also work right away once copy-pasted– kosJul 24, 2015 at 13:11 -
-
/home
is not writabel by a normal user. My guess is you want to copy it to your own homefolder, which is/home/yourusername
. The command is thencp b.txt ~/
(see above). If you do want to copy it in just plain/home
, you will have to runsudo cp b.txt /home
.– aaireyJul 24, 2015 at 13:25 -
@identicon Linux systems are case sensitive, so you want
sudo cp b.txt /home
– kosJul 24, 2015 at 13:31 -
@aairey Please use $USER (it will change the command into the user used so tends to work for all of us). Or of course "~"– RinzwindJul 24, 2015 at 14:47
First go to the location from where the file is to copied using the cd
command.Then:
cp "foldername" -R ~/"foldername"
-
This will copy recursively all the directories / files in
foldername
in~/foldername
– kosJul 24, 2015 at 13:39 -
Ok i am sorry I mistook the question for the abovesaid. Yes it will. Jul 24, 2015 at 13:45
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 /home
or to save the permissions (thx @kos)
sudo cp --preserve=mode,ownership /home/$USER/Documents/file_name /home
If you meant your home
folder, than use
cp /home/$USER/Documents/file_name ~
or
cp /home/$USER/Documents/file_name /home/$USER/
-
-
And if one wants to preserve permissions / ownership:
sudo cp --preserve=mode,ownership /home/identicon/Documents/file_name /home
– kosJul 24, 2015 at 13:17
To copy from your documents folder try:
cp filenameHere /home/$USER
For example, assuming I am located at the Documents folder:
/home/$USER/Documents
And I want to copy the file: foo.txt to my home folder:
cp foo.txt /home/$USER
If you are not currently on the Documents foler, you must cd to it first:
cd /home/$USER/Documents
Then you can do ls
to list your files, remember, the terminal and linux commands are case sensitive:
ls
After the files are listed, use the cp
command to copy to the location you want.
-
-
To do that do: 1 >> home.txt where 1 is the content of the file, this is a fast way, so you can create any file, with any title if no file with the same name is already on the current location.– GTRONICKJul 24, 2015 at 13:24
home
folder? Yourhome
folder, eg/home/identicon
or/home
/home
a garbage.. It's the designated place for individual users home directories..