On who has access to what and a nice hack for dealing with duplicate content
Marek Šuppa
Ondrej Jariabka
Adrián Matejov
You will almost inevitably need to set up your own server environment
Understanding how permissions work will be crucial to you being able to effectively use it
Setting up links here and there will give you a bit of a superpower unheard of on other systems
inode
sinode
, uniquely identified by an IDinode
sThe basic data structure is called an inode
, uniquely identified by an ID
Each inode
contains information about a specific file
inode
sThe basic data structure is called an inode
, uniquely identified by an ID
Each inode
contains information about a specific file
A directory is actually a special file: it contains a list of filenames and pointers to thier inode
s
Image from http://faculty.salina.k-state.edu/tim/unix_sg/advanced/links.html
.txt
)ctime
), modification (mtime
) and access
to content (atime
).txt
)ctime
), modification (mtime
) and access
to content (atime
)Not shown by default in ls
listing
Part of the "long listing format" (i.e. via ls -l
)
$ ls -l /labs/lab06_dist.sh-rwxr-xr-x 1 mrshu mrshu 3402021 Oct 26 15:36 lab06_dist.sh
Not shown by default in ls
listing
Part of the "long listing format" (i.e. via ls -l
)
$ ls -l /labs/lab06_dist.sh-rwxr-xr-x 1 mrshu mrshu 3402021 Oct 26 15:36 lab06_dist.sh
-d
flag (ls
lists directory contents
by default)$ ls -l /labstotal 20264-rwxr-xr-x 1 root root 3389123 Sep 21 13:21 lab01_dist.sh-rwxr-xr-x 1 root root 3428779 Sep 28 14:09 lab02_dist.sh-rwxr-xr-x 1 root root 3644753 Oct 5 14:23 lab03_dist.sh$ ls -l -d /labsdrwxr-xr-x 2 root root 4096 Oct 26 17:01 /labs/
File types:
-
d
c
/ b
p
l
s
Image from https://test-www.ics.uci.edu/computing/linux/file-security.php
r
)w
)x
)Conversion from rwxr-xr--
to octal:
Image from https://danielmiessler.com/study/unixlinux_permissions/
Permissions can be changed with the chmod
command:
chmod {u,g,o,a}{+,-,=}{r,w,x} file
u
ser (owner), g
roup, o
ther and a
ll+
adds, -
removes and =
setsr
ead, w
rite and ex
ecute permissions$ chmod g+rx file.txt$ chmod a-r file.txt$ chmod o=rw file.txt
It also works with numerical (octal) representation:
chmod 750 file
file
to rwxr-x---
# (111 111 111) in binary$ chmod 777 file.txt# (111 100 101) in binary$ chmod 745 file.txt
Maybe also setUID
, setGID
and umask
(in the future)?
Permissions work a bit differently on directories:
read (r
)
write (w
)
execute (x
)
New files/folders are created with the owner's UID and their active/primary group's GID
Only root
can change the owner (via the chown
command)
# Change the owner of file.txt to jane$ chown jane file.txt# Works on directories as well$ chown jane ~/Downloads
Group can be changed by the current group's user's
The user needs to be part of the new group
# Change the group of file.txt to root$ chgrp root file.txt
chmod
$ chown jane:users /home/jane
ls -l
by default shows the mtime
-- last modified time
The other timestamps can be viewed by the stat
utility
$ stat /tmp File: /tmp Size: 3800 Blocks: 0 IO Block: 4096 directoryDevice: 23h/35d Inode: 21596 Links: 129Access: (1777/drwxrwxrwt) Uid: ( 0/ root) Gid: ( 0/ root)Context: system_u:object_r:tmp_t:s0Access: 2020-10-30 13:48:18.249475358 +0100Modify: 2020-11-02 11:05:48.417238277 +0100Change: 2020-11-02 11:05:48.417238277 +0100 Birth: -
The timestamps can be changed with the touch
utility
touch
atime
and mtime
to the current time (by default)-a
: set atime
only-m
: set mtime
only-t STAMP
: use STAMP
instead of current dateSTAMP
is formatted as [[CC]YY]MMDDhhmm[.ss]
$ touch newfile.txt$ touch -a newfile.txt# STAMP format: [[CC]YY]MMDDhhmm[.ss]# Everything in [] is optional## MM == 11# DD == 02# hh == 10# mm == 10$ touch -m -t 11021010 newfile.txt
It makes little sense to copy the same contents multiple times over (what if it changes?)
The solution is called links
Image from https://www.computerhope.com/unix/uln.htm
Notice how the "directory contents" file has entries for both itself (.
) and its parent directory (..
)
Since it can contain arbitrary filenames which point to arbitrary inode
IDs, this can be used for simple implementation of links
Different filenames (or even paths) link to the same inode
ID
The attributes as well as contents stay exactly the same
Only possible within a single data device (disk)
inode
ID of a file can be viewed with ls -i
inode
counts the number of links that point to it
When nothing does, the inode
gets "physically" removed as well
$ echo "This is a file." > file1.txt$ ls -l -i file1.txt136158 -rw-rw-r-- 1 mrshu mrshu 16 Nov 2 11:20 file1.txt# Create a hardlink called file2.txt from file1.txt$ ln file1.txt file2.txt# The hardlink count has increased$ ls -l -i file2.txt 136158 -rw-rw-r-- 2 mrshu mrshu 16 Nov 2 11:20 file2.txt$ cat file1.txtThis is a file.$ cat file2.txtThis is a file.
A "standard shortcut"
When the source file gets removed, the symbolic link continues to live
It is not counted among the hardlinks (e.g. in ls -l
output)
Can be created across the whole filesystem (not just one data device)
Hardlink
Symlink
Images from https://www.computerhope.com/unix/uln.htm
$ echo "This is a file." > file1.txt$ ls -l file1.txt 136158 -rw-rw-r-- 1 mrshu mrshu 16 Nov 2 11:44 file1.txt# Create a symlink called file2.txt pointing to file1.txt$ ln -s file1.txt file2.txt# The hardlink count has not increased$ ls -l -i file2.txt 136159 lrwxrwxrwx 1 mrshu mrshu 9 Nov 2 11:45 file2.txt -> file1.txt$ ls -l -i file1.txt 136158 -rw-rw-r-- 1 mrshu mrshu 16 Nov 2 11:44 file1.txt$ cat file1.txtThis is a file.$ cat file2.txtThis is a file.# Link to the parent directory$ mkdir dir$ cd dir$ ln -s ../file1.txt file3.txt$ ls -l -i file3.txt 393489 lrwxrwxrwx 1 mrshu mrshu 12 Nov 2 11:48 file3.txt -> ../file1.txt
For checking and changing file encoding
file
A useful command for checking the file type (e.g. is it an image, video or a text file).
file filename
-b
simplified output-i
output as a mime type$ file image.jpgimage.jpg: JPEG image data, JFIF standard 1.01, resolution (DPI), density 72x72,segment length 16, progressive, precision 8, 317x191, components 3$ file -bi image.jpgimage/jpeg; charset=binary$ file index.htmlindex.html: HTML document, UTF-8 Unicode text, with very long lines$ file -i index.htmlindex.html: text/html; charset=utf-8
iconv
Convert text form one character encoding to another
iconv -f [encoding] -t [encoding] -o [outputfile] [inputfile]
-f [encoding]
: convert encoding from this charset-t [encoding]
: convert encoding to this charset-o [outputfile]
: save output to this file (stdout by default)$ file -bi file_iso.txt text/plain; charset=iso-8859-1$ iconv -f iso-8859-1 -t utf-8 -o file_utf8.txt file_iso.txt$ file -bi file_utf8.txttext/plain; charset=utf-8
You will almost inevitably need to set up your own server environment
Understanding how permissions work will be crucial to you being able to effectively use it
Setting up links here and there will give you a bit of a superpower unheard of on other systems
Keyboard shortcuts
↑, ←, Pg Up, k | Go to previous slide |
↓, →, Pg Dn, Space, j | Go to next slide |
Home | Go to first slide |
End | Go to last slide |
Number + Return | Go to specific slide |
b / m / f | Toggle blackout / mirrored / fullscreen mode |
c | Clone slideshow |
p | Toggle presenter mode |
t | Restart the presentation timer |
?, h | Toggle this help |
Esc | Back to slideshow |