Lecture 4: File management starting from / Hands-on Unix System - - PowerPoint PPT Presentation

lecture 4 file management starting from
SMART_READER_LITE
LIVE PREVIEW

Lecture 4: File management starting from / Hands-on Unix System - - PowerPoint PPT Presentation

Lecture 4: File management starting from / Hands-on Unix System Administration DeCal 2012-01-30 1 / 32 Review Shell expansion Standard streams Useful commands In a nutshell Review Philosophy Users File hierarchy


slide-1
SLIDE 1

1 / 32

Lecture 4: File management starting from /

Hands-on Unix System Administration DeCal

2012-01-30

slide-2
SLIDE 2

Review

Review ❖ Shell expansion ❖ Standard streams ❖ Useful commands ❖ In a nutshell ❖ Philosophy Users File hierarchy Filesystems Files 2 / 32

slide-3
SLIDE 3

Shell expansion

Review ❖ Shell expansion ❖ Standard streams ❖ Useful commands ❖ In a nutshell ❖ Philosophy Users File hierarchy Filesystems Files 3 / 32

  • variables ($PATH, environment

variables)

  • aliases
  • tilde
  • globbing
  • backticks
  • single vs. double quotes
slide-4
SLIDE 4

Standard streams

Review ❖ Shell expansion ❖ Standard streams ❖ Useful commands ❖ In a nutshell ❖ Philosophy Users File hierarchy Filesystems Files 4 / 32

  • stdin, stdout, stderr
  • redirection: >, >>, <
  • pipes: |
  • tee, xargs
slide-5
SLIDE 5

Useful commands

Review ❖ Shell expansion ❖ Standard streams ❖ Useful commands ❖ In a nutshell ❖ Philosophy Users File hierarchy Filesystems Files 5 / 32

  • find
  • tr, sort, head, tail, wc
  • for index in $array; do

command; done

  • while expression; do command;

done

  • regex with grep, sed, awk
slide-6
SLIDE 6

In a nutshell

Review ❖ Shell expansion ❖ Standard streams ❖ Useful commands ❖ In a nutshell ❖ Philosophy Users File hierarchy Filesystems Files 6 / 32

  • RTFM: man, --help command

line option

  • input: command line options, stdin
  • utput: stdout, stderr
  • manipulate with pipes (|),

redirection (>, >>), and substitution (‘)

slide-7
SLIDE 7

Philosophy

Review ❖ Shell expansion ❖ Standard streams ❖ Useful commands ❖ In a nutshell ❖ Philosophy Users File hierarchy Filesystems Files 7 / 32

The highest achievement of the Unix-aesthetic is to have a command that does precisely one function, and does it

  • well. Purists object that, after freshman programmers at

Berkeley got through with it, the program “cat” which concatenates multiple files to its output now has

  • OPTIONS. . . “Cat came back from Berkeley waving

flags,” in the words of Rob Pike, perhaps the ultimate Unix minimalist. —The Unix-Haters Handbook This is the Unix philosophy. Write programs that do one thing and do it well. Write programs to work together. Write programs to handle text streams, because that is a universal interface. —Doug McIlroy

slide-8
SLIDE 8

Users

Review Users ❖ Types of users ❖ Groups ❖ NSS databases ❖ What’s a user ❖ Who’s logged in File hierarchy Filesystems Files 8 / 32

slide-9
SLIDE 9

Types of users

Review Users ❖ Types of users ❖ Groups ❖ NSS databases ❖ What’s a user ❖ Who’s logged in File hierarchy Filesystems Files 9 / 32

  • root: superuser, virtually unlimited

control

  • system user accounts

typically low UIDs, /bin/false shell

  • real user accounts

typically higher UIDs, real shell like /bin/bash

slide-10
SLIDE 10

Groups

Review Users ❖ Types of users ❖ Groups ❖ NSS databases ❖ What’s a user ❖ Who’s logged in File hierarchy Filesystems Files 10 / 32

  • every user has a primary group and
  • ptionally secondary group(s)
  • important for file permissions
slide-11
SLIDE 11

NSS databases

Review Users ❖ Types of users ❖ Groups ❖ NSS databases ❖ What’s a user ❖ Who’s logged in File hierarchy Filesystems Files 11 / 32

  • passwd: user information, public

✦ useradd, usermod, chsh, userdel

  • shadow: “encrypted” (hashed)

passwords, only readable by root

✦ passwd

  • group: groups

✦ groupadd, groupmod, groupdel

slide-12
SLIDE 12

What’s a user

Review Users ❖ Types of users ❖ Groups ❖ NSS databases ❖ What’s a user ❖ Who’s logged in File hierarchy Filesystems Files 12 / 32 $ getent passwd daradib daradib:x:1000:1000:Dara Adib„,:/home/daradib:/bin/bash

  • login name
  • password hash
  • numerical user ID
  • numerical group ID
  • finger info (name, phone, office, etc.)
  • home directory
  • shell
slide-13
SLIDE 13

Who’s logged in

Review Users ❖ Types of users ❖ Groups ❖ NSS databases ❖ What’s a user ❖ Who’s logged in File hierarchy Filesystems Files 13 / 32

  • who, w: print currently logged in users
  • last: print login-logout log from

/var/log/wtmp, /var/log/utmp, or similar

  • for more details, use process

accounting

slide-14
SLIDE 14

File hierarchy

Review Users File hierarchy ❖ Windows ❖ *nix concept ❖ Looking under / ❖ Looking under / more Filesystems Files 14 / 32

slide-15
SLIDE 15

Windows

Review Users File hierarchy ❖ Windows ❖ *nix concept ❖ Looking under / ❖ Looking under / more Filesystems Files 15 / 32

  • each storage device has a drive letter,

e.g. A:\ for floppy, C:\ for hard disk, etc.

  • important directories

C:\Windows

”C:\Program Files”

C:\Users

slide-16
SLIDE 16

*nix concept

Review Users File hierarchy ❖ Windows ❖ *nix concept ❖ Looking under / ❖ Looking under / more Filesystems Files 16 / 32

  • “simplicity through expression”
  • everything starts from the root1: /
  • excessive (but productive) abbreviation
  • case sensitive

1(not to be confused with /root)

slide-17
SLIDE 17

Looking under /

17 / 32

/bin/ core binaries /dev/ device files /etc/ systemwide configuration files /home/ home directories (user data) /lib/ core libraries /proc/ procfs interface to kernel

slide-18
SLIDE 18

Looking under / more

18 / 32

/root/ root’s home directory2 /sbin/to system binaries /tmp/ temporary files /usr/ non-core binaries, libraries, etc. /var/ varying files: logs, user inboxes, running program data, etc.

2(not to be confused with the root /)

slide-19
SLIDE 19

Filesystems

Review Users File hierarchy Filesystems ❖ What is a filesystem? ❖ Examples ❖ Non- disk/flash filesystems ❖ RAID ❖ RAID examples ❖ Mounting Files 19 / 32

slide-20
SLIDE 20

What is a filesystem?

Review Users File hierarchy Filesystems ❖ What is a filesystem? ❖ Examples ❖ Non- disk/flash filesystems ❖ RAID ❖ RAID examples ❖ Mounting Files 20 / 32

  • Each local hard disk can have one or

more partitions which contain files managed by a filesystem

e.g., /dev/sda, /dev/sda1

slide-21
SLIDE 21

Examples

Review Users File hierarchy Filesystems ❖ What is a filesystem? ❖ Examples ❖ Non- disk/flash filesystems ❖ RAID ❖ RAID examples ❖ Mounting Files 21 / 32

  • Windows (and flash drives)

filesystems: FAT32, NTFS

  • Linux: ext3, ext4, btrfs
  • Other Unix: UFS, XFS, ZFS, ReiserFS
slide-22
SLIDE 22

Non-disk/flash filesystems

Review Users File hierarchy Filesystems ❖ What is a filesystem? ❖ Examples ❖ Non- disk/flash filesystems ❖ RAID ❖ RAID examples ❖ Mounting Files 22 / 32

  • RAM: tmpfs
  • network: NFS, SMB
  • FUSE: GmailFS, WikipediaFS
slide-23
SLIDE 23

RAID

Review Users File hierarchy Filesystems ❖ What is a filesystem? ❖ Examples ❖ Non- disk/flash filesystems ❖ RAID ❖ RAID examples ❖ Mounting Files 23 / 32

  • Redundant Array of Independent

(Inexpensive) Disks

  • combine multiple hard drives for speed

(striping), capacity, reliability (mirroring, parity)

slide-24
SLIDE 24

RAID examples

Review Users File hierarchy Filesystems ❖ What is a filesystem? ❖ Examples ❖ Non- disk/flash filesystems ❖ RAID ❖ RAID examples ❖ Mounting Files 24 / 32

  • common examples: RAID 0 (striping),

RAID1 (mirror), RAID5 (parity), RAID 6 (two parity)

  • nested, e.g., RAID 10
slide-25
SLIDE 25

Mounting

Review Users File hierarchy Filesystems ❖ What is a filesystem? ❖ Examples ❖ Non- disk/flash filesystems ❖ RAID ❖ RAID examples ❖ Mounting Files 25 / 32

  • file hierarchy crosses filesystem

boundaries

  • use mount to mount local or

networked stuff on a directory (mount point)

can mount regular files too

slide-26
SLIDE 26

Files

Review Users File hierarchy Filesystems Files ❖ ls options ❖ ls -l ❖ Regular files ❖ Other file types ❖ File permissions ❖ Changing file permissions 26 / 32

slide-27
SLIDE 27

ls options

Review Users File hierarchy Filesystems Files ❖ ls options ❖ ls -l ❖ Regular files ❖ Other file types ❖ File permissions ❖ Changing file permissions 27 / 32

  • l: long listing format
  • h: human-readable file sizes
  • d: show directories themselves, not

contents

  • F: classify files with indicators

e.g., directory/, symlink@, executable*

slide-28
SLIDE 28

ls -l

Review Users File hierarchy Filesystems Files ❖ ls options ❖ ls -l ❖ Regular files ❖ Other file types ❖ File permissions ❖ Changing file permissions 28 / 32

$ ls -l lec04.lyx

  • rw-r--r-- 1 daradib daradib

15K Sep 24 16:38 lec04.lyx

  • file type
  • permissions: user, group, other
  • number of hard links
  • wner, group, size, mtime, name
slide-29
SLIDE 29

Regular files

Review Users File hierarchy Filesystems Files ❖ ls options ❖ ls -l ❖ Regular files ❖ Other file types ❖ File permissions ❖ Changing file permissions 29 / 32

  • Windows: filetype extensions

.exe

.doc

  • Unix: magic tests

man file

slide-30
SLIDE 30

Other file types

Review Users File hierarchy Filesystems Files ❖ ls options ❖ ls -l ❖ Regular files ❖ Other file types ❖ File permissions ❖ Changing file permissions 30 / 32

  • ls -l

directories (dir)

symbolic links (symlink)

devices: character, block

sockets, named pipes (FIFOs)

slide-31
SLIDE 31

File permissions

Review Users File hierarchy Filesystems Files ❖ ls options ❖ ls -l ❖ Regular files ❖ Other file types ❖ File permissions ❖ Changing file permissions 31 / 32

  • rw-r--r-- 1 root root

1.5K Sep 2 10:58 /etc/passwd

  • rw-r----- 1 root shadow 947 Sep 2 10:58 /etc/shadow
  • permissions (chmod)

✦ read (+4) ✦ write (+2) ✦ execute (+1)

  • wners (chown, chgrp)

✦ user (first digit) ✦ group (second digit) ✦

  • ther (third digit)
slide-32
SLIDE 32

Changing file permissions

Review Users File hierarchy Filesystems Files ❖ ls options ❖ ls -l ❖ Regular files ❖ Other file types ❖ File permissions ❖ Changing file permissions 32 / 32

These commands are equivalent:

  • chown daradib:root file
  • chown daradib file; chgrp

root file These commands are equivalent:

  • chmod u=rwx,g+w,o-rwx file
  • chmod 720 file