copying a file from documents folder to home folder using cp command [closed]

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?

10

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 ~/
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 /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/
2

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.

2

You Might Also Like