Home COMSC-171 <- Prev Next ->

Inodes

Metadata

inode table
data structure containing metadata for UNIX files (permissions, ownership, times, blocks, etc.)
information about the files rather than contents of the files
hard link
directory entry (name) associated with a file
a file may have many hard links, all are equivalent
must be in same filesystem
symbolic link
shortcut, pointer to a hard link
attribute
filesystem-dependent flags
common examples: append, immutable
extended attribute
arbitrary name=value pair

Hard Links

cat > test1 # create a file abcde # type characters into it Ctrl+d # save ls -l # note the size ln test1 test2 # create a hard link in the same filesystem ls -l test[12] # both should look the same ls -il test[12] # '-i' option shows inode number cat >> test2 # append characters qwerty # type characters Ctrl+d # save ls -l test[12] # both have changed in the same way touch test2 # reset date (if it's been a minute you'll see the change) ls -l test[12] # both have changed in the same way stat test2 # shows inode information

Symbolic Links

ln -s ~/test1 /tmp/test.$USER # create a symbolic link # unique name in a different filesystem ls -l /tmp/test.$USER # should show a link cat /tmp/test.$USER # same as original rm test1 # remove hard link ls -l test* # one link still here cat test* # data still here cat /tmp/test.$USER # dead symbolic link rm /tmp/test.$USER # remove symbolic link rm test2 # remove the last link ls -l test* # now it's gone

Attributes

touch foo # create an empty file (changes date on an existing file) lsattr # list attributes (e is extents) chattr -v 1 foo # change attributes (-v is version number) lsattr -v # shows version number touch bar chattr -v 2 bar lsattr ls -vl # sorted by version number # interesting attributes can only be changed by root # FreeBSD uses ls -o and chflags # ZFS uses lsextattr, getextattr, setextattr, rmextattr rm foo bar # clean up

Find

# FreeBSD tests may differ slightly # append 2> /dev/null to hide error messages find /usr/bin -size +100k # look for files > 100KB find /usr/bin -size +100k -exec ls -ld {} \; # list files found find /usr/bin -name '*sh' -exec ls -ld {} \; # find by name find /usr/bin \( -name '*sh' -o -name 'z*' \) -exec ls -ld {} \; # OR find /usr/bin -type l -exec ls -ld {} \; # look for symbolic links find /usr/bin ! -group root -exec ls -ld {} \; # group not root find /etc -perm 700 -exec ls -ld {} \; # exact permissions find /etc -perm -222 -exec ls -ild {} \; # all write bits set find /etc ! -perm /222 -exec ls -ld {} \; # not any write bits set find /var/log -mtime -1 -exec ls -ld {} \; # modified within 24 hrs find /var/log -mmin -60 -exec ls -ld {} \; # modified within 60 min find /usr -maxdepth 1 -type d # look for directories, only 1 level down find /usr -links +2 -type f -exec ls -ild {} \; # > 2 links, show inode number # files which have the same inode number are the same file # remember one of the inode numbers, in the next line use it as INUM find /usr -inum INUM -exec ls -ild {} \; # inode number