-4

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
  • What do you mean with home folder? Your home folder, eg /home/identicon or /home
    – A.B.
    Jul 24, 2015 at 13:07
  • Is there any error output?
    – leorize
    Jul 24, 2015 at 13:07
  • 2
    Don't make /home a garbage.. It's the designated place for individual users home directories..
    – heemayl
    Jul 24, 2015 at 13:35
  • 2
    You need to edit your question and post the exact commands you are typing, with exact capitalization: otherwise we can only guess what the issue is. Jul 24, 2015 at 13:38
  • 1
    Please provide the actual commands or this will be riddled with comments and the answers will be partially guesses
    – Rinzwind
    Jul 24, 2015 at 14:54

4 Answers 4

2

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
  • This will copy the whole ~/Documents/ folder to ~/; also maybe use the shorthanded cp ~/Documents/file ~/, this way the command will also work right away once copy-pasted
    – kos
    Jul 24, 2015 at 13:11
  • Notebook-PC:~/Documents$ cp b.txt /Home is the command
    – identicon
    Jul 24, 2015 at 13:18
  • /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 then cp b.txt ~/ (see above). If you do want to copy it in just plain /home, you will have to run sudo cp b.txt /home.
    – aairey
    Jul 24, 2015 at 13:25
  • @identicon Linux systems are case sensitive, so you want sudo cp b.txt /home
    – kos
    Jul 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 "~"
    – Rinzwind
    Jul 24, 2015 at 14:47
0

First go to the location from where the file is to copied using the cd command.Then:

cp "foldername" -R ~/"foldername"
2
  • This will copy recursively all the directories / files in foldername in ~/foldername
    – kos
    Jul 24, 2015 at 13:39
  • Ok i am sorry I mistook the question for the abovesaid. Yes it will.
    – Rahul Nair
    Jul 24, 2015 at 13:45
0

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
  • not working with sudo also
    – identicon
    Jul 24, 2015 at 13:16
  • And if one wants to preserve permissions / ownership: sudo cp --preserve=mode,ownership /home/identicon/Documents/file_name /home
    – kos
    Jul 24, 2015 at 13:17
0

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
  • it is creating a file named home in documents folder itself
    – identicon
    Jul 24, 2015 at 13:19
  • 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.
    – GTRONICK
    Jul 24, 2015 at 13:24

Not the answer you're looking for? Browse other questions tagged .