I wonder why this is a "problem". The directory /root
is the home directory of the root user, and you usually don't need to do anything in it. Accordingly, it has no execute permission for normal users, meaning that you can't enter it or list its contents. These are not things you should change, for security reasons.
Anyway, you can often find some guidance on usage of a command by running
man command
In man ls
you'll find
-d, --directory
list directories themselves, not their contents
Compare the effects:
$ ls /root
ls: cannot open directory '/root': Permission denied
$ sudo !!
sudo ls /root
[sudo] password for zanna:
snap
$ ls -d /root
/root
I need root permission (gained just for one command by running sudo command
) to list out the contents of this directory, but not to list the directory itself. That's because I have execute permission on the parent directory of /root
, /
(often confusingly called the root directory as it is the "root" of the filesystem from which the rest branches off).
The vast majority of directories on your system have read and execute permission for you by default. The /root
directory is rather exceptional in its restrictive permissions.
Also in man ls
is the tool to show the permissions, but it's not at all obvious which one it is there, so you might want to try running info ls
, which shows, in the section explaining what information each option causes to be shown, the documentation for the -l
option:
‘-l’
‘--format=long’
‘--format=verbose’
In addition to the name of each file, print the file type, file
mode bits, number of hard links, owner name, group name, size, and
timestamp (*note Formatting file timestamps::), normally the
modification time. Print question marks for information that
cannot be determined.
This still isn't very clear! Did you know that "file mode bits" means the permissions? The command chmod
is an abbreviation of change mode. Now you know. So let's try the options together. I have annotated the output:
$ ls -dl /root #note that the order of options does not matter here
drwx------ 8 root root 4096 Dec 17 14:06 /root
^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^--file name
| | | | | | | | | | |--last modified time
| | | | | | | | | |--day of month
| | | | | | | | |--name of month *
| | | | | | | |--size
| | | | | | |--group
| | | | | |--owner
| | | | |--number of hard links to this file
| | | |--permission bits for "others" (any user/program)
| | |--permission bits for group
| |--permission bits for owner
|--file type (d=directory)
*Depends on locale settings. If you use a non-English locale you can get English output for any command by running LC_ALL=C ls -dl /root
See the tag wiki for permissions for information on how to interpret the "mode bits". ls -l
displays symbolic notation for the permissions, where r
=read access, w
=write access, x
=executable, and -
indicates no permission. These have different effects for directories and regular files. For directories, read access allows the contents of the directory to be listed if the x
permission bit it also set, the x
bit allows the directory to be entered, and w
allows files within the directory to be deleted, created and renamed if the x
bit is also set. It helps to remember that a directory is a file that stores a list of files - that's why you need write permission on the directory to create, rename or delete its contents - those actions change the list. This permission also allows you to force-write other changes to files inside the directory though.
If we are only interested in owners and permissions, ls -l
gives us too much information. There is a more flexible command to show file metadata; it's stat
. You can use it to list owner (%U
) (u for user - most command line utilities call the owner of a file the user. In chmod
, for example, u=owner and o=others - make sure you don't give permissions to o
when you only want to give them to u
!), group (%G
), and list permissions in octal or symbolic notation:
$ stat -c "%U %G %a" /root
root root 700
$ stat -c "%U %G %A" /root
root root drwx------
See man stat
for many other things stat
can tell you about files.
/root
folder exists as a home directory for the root user (eg a workspace for admin tasks). More info about directories on your system @ https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard – thomasrutter Jan 22 '18 at 01:15