One 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)
/
.
..
.*
Path components are separated by forward slashes:
/etc/rc.d/rc.local ../../x/y/z /x/../y/. ⟶ /y
/etc/rc.d/rc.local
../../x/y/z
/x/../y/.
/y
> cat [-n] [<files...>]
> cat [-n] [<
>]
> more [<files...>] > less [<files...>]
> more [<
> less [<
> head [-n <lines>] [<file>]
> head [-n <
>] [<
> tail [-n <lines>] [-f] [<file>]
> tail [-n <
>] [-f] [<
> grep <pattern> [<files...>]
> grep <
> [<
> zcat / zgrep / gzip
> file <file>
> file <
>
The first file-system mounted on the system is the root file-system as is always mounted at /. Drives/partitions are then mapped onto the root file-system or sub mounted file-system at their "mount point" with the mount(8) command. Mounted file-systems are removed using the umount(8) command.
mount
umount
# mount /dev/sda1 /mnt Mounts the device /dev/sda1 at /mnt
# mount /dev/sda1 /mnt
# umount /mnt Removes the file-system mounted at /mnt
# umount /mnt
> df [-h] [-i]
-h
-i
man 7 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 (/) at the beginning of a path means that the path is an absolute path beginning from the root of the file-system (/). If the path does not begin with the a slash then it is a relative path, one that is relative to the current working directory, as if the absolute path of the current working directory were prefixed to the path and then path resolution is performed.
A file is accessible if:
All the parent directories (all the way to the root (/) directory) allow search permissions for that user.
If the user owns the file, the owner permission bits are used to determine access, otherwise if the user is a member of the group of the file, then the group perms are used, otherwise the "other" permissions are used.
man 2 stat
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.
Owner UID (User ID) and GID (Group ID) (unsigned 32 bit integers)
Mode (file permissions bits, shown here in octal):
Mode What Description 4000 setuid Allows the setuid() (change effective user id) system calls to work. setuid() is restricted to the uid of the owner of the file (unrestricted if that owner is uid 0 (i.e. root)) 2000 setgid Allow setgid()/setegid(), same as with setuid above. 1000 sticky bit(t) On directories it sets a restricted delete mode which prevents users from removing/renaming files/dirs not owned by them. Used on /tmp for example. 0x00 Owner bits Permissions used when the user owns the file 00x0 Group bits Permissions used if the user is a group member 000x Other bits Permissions used if neither user or group permissions apply
4000
2000
1000
0x00
00x0
000x
Permission bit values x= 4 read (r) / list files in directory x= 2 write (w) / add/remove entries in a directory x= 1 execute (x) / search (cd into) a directory
r
w
x
Size (bytes and blocks) (32 or 64 bits)
Times (nominally times in seconds since the epoch (Jan 1 1970) (time_t)):
atime Last access time (last time read) mtime Last modification time (last time file modified) ctime Last status change (meta information changed) btime File creation (birth) time. Some file-systems support btime, but is not generally accessible via normal system calls (i.e. only via statx())
atime
mtime
ctime
btime
ls -l
-rw-r--r-- 1 user group 283 Jan 13 18:52 file │╲ ╱╲ ╱╲ ╱ │ │ │ └File┘└────┬─────┘ └─── File-name │ U G O │ └───┬────┘ Size └──────────── Last modified time │ perms │ └────────────────────────────── User and Group owners (user first) │ └──────────────────────────────────── Hard link count └─────────────────────────────────────────────── File type
- 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)
-
d
l
p
c
b
s
?
> chmod [-R] <mode> <file...>
> chmod [-R] <
> <
Set permissions on file or files. has two possible forms, octal or ascii: <[ugoa]+><[+-=]><[rwxts]+> -R = recursively set permissions on all files/directories in a directory.
ugoa
+-=
rwxts
Example: chmod -R u+x,g=r,o-rwx /tmp/foo
chmod -R u+x,g=r,o-rwx /tmp/foo
# chown [-R] <owner>[:<group>] <file...>
# chown [-R] <
>[:<
>] <
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.
getfacl
setfacl
ACL's are composed of a list of tags of the following types:
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
-m
-x
-b
[d:][u:]
[:
]
[d:]g:
[d:]m[:][:
[d:]o[:][:
u
g
o
m
getfacl dir Displays the set ACL's on dir.
getfacl 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 d:u:sbaker:r-x,u:sbaker:r-x dir
setfacl -m default:user:sbaker:r-x,user:sbaker:r-x dir Same as above, but spelled out.
setfacl -m default:user:sbaker:r-x,user:sbaker:r-x dir
setfacl -R -b dir Recursively removes all ACL's on dir and all its contents.
setfacl -R -b dir
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
> ln [-s] <target> [<name>|<directory>]
> ln [-s] <
>|<
-s
> readlink <symbolic link>
> readlink <
> realpath <path>
> realpath <