Hey, look, the OP is using Ubuntu, so he should
only be using
sudo, not starting a root session.
That being said, any directory on a Linux system
must be created as a sub-directory of some other directory. The only exception is the root pseudo-directory, /, which is created when the initial RAM file system is started.
In order to create a sub-directory of some directory, you must have write permission to that directory. (You also need read permission to access any file in the directory, and execute permission in order to be able to list the contents of a directory) Generally speaking, if you are trying to create a sub-directory if some directory A, and you are in that directory and denied permission to do so, look at
ls -l ../ where you should see something like this:
Code:
[peter ~]$ ls -l ../
total 8
drwx--x---+ 65 peter peter 4096 Jun 25 09:18 Peter
which tells you that
../ is a directory (the
d at the start of the line), to which the user (
peter) has read, write, and list access (the
rwx following the
d).
If you don't have access, you should see something like this:
Code:
$ ls -dl /
dr-xr-xr-x. 26 root root 4096 Jun 25 09:16 /
Notice that
nobody has write access to the root directory itself, but that anyone can list and read files in it. That's actually somewhat misleading because the root account can actually create a new sub-directory of /. For example:
Code:
[peter ~]$ sudo mkdir /Example
[peter ~]$ ls -dl /Example
drwxr-xr-x. 2 root root 4096 Jun 25 11:05 /Example
but a normal user can't create a new sub-directory of that Example directory:
Code:
[peter ~]$ mkdir /Example/Example1
mkdir: cannot create directory ‘/Example/Example1’: Permission denied
unless the permissions on the directory are changed:
Code:
[peter ~]$ sudo chmod o+rwx /Example
[Peter ~]$ mkdir /Example/Example1
[peter ~]$ ls -l /Example/
total 4
drwxrwxr-x. 2 peter peter 4096 Jun 25 11:12 Example1
Note that the new sub-directory is owned by "peter," not "root," because the was created by "peter."
Note also that the chmod used gives everybody permission to do anything they want to do with the Example directory and any sub-directory under it. A better, but more complicated, choice would have been:
Code:
[peter ~]$ sudo mkdir /Example
[peter ~]$ ls -dl /Example
drwxr-xr-x. 2 root root 4096 Jun 25 11:23 /Example
[peter ~]$ sudo chown root:peter /Example
[peter ~]$ sudo chmod g+rwx /Example
[peter ~]$ ls -dl /Example
drwxrwxr-x. 2 root peter 4096 Jun 25 11:23 /Example
[peter ~]$ mkdir /Example/Example1
[peter ~]$ ls -l /Example/
total 4
drwxrwxr-x. 2 peter peter 4096 Jun 25 11:25 Example1