Files and PathsOne of the Unix philosophies is that everything should present as a "file", including devices, wherever possible. File/directory-names likely limited to 255 characters (depends on file-system being used.) File-names may not contain '/' (the path component separator character) or the null byte('\0') (likely a limitation of the kernel being written in C.) Path length are likely limited to 4096 bytes (depends on file-system)
Examples
Files - Reading and writing:
File-SystemsThe first file-system mounted on the system is the root file-system as is always
mounted at Examples:
Commands:
Path resolution:
Path resolution is the process by which a path-name (a slash separated list of directorys terminating with an optional file name) resolves to a specific file or directory. A slash ( A file is accessible if:
Meta/Inode file information
An inode represents an actual file, its meta data and data. Files in directories merely point to an inode. A file pointer to an inode is a "hard link", and increases the inodes hard link count. When the hard link count drops to zero, the inode (and the file data) is freed. The file information might not actually be deleted, just un-referenced, so it is sometimes possible to recover the deleted data if file-system is immediately unmounted (or set to read-only) and special recovery programs are used to recover the data. Inodes contain the following meta data:
|
- |
Regular file |
d |
Directory |
l |
Symbolic link |
p |
Pipe (FIFO) |
c |
Character Special (typically serial data) |
b |
Block Special (typically disks) |
s |
Socket file (Unix domain sockets) |
? |
Unknown (very bad) |
> chmod [-R] <
mode> <
file...>
Set permissions on file or files. ugoa
]+><[+-=
]><[rwxts
]+>
-R = recursively set permissions on all files/directories in a directory.
Example: chmod -R u+x,g=r,o-rwx /tmp/foo
# chown [-R] <
owner>[:<
group>] <
file...>
chown -R sbaker:users /tmp/foo
> chgrp [-R] <group> <file...>
chgrp -R users /tmp/foo
> touch <file..>
touch foo bar baz
> umask [<octal #>]
umask 022
man 5 acl
Some file-systems may support ACL (Access Control List) permissions which if present on a file supersede the regular permissions.
ACLs are viewed with getfacl
and set with setfacl
.
ACL's are composed of a list of tags of the following types:
ACL_USER_OBJ | Access rights for the file owner. |
ACL_GROUP_OBJ | Access rights for the file group. |
ACL_USER | Access rights for users identified by the entry's qualifier. |
ACL_GROUP | Access rights for groups identified by the entry's qualifier. |
ACL_MASK | The maximum access rights that can be granted by entries of type ACL_USER, ACL_GROUP_OBJ, or ACL_GROUP. |
ACL_OTHER | Access rights for processes that do not match any other entry in the ACL. |
An ACL contains at least one of ACL_USER_OBJ, ACL_GROUP_OBJ and ACL_OTHER,
and zero or more of ACL_USER and ACL_GROUP, if either are present, then
exactly one ACL_MASK tag must also be present.
A default ACL on a directory is inherited by any children created within it.
> getfacl <file>
> setfacl [-m|-x] <acl-list> <file(s)>
-m
= modify
-x
= remove
-b
= remove all ACLs
[d:][u:] uid[: perms] |
Permissions of a named user, or of the file owner if uid is empty. |
[d:]g: gid[: perms] |
Permissions of a named group, or owning group if gid is empty. |
[d:]m[:][: perms] |
Effective rights mask |
[d:]o[:][: perms] |
Permissions of others. |
Where: | |
d |
= default (and may be spelled out as default) |
u |
= user (also may be spelled out as user) |
g |
= group (also may be spelled out) |
o |
= other (also may be spelled out) |
m |
= mask (specifies maximum permissions for other) |
getfacl dir
- Displays the set ACL's on dir.
setfacl -m d:u:sbaker:r-x,u:sbaker:r-x dir
- Sets both a default ACL and user ACL (for sbaker) on the directory dir. Note that there are no spaces in the acl-list.
setfacl -m default:user:sbaker:r-x,user:sbaker:r-x dir
- Same as above, but spelled out.
setfacl -R -b dir
- Recursively removes all ACL's on dir and all its contents.
There are two types of links, hard and symbolic:
Hard linked files are essentially the same file (share the same inode and data), just have different directory entries to the same inode. Hard links cannot cross a mount-point (i.e. they are limited to the same device and file-system) for obvious reasons.
Symbolic links are text values that may or may not point to an existing object.
man 7 symlink
for more about them.> ln [-s] <
target> [<
name>|<
directory>]
-s
for symbolic links.> readlink <
symbolic link>
> realpath <
path>