Score:0

What is the command to copy the contents of "/media/sf_Shared_Folder/myfolder/" to "/var/www/myfolder"?

cn flag

I'm using Ubuntu 20.04 and I have a folder full of files in /media/sf_Shared_Folder/myfolder/. I want to copy the contents of this folder to /var/www/myfolder.

I prefer to use the GUI, however I keep getting permissions problems, so I'm trying to use the terminal but I am still learning the commands.

So what is the command I should use to copy the contents of /media/sf_Shared_Folder/myfolder/ to /var/www/myfolder?

Appreciate the help.

janos avatar
in flag
Please include the error messages of the "permissions problems".
Score:2
in flag

The /var/www directory is generally owned by the web server, which is why you are seeing permission issues when you are copying from the GUI. The simple answer to your question would be this:

sudo cp -R {source} {destination}

Breaking this down:

Element Meaning
sudo "Super User DO", which means "do this (the command that follows) with root privileges"
cp Copy
-R Include subdirectories
{source} Where to read from
{destination} Where to write to

This means that you would type the following command into your Terminal:

sudo cp -R /media/sf_Shared_Folder/myfolder/* /var/www/myfolder

If this is something you will do regularly, it may be worthwhile to look at adding your user account to the same group as the web server, or perhaps changing the source directory for the web server to the shared location

Score:0
pl flag

The /var folder is a somewhat special folder in Linux (and other Unix operating systems). It is used by the operating system to write stuff it needs for log purposes, administration, etc...

I am not sure you want/should move your stuff in there. As a user you can read and run files there but not write, as the owner most probably is the root super-user and, unless you have access to that user, you will not be able to either change the permissions (chmod) or copy anything to there (cp/mv).

You most probably should not. You most probably should move that somewhere else.

ozstar avatar
cn flag
Many thanks guys. I really appreciate your input and guidance. I will ingest the info so it helps my journey into Linux land. I'm looking for whatever it takes to save as much time as I can doing things, but at the moment as I struggle to learn, time is not my friend if you know what I mean. It's harder when the easiness of Windows habit creeps in. The analogy for me at the moment is working in Windows is like a racehorse on a racetrack, whilst Linux for me is like a horse on a steeplechase track, so many jumps. :-)
Score:0
cn flag

I assume that /var/www/myfolder is served by a web server or another web application that runs under the www-data account and that you want to publish some media files.

This will copy all the content of /media/sf_Shared_Folder/myfolder to /var/www/myfolder:

( cd /media/sf_Shared_Folder/myfolder && tar cf - . ) |
( sudo su -s /bin/sh www-data -c 'cd /var/www/myfolder && tar xf -' )

But there might be a simpler solution for you. Take ownership of /var/www/myfolder and its current content. Note that it could make your web app unhappy. I don't know. So this is a bit dangerous. Use at your own risks.

sudo chown -hR ${USER}: /var/www/myfolder

Once this is done, you can drag and drop your files with the mouse.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.