TL;DR version: Skip to In a nutshell.
This article assumes you understand the notiation for file system permissions, and have a basic grasp on the topic. If not, there is a nice starter article on the Ubuntu community wiki:
By default, when you create a file in Ubuntu as a standard user (either in Nautilus or with touch
), it gets the permission of 644
. If you mark that file as executable, as expected, it gets the permission 755
.
What may be surprising is that directories also have a default permission of 755
. Even though it seems like directories aren’t the type of thing that would be “executed”, this flag is actually very important to Linux! (and if anyone can find an article behind the reasoning behind this decision, I would love to find out)
If a directory (or any of its parent directories) isn’t marked as executable, you cannot cd
into it. Although it is browsable in Nautilus, trying to write anything to the folder results in a “forbidden” or “insufficient privileges” error message. Some commands (like ls
) work on the directory, while others (such as stat
) do not.
Links (both to files and directories) have the permission 777
, which I’m assuming is done for the similar reasons as the executable bit on directories.
On external media
For external harddrives, USB drives, or SD cards that are mounted in /media/<username>
, if you haven’t manually changed either the mount settings or file system format of the drive, the file system type is likely to be either Fat32
or NTFS
. Here, the file permissions are going to be different, with a value of 600
for files and 700
for directories. Links remain the same at 777
, though it is unclear to me if links created in Linux are stored differently or not on foreign file systems.
As far as I can tell, there is no way to change file and directory permissions, or even mark files as being executable without changing the mount settings, so all files are always stuck with a privilege of 600
. This makes sense as such file systems don’t use the same type of permission settings for files, so storing the permission data would be difficult. In fact, I’m just glad we are able read from and write to those types of file systems from Linux at all!
In a nutshell
These are the default values for file permissions in Ubuntu 13.10. They may be the same in other Linux distributions, but I have not been able to verify this personally.
In a standard ext3 file system
644
files755
executable files755
directories777
links to files777
links to directories
For removable media (Fat32) and windows partitions (NTFS)
600
files (can’t be executable)700
directories777
links to files777
links to directories
A script for better displaying file permissions in a directory
While you can display the permissions of files in a directory with ls -l
, that information isn’t very easy to read:
1 2 3 4 5 6 7 8 |
|
Instead, you can instead use the stat
command to display permissions in the more friendly “octal notation” (source):
1 2 3 4 5 6 7 |
|
And if you want to tweak the output further (such as to tell us whether an item is a file, directory, or link), see the following page (or just run man stat
) which lists all available options:
Post a comment
All comments are held for moderation; Markdown and basic HTML formatting accepted.