Logo  

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

/bin

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

/boot

  • Kernels / boot loader files

/dev

  • Device files

/etc

  • System-wide configuration files.

/etc/rc.d/

  • Slackware init scripts

/etc/X11

  • X windows system configuration files.

/home

  • Typically user home directories

/lib, /lib64

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

/media
/mnt

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

/opt

  • Optional local packages

/proc

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

/root

  • The super-users home directory

/run

  • System runtime files

/sbin

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

/srv

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

/sys

  • System information pseudo-filesystem

/tmp

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

/usr

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

/usr/bin

  • User binaries, not needed at boot.

/usr/include

  • Standard include libraries (C, C++)

/usr/lib*

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

/usr/local/

  • A tertiary hierarchy for local system additions

/usr/sbin

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

/usr/share

  • Shared data

/usr/src

  • Source code (e.g. kernel source)

/usr/X11R6

  • X windows (Version 11, release 6)

/var

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

/var/cache

  • Application cache data.

/var/lib

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

/var/lock

  • Lock files

/var/log

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

/var/log/packages

  • Slackware package database

/var/log/setup

  • Slackware setup/configuration scripts

/var/mail

  • User mailboxes

/var/spool

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

/var/tmp

  • Temporary files to be preserved across reboots

Finding things:

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

  • search for files in a directory hierarchy
    Expressions:
    -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
Regex:

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

Matches anything that matches one of the branches.
Branch:
<piece>[<piece>[<piece>...]]
Matches a match for the first piece, then the second, etc.
Piece:

<atom>'*'

Matches 0 or more of the atom

<atom>'+'

Matches 1 or more of the atom

<atom>'?'

Matches 0 or 1 of the atom

<atom><bound>

Matches bound # of atoms

Bound:

'{'<num>'}'

Matches exactly num items

'{'<min>','[<max>]}'

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

Atom:

^

Matches the beginng of a line

$

Matches the end of the line

.

Matches any single character

[...]

Bracket expression

(<regex>)

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.