Unix Files

In Unix everything is a file. Files are files, folders are files, disks are files, your keyboard is a file, your mouth is a file, the air is a file, you can't breathe, your file lungs fill with files and you try to scream but only files come out oh god Dennis how could you do thi

Sy Brand

File Permissions

Permissions have 3 kinds of access:

3 user sets:

These are presented like this in ls:

-rw- --- ---

Directories are the same but are preceeded with a d:

drw- --- ---

Setting file permissions can be done with chmod
- chmod <octal mode> <files> - silly to use this 2023 except in shell scripts, but even then - each group of 3 permission is views a 3 bits of an octal number - 100 r perm - 010 w perm - 001 x perm - chmod <symbolic mode> <files> - chmod <user sets><+|-><perms> <files> - chmod go+r file.txt - may require multiple calls

Input/Output

Unix views all files as characters/bytes, leaving interpretation up to the programs.

Redirection

stdin/stdout/stderr can be redirected to other files - < redirects stdin to file - > redirects stdout to file - >> redirects stdout to append to a file - 2> redirects stderr to file

Piping

stdout/stderr can be redirected to other programs inputs, rather than files using piping.

date | wc

| only applies to stdout, but 2> errors | works equivalently for errors.

Scripts

Scripts are files that contains sets of commands on consecutive lives that can be repeatedly run.

The first line of a script says what interpreter should be used to execute the script.

#!/usr/bin/env bash

Script needs to be made executable

chmod u+x script.sh

From here Bash takes overs.