K Research
Posts: 77
Joined: Wed Jun 19, 2019 12:45 am

Move Directory?

Thu Jan 16, 2020 5:28 am

What is the command to move a directory with files from Downloads to /var/www ?

Cant drag and drop because of the permissions thing that I will never understand... same with mv --help tried over 40 different combinations all returned some sort of error that makes no sense to me.

Guess it would make too much sense to just asking for the root password when you drag and drop the files and if you dont know the pass then start with the cryptic errors I can never resolve myself.

Thanks in advance.

klricks
Posts: 7288
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: Move Directory?

Thu Jan 16, 2020 6:03 am

You must have root privileges to move files that are not in the logged in users /home directory.
If you want to use filemanager for this then you need to start filemanager from terminal command line using sudo:

Code: Select all

sudo pcmanfm
Unless specified otherwise my response is based on the latest and fully updated RPiOS Buster w/ Desktop OS.

GlowInTheDark
Posts: 1068
Joined: Sat Nov 09, 2019 12:14 pm

Re: Move Directory?

Thu Jan 16, 2020 7:02 am

I suppose the easy way is:

$ sudo bash
# cd Downloads
# mv foo_DIR /var/www
# exit
$
GitD's list of things that are not ready for prime time:
1) IPv6
2) 64 bit OSes
3) USB 3
4) Bluetooth

Loves Linux; loves to dance.

User avatar
rpdom
Posts: 17712
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Move Directory?

Thu Jan 16, 2020 7:06 am

GlowInTheDark wrote:
Thu Jan 16, 2020 7:02 am
I suppose the easy way is:

$ sudo bash
# cd Downloads
# mv foo_DIR /var/www
# exit
$
No, that's the long winded way.

The easy way would be:

sudo mv Downloads/foo /var/www

or add the user to the www-data group and they should have permissions to move/copy the files there anyway without needing sudo.
Unreadable squiggle

User avatar
jojopi
Posts: 3353
Joined: Tue Oct 11, 2011 8:38 pm

Re: Move Directory?

Thu Jan 16, 2020 2:58 pm

rpdom wrote:
Thu Jan 16, 2020 7:06 am
or add the user to the www-data group and they should have permissions to move/copy the files there anyway without needing sudo.
No. By default, /var/www/ is only writable by root.

This is a rare case where the default permissions are wrong, of course. The Debian developers cannot know which users on your system should have what access to whatever files you might place in there. You need to set the permissions yourself.

Allowing write access for the www-data group is not the best choice, because the web server itself is in that group. You do not want the web server to be able to modify the files it is serving, in most cases. Any security flaw would then allow attackers to insert embarrassing messages.
K Research wrote:
Thu Jan 16, 2020 5:28 am
Guess it would make too much sense to just asking for the root password when you drag and drop the files
That is a nice idea, but it is only addressing the issue of whether the user is trusted. That is one small part of why we have permissions.

When you drag files from /home/pi to /var/www, do you want them to remain owned by pi; become owned by root because you needed to be root to do it; or become the property of the web server (as I stated above, generally not a good idea)? You cannot expect a GUI tool to magically do the right thing, even when the user admits to not understanding the permissions model.

Without knowing anything more about your situation, I am going to suggest that your user, presumably "pi", takes full and sole control of /var/www. That might not be the best possible solution for you, but it is safe, and it allows you to use GUI tools both for moving and editing the served files.

Code: Select all

sudo chown -R pi:pi /var/www
Be careful when typing the command, and do not think that you can apply it to other directories that you would like to have control of. "sudo chown -R" can be exceptionally destructive if you do not understand the purpose of the existing permissions.

K Research
Posts: 77
Joined: Wed Jun 19, 2019 12:45 am

Re: Move Directory?

Thu Jan 16, 2020 4:14 pm

rpdom wrote:
Thu Jan 16, 2020 7:06 am
GlowInTheDark wrote:
Thu Jan 16, 2020 7:02 am
I suppose the easy way is:

$ sudo bash
# cd Downloads
# mv foo_DIR /var/www
# exit
$
No, that's the long winded way.

The easy way would be:

sudo mv Downloads/foo /var/www

or add the user to the www-data group and they should have permissions to move/copy the files there anyway without needing sudo.
Fail
mv: missing destination file operand after bla bla bla
Try mv --help for more information

mv --help might as well be written in Chinese GOD FORBID the Genius who wrote the help would use more than one or to words to help someone resolve a problem.

I have tried the --help thing dozens of times and --help was NO help 100% of the time.

Hint to the Professors writing the --help in Linux based systems if someone is typing --help they have NO CLUE if they knew what they were doing they would never have seen the ERROR in the first place so you need to write your --help documentation in Dummies language and not use shorthand!



Thanks

K Research
Posts: 77
Joined: Wed Jun 19, 2019 12:45 am

Re: Move Directory?

Thu Jan 16, 2020 4:29 pm

klricks wrote:
Thu Jan 16, 2020 6:03 am
You must have root privileges to move files that are not in the logged in users /home directory.
If you want to use filemanager for this then you need to start filemanager from terminal command line using sudo:

Code: Select all

sudo pcmanfm
The sudo pcmanfm command allowed me to copy the directory containing files from Downloads to var/www how ever will not allow me to copy the file index.html from var/www/html to var/www/Test

Thanks

User avatar
rpdom
Posts: 17712
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Move Directory?

Thu Jan 16, 2020 5:02 pm

K Research wrote:
Thu Jan 16, 2020 4:14 pm
rpdom wrote:
Thu Jan 16, 2020 7:06 am
GlowInTheDark wrote:
Thu Jan 16, 2020 7:02 am
I suppose the easy way is:

$ sudo bash
# cd Downloads
# mv foo_DIR /var/www
# exit
$
No, that's the long winded way.

The easy way would be:

sudo mv Downloads/foo /var/www

or add the user to the www-data group and they should have permissions to move/copy the files there anyway without needing sudo.
Fail
mv: missing destination file operand after bla bla bla
Try mv --help for more information

mv --help might as well be written in Chinese GOD FORBID the Genius who wrote the help would use more than one or to words to help someone resolve a problem.

I have tried the --help thing dozens of times and --help was NO help 100% of the time.

Hint to the Professors writing the --help in Linux based systems if someone is typing --help they have NO CLUE if they knew what they were doing they would never have seen the ERROR in the first place so you need to write your --help documentation in Dummies language and not use shorthand!



Thanks
Post the EXACT full command that you are using and the EXACT full error message, otherwise we have to work by guesswork.
Unreadable squiggle

K Research
Posts: 77
Joined: Wed Jun 19, 2019 12:45 am

Re: Move Directory?

Thu Jan 16, 2020 5:47 pm

K Research wrote:
Thu Jan 16, 2020 4:14 pm
rpdom wrote:
Thu Jan 16, 2020 7:06 am
GlowInTheDark wrote:
Thu Jan 16, 2020 7:02 am
I suppose the easy way is:

$ sudo bash
# cd Downloads
# mv foo_DIR /var/www
# exit
$
No, that's the long winded way.

The easy way would be:

sudo mv Downloads/foo /var/www

or add the user to the www-data group and they should have permissions to move/copy the files there anyway without needing sudo.
Fail
mv: missing destination file operand after bla bla bla
Try mv --help for more information

mv --help might as well be written in Chinese GOD FORBID the Genius who wrote the help would use more than one or to words to help someone resolve a problem.

I have tried the --help thing dozens of times and --help was NO help 100% of the time.

Hint to the Professors writing the --help in Linux based systems if someone is typing --help they have NO CLUE if they knew what they were doing they would never have seen the ERROR in the first place so you need to write your --help documentation in Dummies language and not use shorthand!



Thanks
After searching around the web for the error I found out there needs to be a space before the /var/www I inserted the space and it moved the directory and contents to /var/www how ever when I go to localhost/foo/index.php I am getting the Not Found error index.php under www works so I know the server is working, this a permissions thing for the foo folder and its contents?

Thanks.

User avatar
jahboater
Posts: 6281
Joined: Wed Feb 04, 2015 6:38 pm
Location: Wonderful West Dorset

Re: Move Directory?

Thu Jan 16, 2020 5:53 pm

K Research wrote:
Thu Jan 16, 2020 5:47 pm
After searching around the web for the error I found out there needs to be a space before the /var/www I inserted the space and it moved the directory and contents to /var/www
The thing is, how does it know that "Downloads/foo/var/www" is in fact two directories???
Looks just like one long path to me and to the mv command.

Common sense should indicate that you must separate the two arguments somehow: "Downloads/foo /var/www", so there is no point in the help authors patiently explaining it - every time!

User avatar
rpdom
Posts: 17712
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Move Directory?

Thu Jan 16, 2020 7:52 pm

If you are using Apache2 in Raspbian the web base directory is /var/www/html now, rather than /var/www.
Unreadable squiggle

K Research
Posts: 77
Joined: Wed Jun 19, 2019 12:45 am

Re: Move Directory?

Thu Jan 16, 2020 11:54 pm

jahboater wrote:
Thu Jan 16, 2020 5:53 pm
K Research wrote:
Thu Jan 16, 2020 5:47 pm
After searching around the web for the error I found out there needs to be a space before the /var/www I inserted the space and it moved the directory and contents to /var/www
The thing is, how does it know that "Downloads/foo/var/www" is in fact two directories???
Looks just like one long path to me and to the mv command.

Common sense should indicate that you must separate the two arguments somehow: "Downloads/foo /var/www", so there is no point in the help authors patiently explaining it - every time!
Commonsense? I have no clue about "arguments" what they are what they mean or how they apply to this conversation.

When I read the instructions it looked like one long line to me with NO SPACES who knows maybe your fonts screen size monitor size etc. makes spaces look obvious there is a extra space I am not use to looking at code or lines of text and special charterers, I have spent hours researching problems in the past only to find out the person who wrote the tutorial put a PERIOD at the end of the command I was suppose to cut and paste looked like part of the command to me.

Thanks

GlowInTheDark
Posts: 1068
Joined: Sat Nov 09, 2019 12:14 pm

Re: Move Directory?

Fri Jan 17, 2020 12:01 am

Sounds like you need to get basic book on Unix and shell basics. It will explain a lot of basic stuff that a lot of us just take for granted.

Or, you need to stick exclusively to GUI tools, such as the file manager.

No offense meant, of course.
GitD's list of things that are not ready for prime time:
1) IPv6
2) 64 bit OSes
3) USB 3
4) Bluetooth

Loves Linux; loves to dance.

K Research
Posts: 77
Joined: Wed Jun 19, 2019 12:45 am

Re: Move Directory?

Fri Jan 17, 2020 1:31 am

GlowInTheDark wrote:
Fri Jan 17, 2020 12:01 am
Sounds like you need to get basic book on Unix and shell basics. It will explain a lot of basic stuff that a lot of us just take for granted.

Or, you need to stick exclusively to GUI tools, such as the file manager.

No offense meant, of course.


Right spend another day researching to setup an application then not use those skills for another few years, or simply find a tutorial that works?

I am use to following written procedres while having simutainus peer checking to ensure work performed as intended and is error free, peocedure writers are peer checked about a dozen times for each work step to ensure the work step is correct and can be performed as witten 100% of the time without exception, sure glad the authors of tutorias I encountered are not procedure writers at necular power plants we would be witnessing catistrophic meltdowns on a regular basis...

Have a few spare moments try this https://www.uniformserver.com/ why it cant be this simple on a Linux system .

No offense taken.

Thanks

User avatar
jahboater
Posts: 6281
Joined: Wed Feb 04, 2015 6:38 pm
Location: Wonderful West Dorset

Re: Move Directory?

Fri Jan 17, 2020 1:45 am

Its actually nothing to do with Linux.
Any system that supports a command line, including Windows and MacOS, will be exactly the same.

GlowInTheDark
Posts: 1068
Joined: Sat Nov 09, 2019 12:14 pm

Re: Move Directory?

Fri Jan 17, 2020 2:27 am

jahboater wrote:
Fri Jan 17, 2020 1:45 am
Its actually nothing to do with Linux.
Any system that supports a command line, including Windows and MacOS, will be exactly the same.
Yeah, but both Windows and MacOS are (like Linux) based on Unix.

(Again: Nitpickers: Don't bother...)
GitD's list of things that are not ready for prime time:
1) IPv6
2) 64 bit OSes
3) USB 3
4) Bluetooth

Loves Linux; loves to dance.

swampdog
Posts: 414
Joined: Fri Dec 04, 2015 11:22 am

Re: Move Directory?

Sat Jan 18, 2020 5:16 pm

K Research wrote:
Thu Jan 16, 2020 11:54 pm
jahboater wrote:
Thu Jan 16, 2020 5:53 pm
K Research wrote:
Thu Jan 16, 2020 5:47 pm
After searching around the web for the error I found out there needs to be a space before the /var/www I inserted the space and it moved the directory and contents to /var/www
The thing is, how does it know that "Downloads/foo/var/www" is in fact two directories???
Looks just like one long path to me and to the mv command.

Common sense should indicate that you must separate the two arguments somehow: "Downloads/foo /var/www", so there is no point in the help authors patiently explaining it - every time!
Commonsense? I have no clue about "arguments" what they are what they mean or how they apply to this conversation.

When I read the instructions it looked like one long line to me with NO SPACES who knows maybe your fonts screen size monitor size etc. makes spaces look obvious there is a extra space I am not use to looking at code or lines of text and special charterers, I have spent hours researching problems in the past only to find out the person who wrote the tutorial put a PERIOD at the end of the command I was suppose to cut and paste looked like part of the command to me.

Thanks
Open an editor which uses a mono-space font and paste into that. You'll see spaces.

I'm afraid you'll need to learn some basics else you'll be unable to do anything. Take this for instance..

Code: Select all

$ cat `which dfh`
#!/bin/bash

df -hP | \
 egrep "(^/dev/|:/)" | \
 sed -e 's,^/dev/mapper/,,' | \
 sed -e 's,^/dev/,,' | \
 column -t | \
 sort
..is enough to inform any linux user with a bit of knowledge exactly what the above does. I don't even need to explain it. This is the same thing..

Code: Select all

foo@pi18:/wrk $ cat /usr/local/sd/bin/dfh
#!/bin/bash

df -hP | \
 egrep "(^/dev/|:/)" | \
 sed -e 's,^/dev/mapper/,,' | \
 sed -e 's,^/dev/,,' | \
 column -t | \
 sort
..but you will never know that without taking a bit of time to learn the basics. It really is worth the time so you don't waste hours in the future.

Time to get out that monospace editor so things line up..

Code: Select all

df -hP | \
^^(1)
   ^^^(2)
       ^(3)
         ^(4)

 egrep "(^/dev/|:/)" | \
       ^---(5)-----^
 sed -e 's,^/dev/mapper/,,' | \
        ^--------(5)------^
 sed -e 's,^/dev/,,' | \
 column -t | \
 sort

(1) command
(2) switch (argument)
(3) pipe
(4) line continuation
(5) quote (delimits single argument)
Now you know the 'df' command is used with switches "-hP". That output is sent to 'egrep' command which has a single "(^/dev/|:/)" argument. Whatever that does is then sent to the 'sed' command with switch argument "-e" and argument "'s,^/dev/mapper/,,'". Whatever that does is sent to the next 'sed' command with switch argument "-e" but with argument "'s,^/dev/,,'". Whatever that does is sent to 'column' command with switch "-t" and finally whatever is happening at this point is sent to 'sort' command which has no arguments.

It could have been written..

Code: Select all

df -hP | egrep "(^/dev/|:/)" | sed -e 's,^/dev/mapper/,,' | sed -e 's,^/dev/,,' | column -t | sort
..(no line continuation(4) but that makes for very long lines). Nobody is expecting you to understand the above example, just to be able to break it into parts.

eg:

Code: Select all

/usr/bin/install -c -m 644 ./libitm.info '/home/foo/usr/src/pi/xgcc/out/share/info'
Doesn't matter what the above does, just that "/usr/bin/install" is the command and it takes four arguments: "-c", "-m 644", "/libitm.info" and "'/home/foo/usr/src/pi/xgcc/out/share/info'".

User avatar
dickon
Posts: 1804
Joined: Sun Dec 09, 2012 3:54 pm
Location: Home, just outside Reading

Re: Move Directory?

Sat Jan 18, 2020 7:37 pm

swampdog wrote:
Sat Jan 18, 2020 5:16 pm

Code: Select all

/usr/bin/install -c -m 644 ./libitm.info '/home/foo/usr/src/pi/xgcc/out/share/info'
Doesn't matter what the above does, just that "/usr/bin/install" is the command and it takes four arguments: "-c", "-m 644", "/libitm.info" and "'/home/foo/usr/src/pi/xgcc/out/share/info'".
No, five. '-c', '-m', '644', './libitm.info' and '/home/foo/usr/src/pi/xgcc/out/share/info'. It'd be '-m\ 644' or the like for it to be four. This isn't nitpicking: getting it wrong will only muddy the waters for a newbie.

swampdog
Posts: 414
Joined: Fri Dec 04, 2015 11:22 am

Re: Move Directory?

Sun Jan 19, 2020 2:11 am

dickon wrote:
Sat Jan 18, 2020 7:37 pm
swampdog wrote:
Sat Jan 18, 2020 5:16 pm

Code: Select all

/usr/bin/install -c -m 644 ./libitm.info '/home/foo/usr/src/pi/xgcc/out/share/info'
Doesn't matter what the above does, just that "/usr/bin/install" is the command and it takes four arguments: "-c", "-m 644", "/libitm.info" and "'/home/foo/usr/src/pi/xgcc/out/share/info'".
No, five. '-c', '-m', '644', './libitm.info' and '/home/foo/usr/src/pi/xgcc/out/share/info'. It'd be '-m\ 644' or the like for it to be four. This isn't nitpicking: getting it wrong will only muddy the waters for a newbie.
Unfortunately I was hoping to avoid this. It depends on which context you're coming from. From the program point of view (aka argv[]) then yes it's five but from a human point of view it's four because switch "-m" requires the next argv[] argument. We could get bogged down debating this but in essence there is no definition for the word "argument". I didn't think pointing the OP at (say) BNF https://en.wikipedia.org/wiki/Syntax_diagram (in case they are interested) would be helpful. :-)

GlowInTheDark
Posts: 1068
Joined: Sat Nov 09, 2019 12:14 pm

Re: Move Directory?

Sun Jan 19, 2020 3:23 am

dickon wrote:
Sat Jan 18, 2020 7:37 pm
swampdog wrote:
Sat Jan 18, 2020 5:16 pm

Code: Select all

/usr/bin/install -c -m 644 ./libitm.info '/home/foo/usr/src/pi/xgcc/out/share/info'
Doesn't matter what the above does, just that "/usr/bin/install" is the command and it takes four arguments: "-c", "-m 644", "/libitm.info" and "'/home/foo/usr/src/pi/xgcc/out/share/info'".
No, five. '-c', '-m', '644', './libitm.info' and '/home/foo/usr/src/pi/xgcc/out/share/info'. It'd be '-m\ 644' or the like for it to be four. This isn't nitpicking: getting it wrong will only muddy the waters for a newbie.
Actually, the right answer is 6, since there are 6 pieces in the above command line and, in fact, both of the following are true:
1) argv will have 6 elements (numbered 0 through 5)
2) argc will be 6
GitD's list of things that are not ready for prime time:
1) IPv6
2) 64 bit OSes
3) USB 3
4) Bluetooth

Loves Linux; loves to dance.

User avatar
jahboater
Posts: 6281
Joined: Wed Feb 04, 2015 6:38 pm
Location: Wonderful West Dorset

Re: Move Directory?

Sun Jan 19, 2020 3:57 am

argv[0] is not an argument.
So it is five arguments.
As far as the shell is concerned.
Pi4 8GB running PIOS64 Lite

GlowInTheDark
Posts: 1068
Joined: Sat Nov 09, 2019 12:14 pm

Re: Move Directory?

Sun Jan 19, 2020 4:08 am

From the point of view of ld.so, argv[0] is the most important argument of all.

But you're right, the shell will report $# = 5, even though in C, argc = 6.

P.S. Great sig quote!
GitD's list of things that are not ready for prime time:
1) IPv6
2) 64 bit OSes
3) USB 3
4) Bluetooth

Loves Linux; loves to dance.

User avatar
dickon
Posts: 1804
Joined: Sun Dec 09, 2012 3:54 pm
Location: Home, just outside Reading

Re: Move Directory?

Sun Jan 19, 2020 11:27 am

swampdog wrote:
Sun Jan 19, 2020 2:11 am
Unfortunately I was hoping to avoid this. It depends on which context you're coming from.
No. It doesn't.
From the program point of view (aka argv[]) then yes it's five but from a human point of view it's four
No.
because switch "-m" requires the next argv[] argument.
That an argument requires another argument is utterly irrelevant. It is five arguments, not four.
We could get bogged down debating this but in essence there is no definition for the word "argument". I didn't think pointing the OP at (say) BNF https://en.wikipedia.org/wiki/Syntax_diagram (in case they are interested) would be helpful. :-)
It really doesn't matter. '-m 644' is very much not a single argument. It's two: '-m', and '644'. Otherwise you may as well assert that it's actually two arguments in total, '-c', and '-m 644', because install takes a source and destination anyway. That's obviously bogus.

User avatar
dickon
Posts: 1804
Joined: Sun Dec 09, 2012 3:54 pm
Location: Home, just outside Reading

Re: Move Directory?

Sun Jan 19, 2020 11:40 am

GlowInTheDark wrote:
Sun Jan 19, 2020 4:08 am
From the point of view of ld.so, argv[0] is the most important argument of all.
Not really. The first argument to exec*() is the bit that's run, and that doesn't make it as far as argv[0]...

There's a fairly common idiom:

Code: Select all

char args[];
args[0] = "/usr/bin/foo";
args[1] = "first arg";
args[2] = "second";
[...]
args[n] = NULL;
execv(args[0], args);
which sets argv[0] to be the name of the binary that's run, but it isn't required. There's nothing stopping you replacing argv[0] with whatever you wish, and anything which doesn't check what it's called will run happily anyway. You can test this with, eg., busybox:

Code: Select all

execl("/usr/bin/busybox", "ls", "/bin");
will do something very different to

Code: Select all

execl("/usr/bin/busybox", "cat", "/etc/issue");
for example, but this is all hidden at the shell level anyway.

GlowInTheDark
Posts: 1068
Joined: Sat Nov 09, 2019 12:14 pm

Re: Move Directory?

Sun Jan 19, 2020 12:08 pm

Again, talking to the hand.
GitD's list of things that are not ready for prime time:
1) IPv6
2) 64 bit OSes
3) USB 3
4) Bluetooth

Loves Linux; loves to dance.

Return to “Raspberry Pi OS”