CT320: Network and System Administration

Fall 2018

Filesystem

See this page as a slide show

CT320 Filesystem

Original slides from Dr. James Walden at Northern Kentucky University.

Topics

  1. Overview
  2. Pathnames
  3. Mounting
  4. Structure
  5. Organization
  6. File types
  7. Kernel Data Structures

Overview

Filesystem Components

Filesystem Types

https://en.wikipedia.org/wiki/Comparison_of_file_systems

Hierarchy

Files are located by traversing a directory tree:

Linux filesystem is a single unified hierarchy, unlike Windows.

Filenames

Characters in Filenames

Really, anything?

$ touch now then

$ date >n*

$ id >'~!#$^&*\ ([{<>}])|;'\''`":,.?½→☂ 🐟 ψάρι سمك मछली 鱼'

$ ls -lhog
total 8.0K
-rw------- 1 29 Jan 23 04:33 now
-rw------- 1  0 Jan 23 04:33 then
-rw------- 1 51 Jan 23 04:33 ~!#$^&*\ ([{<>}])|;'`":,.?½→☂ 🐟 ψάρι سمك मछली 鱼

Anything‽

$ date >-z
$ ls -l
total 4
-rw------- 1 ct320 class 29 Jan 23 04:33 -z

$ rm -z
rm: invalid option -- 'z'
Try 'rm ./-z' to remove the file '-z'.
Try 'rm --help' for more information.

$ rm '-z'
rm: invalid option -- 'z'
Try 'rm ./-z' to remove the file '-z'.
Try 'rm --help' for more information.

$ rm ./-z

$ rm -- -z
rm: cannot remove '-z': No such file or directory

Mounted Filesystems

Global filesystem contains mounted filesystems:

Mounting

Unmounting

fuser

CodeMeaning
ffile open for reading
Ffile open for writing
ccurrent working directory
eexecuting a file
rroot directory (chroot)
mmapped file or shared library
$ PATH=/bin:/usr/bin:/sbin:/usr/sbin

$ pwd
/tmp/PmWiki-tmp
$ fuser -v .
                     USER        PID ACCESS COMMAND
/tmp/PmWiki-tmp:     ct320     25649 ..c.. php-cgi
                     ct320     25682 ..c.. bash

$ sleep 10 </etc/group &
$ fuser -v /etc/group
                     USER        PID ACCESS COMMAND
/etc/group:          ct320     25690 f.... sleep
$ kill %%

.script: line 2: 25690 Terminated              sleep 10 < /etc/group
$ echo "My PID is $$"
My PID is 25682
$ fuser -v /bin/bash
                     USER        PID ACCESS COMMAND
/usr/bin/bash:       ct320     25682 ...e. bash

Filesystem Structure

Examples

$ ls -l /etc/passwd
-rw-r--r-- 1 root root 4101 Nov  9 15:16 /etc/passwd

$ ls -i /etc/passwd
530603 /etc/passwd

$ stat /etc/passwd
  File: '/etc/passwd'
  Size: 4101      	Blocks: 16         IO Block: 4096   regular file
Device: 803h/2051d	Inode: 530603      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2019-01-22 15:19:10.010602088 -0700
Modify: 2018-11-09 15:16:48.107481099 -0700
Change: 2018-11-09 15:16:48.107481099 -0700
 Birth: -

inode

times

inode block pointers

A classic inode has thirteen pointers:

Some filesystems optimize the storage of tiny files by storing the data itself in the inode.

Filesystem Organization

Standard directories

DirectoryMeaningDirectoryMeaning
/bootBoot directory/usrMost standard programs
/devDevice files/varSpool directories
/etcCritical system files/homeMount point for users
/sbinSystem utilities/libLibs and parts of the C compiler
/binImportant utilities/mediaRemovable media
/tmpTemp files/optOptional applications

Standard directories

/usr/binMost commands and executables
/usr/includeHeader files
/usr/libLibraries, support files for standard programs
/usr/localLocal software
/usr/local/binLocal executables
/usr/local/Other local (etc, lib, sbin, src)

Standard directories

/usr/manMan pages
/usr/sbinLess essential sysadmin commands
/usr/shareCommon to multiple systems
/usr/share/manShared man pages
/usr/srcSource code for nonlocal packages

Standard directories

/var/admLogs, system setup records
/var/logSystem log files
/var/spoolSpooling directories (mail, printers)
/var/tmpMore temp space (preserved between boots)

File types

$ ls -l /dev/console /dev/log /dev/sda
crw------- 1 root root 5, 1 Jan 15 18:13 /dev/console
srw-rw-rw- 1 root root    0 Jan 15 18:13 /dev/log
brw-rw---- 1 root disk 8, 0 Jan 23 02:45 /dev/sda

File type encoding

File typeSymbolCreated byRemoved by
Regular file-cp, mv, virm
Directorydmkdir, cp -rrmdir, rm -r
Character device filecmknodrm
Block device filebmknodrm
Local domain socketssocket(2)rm
Named pipepmknodrm
Symbolic linklln -srm

Examples

$ ls -ldU /bin/cat /etc/magic /tmp /dev/random /dev/sda /dev/gpmctl /bin/cc
-rwxr-xr-x 1 root root 54160 Jun 15  2018 /bin/cat
-rw-r--r-- 1 root root   111 Jun  6  2018 /etc/magic
drwxrwxrwt 4 root root   700 Jan 23 04:33 /tmp
crw-rw-rw- 1 root root  1, 8 Jan 15 18:13 /dev/random
brw-rw---- 1 root disk  8, 0 Jan 23 02:45 /dev/sda
srwxrwxrwx 1 root root     0 Jan 15 18:13 /dev/gpmctl
lrwxrwxrwx 1 root root     3 Nov  9 15:15 /bin/cc -> gcc

Regular file

Directories

Character and Block Device files

$ ls -l /dev/cdrom
lrwxrwxrwx 1 root root 3 Jan 15 18:13 /dev/cdrom -> sr0
$ ls -lH /dev/cdrom
brw-rw----+ 1 root cdrom 11, 0 Jan 15 18:13 /dev/cdrom

Some Device Files

NameDescription
/dev/sda2disk
/dev/ttyS0RS-232 serial line
/dev/pts/1Pseudo-tty (pty)
/dev/ttyAn alias for your terminal
/dev/nullRead fails, write succeeds
/dev/fullRead succeeds, write fails
/dev/zeroRead yields zeroes
/dev/randomRead yields random data

Local domain sockets

Named Pipes

Communication mechanisms

Symbolic links

Symbolic link example

$ date >now
$ ln -s now foo
$ ls -l
total 4
lrwxrwxrwx 1 ct320 class  3 Jan 23 04:33 foo -> now
-rw------- 1 ct320 class 29 Jan 23 04:33 now
$ cat now foo
Wed Jan 23 04:33:35 MST 2019
Wed Jan 23 04:33:35 MST 2019
$ echo "I am $USER" >foo
$ ls -l
total 4
lrwxrwxrwx 1 ct320 class  3 Jan 23 04:33 foo -> now
-rw------- 1 ct320 class 11 Jan 23 04:33 now
$ cat now foo
I am ct320
I am ct320
$ rm now
$ cat foo
cat: foo: No such file or directory

Hard Links

Hard/Soft Link Differences

Hard Link Analogy

Soft Link Analogy

User: Guest

Check: HTML CSS
Edit History Source

Modified: 2018-10-06T13:35

Apply to CSU | Contact CSU | Disclaimer | Equal Opportunity
Colorado State University, Fort Collins, CO 80523 USA
© 2018 Colorado State University
CS Building