CS469 - Linux and Unix Administration and Networking

Filesystem Hierarchy Standard (FHS / originally FSSTND)

  • A standard that defines the layout of the Unix filesystem
  • Current version 2.3 (http://www.pathname.com/fhs/)
  • Maintained by the Linux Foundation
  • FILES section of man pages will usually note the file locations of things relavent to the program.

File-system layout

  • Reading: man 7 hier


  • Binaries needed before a /usr is mounted (single user mode).


  • Kernels / boot loader files


  • Device files


  • System-wide configuration files.


  • Slackware init scripts


  • X windows system configuration files.


  • Typically user home directories

/lib, /lib64

  • System libraries (essential for binaries in /bin, /sbin)


  • Spare, usually temporary mount points, usually for removable media (/media)


  • Optional local packages


  • System & process information virtual pseudo-file-system (man 5 proc)


  • The super-users home directory


  • System runtime files


  • System (admin) binaries needed before /usr is mounted


  • Files served by the system (e.g. web service)


  • System information pseudo-filesystem


  • System wide temporary files, not guaranteed to be preserved between reboots


  • Read-only data, historically a secondary hierarchy to be mounted after '/', so binaries / data that might not be available during boot.


  • User binaries, not needed at boot.


  • Standard include libraries (C, C++)


  • Libraries (for binaries in /usr/bin, /usr/sbin)


  • A tertiary hierarchy for local system additions


  • Non-essential system binaries (e.g. daemons)


  • Shared data


  • Source code (e.g. kernel source)


  • X windows (Version 11, release 6)


  • Variable files, files that will likely change during run-time.


  • Application cache data.


  • State information generated by programs such as databases and package managers


  • Lock files


  • log files (syslogd, klogd, httpd, other daemons)


  • Slackware package database


  • Slackware setup/configuration scripts


  • User mailboxes


  • Spool directories for tasks waiting to be processed (cron, mail, print files) (depreciates /var/spool/mail)


  • Temporary files to be preserved across reboots

Finding things:

> find <path> [<expressions...>] [-ls] [-exec <cmd> {} \;]

  • search for files in a directory hierarchy
    -a = AND expr1 -a expr2 - both must be true
    -o = OR expr1 -o expr2 - only one need be true
    -ls List files using a long ls like listing
    -exec cmd {} \; Execute cmd for each file placing the filename where {} is located. Command is terminated with an escaped semicolon (\;) `
    True if:
    -name pattern Filename matches shell pattern
    -regex pattern Filename matches regex pattern
    -iname / -iregex Like -name / -regex but ignore case
    -mtime n File was modified n x 24 hours ago
    -perm mode Files permissions are mode
    -user user File is owned by user
    -group group File is owned by group

> locate <name>

  • Search for files indexed in a location database (much faster than find)

> tree

  • Depth indented directory tree display

Regular Expressions

  • Reading: man 7 regex
Class Grammar What it matches

<branch> ['|' <branch> ['|' <branch> ...]]

Matches anything that matches one of the branches.
Matches a match for the first piece, then the second, etc.


Matches 0 or more of the atom


Matches 1 or more of the atom


Matches 0 or 1 of the atom


Matches bound # of atoms



Matches exactly num items


Matches min or more items, up to max if specified.



Matches the beginng of a line


Matches the end of the line


Matches any single character


Bracket expression


Matches the regular expression regex as an atom.


Matches the empty string
Any normal character Matches that character
Regex examples:
Lines starting with foo ^foo
Lines ending with foo foo$
Lines with only foo in them ^foo$
Lines starting with foo or bar ^(foo|bar)
CS469 account cs469[0-9]{2}
7 digit phone number [0-9]{3}-[0-9]{4}
MAC address ([a-f0-9]{2}:){5}[a-f0-9]{2}
A hex number (0[xX])?[0-9a-fA-F]+
A C character reference '.'|'\\.'|'\\[0-7]{1,3}'
Quoted string (no escapes) "[^"]*"
IP address ((1?[0-9]{1,2}|2[0-4][0-9]|25[0-5]).){3}(1?[0-9]{1,2}|2[0-4][0-9]|25[0-5])

Commands using regular expressions

> grep patterns [files...]

  • Print lines matching a pattern

> egrep ...

  • Extended regular expressions (same as grep -E)

> fgrep ...

  • greps for fixed strings not regular expressions (same as grep -F)

> sed

  • stream editor for filtering and transforming text.
    -n    Quiet (no extraneous output) -e expr    Expression (script) to execute.

Perl regular expression syntax:

> man pcresyntax

> man pcrepattern

> pcregrep

  • PCRE compatible grep.