Files & Directories Objectives –to be able to describe and use the Unix file system model and concepts Contents –directory structure –file system concepts.

Slides:



Advertisements
Similar presentations
CST8177 File Systems.
Advertisements

MORE FILE ATTRIBUTES. ls –l to display file attributes (properties) Listing of a specific directory Ownership and group ownership Different file permissions.
The Unix File System. What are the three parts of every file on a Unix filesystem? And where is each stored? Filename - stored in directories Inode -
Unix permissions, ownership and setuid File security and ownership The chmod(1) command Process Ownership Setuid, Setgid and the Sticky bit Writing setuid.
UNIX file systems Learning Objectives: 1. To understand the basics of file systems 2. To understand the hierarchical structure in Unix file system 3. To.
Exploring the UNIX File System and File Security
File security and Permissions A file is owned by the user who created it That user can then specify who can read, write and execute that file A file when.
Linux+ Guide to Linux Certification, Second Edition
6/24/2015B.RamamurthyPage 1 File System B. Ramamurthy.
Links Learning Objectives: 1. To understand the basics of links & its usage 2. To learn the construction / removal of different types of links 3. To distinguish.
More Shell Basics CS465 - Unix. Unix shells User’s default shell - specified in /etc/passwd file To show which shell you are currently using: $ echo $SHELL.
Linux Linux File System.
File Management System The way a user or application may access files Programmer does not need to develop file management software You take files for granted.
UNIX Files and Security Software Tools. Slide 2 File Systems l What is a file system? A means of organizing information on the computer. A file system.
7/15/2015B.RamamurthyPage 1 File System B. Ramamurthy.
Links Software Tools. Lecture 4 / Slide 2 Links l A link is a pointer to a file. l In fact, in UNIX all filenames are just links to a file. Most files.
Linux File Security. What is Permission ? Specifies what right are granting to users to access the resources available in the computer. So that important.
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi.
COMP1070/2002/lec4/H.Melikian COMP1070 Lecture #5  Files and directories in UNIX  Various types of files  File attributes  Notion of pathname  Commands.
O.S security Ge Zhang Karlstad University. Outline Why O.S. security is important? Security schemes in Unix/Linux system Security schemes in windows system.
Filesystem Hierarchy Standard (FHS) –Standard of outlining the location of set files and directories on a Linux system –Gives Linux software developers.
The file structure and related utilities CS240 Computer Science II.
Lesson 7-Creating and Changing Directories. Overview Using directories to create order. Managing files in directories. Using pathnames to manage files.
1 File Management Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung Institute of Technology
1 Lecture 2 Working with Files and Directories COP 3344 Introduction to UNIX.
File Permissions. What are the three categories of users that apply to file permissions? Owner (or user) Group All others (public, world, others)
Linux+ Guide to Linux Certification, Second Edition
1Week 4 - Jan 31, 2005 Week 4 Agenda UNIX Directory Structure Absolute pathname Relative pathname Permissions chmod (symbolic/absolute)
Managing Files CSCI N321 – System and Network Administration Copyright © 2000, 2011 by the Trustees of Indiana University except as noted.
The UNIX File System. The UNIX File A file is a container for storing information and data. Filename limited to 255 characters. Can’t contain / or NULL.
Module 4 - File Security. Security Overview File Ownership Access to Files and Dircetories Changing File and Directory Ownership Changing File and Directory.
Chapter Two Exploring the UNIX File System and File Security.
INTRODUCTION TO LINUX Jacob Chan. GNU/Linux Consists of Linux kernel, GNU utilities, and open source and commercial applications Works like Unix –Multi-user.
File Systems CSCI What is a file? A file is information that is stored on disks or other external media.
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved Chapter 5 File Management File Overview.
ITI-481: Unix Administration Meeting 3 Christopher Uriarte, Instructor Rutgers University Center for Applied Computing Technologies.
Lesson 9-Setting and Using Permissions. Overview Describing file permissions. Using execute permissions with a file. Changing file permissions using mnemonics.
1Week 4 - Sep 26, 2005 Week 4 Agenda UNIX Directory Structure Absolute pathname Relative pathname Permissions chmod (symbolic/absolute)
Managing Files. Module 5 Managing Files ♦ Introduction “On a Linux system, everything is a file; if something is not a file, it is a process.” ♦ Topics.
Linux file system "On a UNIX system, everything is a file; if something is not a file, it is a process." Sorts of files (on a Linux system) Directories:
Chapter Two Exploring the UNIX File System and File Security.
Chapter 4: File Security & Permissions Also: Hard and Soft Links, see p77-80 &
Linux+ Guide to Linux Certification, Third Edition
Linux+ Guide to Linux Certification, Third Edition
Workbook 4 User & Group Permissions RH030 Linux Computing Essentials.
1 © 2001 John Urrutia. All rights reserved. Chapter 4 The LINUX Filesystem.
Managing Files CSCI N321 – System and Network Administration Copyright © 2000, 2007 by the Trustees of Indiana University except as noted.
Λειτουργικά Συστήματα – Lab2 Γιάννης Πετράκης. Directory Navigation and Control  The Unix file system is set up like a tree branching out from the root.
The Unix File system (UFS) Presented by: Gurpreet Singh Assistant Professor Department of School of Computing and Engineering Galgotias University.
2 Manual & Filestore Mauro Jaskelioff. Introduction Using the manual The UNIX filestore File permissions.
1 Lecture 2 Working with Files and Directories COP 3353 Introduction to UNIX.
CSCI 330 The UNIX System Unit V Permissions. all access to directories and files is controlled UNIX uses discretionary access control (DAC) model each.
CIT 383: Administrative ScriptingSlide #1 CIT 383: Administrative Scripting Directories.
Lecture 02 File and File system. Topics Describe the layout of a Linux file system Display and set paths Describe the most important files, including.
Fall 2013 SILICON VALLEY UNIVERSITY CONFIDENTIAL 1 Introduction to Embedded Systems Dr. Jerry Shiao, Silicon Valley University.
CSCI 330 UNIX and Network Programming Unit II Basic UNIX Usage: File System.
UNIX file systems Learning Objectives: 1. To understand the basics of file systems 2. To understand the hierarchical structure in Unix file system 3. To.
The Unix File System R Bigelow. The UNIX File System The file system refers to the way in which UNIX implements files and directories. The UNIX file system.
File Management commands cat Cat command cat cal.txt cat command displays the contents of a file here cal.txt on screen (or standard out).
Chapter 2: Exploring the UNIX File System (For Tuesday Section) File and File Systems.
File System Security in Unix Annie Calpe. Overview Unix Basics File System Security: - Account Security: Passwords - File Permissions - Access Control.
Linux Filesystem Management
Agenda The Linux File System (chapter 4 in text)
Module X (Unix/Linux Password Security)
Commands Basic syntax of shell commands UNIX or shell commands have a basic structure command -options target command comes first (such as cd or ls) any.
Exploring the UNIX File System and File Security
File System B. Ramamurthy B.Ramamurthy 11/27/2018.
Module 6 Working with Files and Directories
January 26th, 2004 Class Meeting 2
Presentation transcript:

Files & Directories Objectives –to be able to describe and use the Unix file system model and concepts Contents –directory structure –file system concepts –i-nodes –permission bits and access control –links –set user/group ID –sticky bits Practicals –manipulating files and permissions Summary

Standard Directories

The Unix Filesystem Unix supports disk partitioning and slicing –one branch of directory structure can reside on one partition or slice –different types of filesystem can be assigned to each partition or slice All filesystems types follow similar model –each filesystem on a partition (or slice) has inode table –inode table comprises one record for each file stored within this partition –file is uniquely identified within the filesystem by its inode number Each file has an inode table entry –inode table entry holds all attributes of a file, such as: –file size, user, group, permissions, etc. Directories map names into inode numbers –directories do not store file attributes –a inode number can have more than one name referencing it

Long Directory Listing # ls -al drwxr-xr-x 2 hawkeye users 512 Jul 11 11:21. drwxr-xr-x 9 root sys 512 Jul 11 10:54.. -rw-r--r-- 1 hawkeye users 23 Jul 15 10:21 file1 drwxr-xr-x 2 hawkeye users 512 Jul 15 10:25 dir1 # ls -al drwxr-xr-x 2 hawkeye users 512 Jul 11 11:21. drwxr-xr-x 9 root sys 512 Jul 11 10:54.. -rw-r--r-- 1 hawkeye users 23 Jul 15 10:21 file1 drwxr-xr-x 2 hawkeye users 512 Jul 15 10:25 dir1 Type of file -plain file ddirectory lsymbolic link Permissions rread wwrite xexecute Size in bytes File user (owner) and group Link count Date and time of last modification Name

Three types of user, plus super user –User (or owner) –Group (any user in same group) –Other Three types of protection –Read –Write –Execute Determine protection flags using: –If super user, all operations permitted –If user, use user protection flags –If same group, use group protection flags –Otherwise use other protection flags Access Control

File & Directory Protection File protection r - read file w - write file (does not imply read) x - execute file (program or shell script) Directory protection r - can read directory list (does not imply access to files) w - can write to directory (create, rename & delete files) x - can search directory (pass through and access files) To create a file you need: --x permission on all directories in the pathname -wx permission on the last directory in the pathname To read a file you need: --x permission on all directories in the pathname r-- permission on the file To write into a file you need: --x permission on all directories in the pathname -w- permission on the file

File Manipulation Permissions File manipulation permissions define ability to write into a directory, ie executing cp, rm, mv, mkdir, rmdir To write into a directory you need: - -xpermission on all directories in the pathname -wx permission on the last directory in the pathname You do not need access to the contents of the file itself You do not need to be the file owner! The rm and mv commands try to be helpful –they will prompt you to confirm the operation for those files for which you do not have write access –The -f (force) option on both commands suppresses this prompt $ rm mypass mypass mode 444? # type y or n $ rm mypass mypass mode 444? # type y or n $ rm -f mypass # done

Exercise - Using File Protection Which of the following operations are permitted? $ id -a uid=318(hawkeye) gid=300(users) groups=100(staff),300(users) $ ls -ld. file* /etc/passwd /etc/shadow /etc drwxr-xr-x 2 trapper users 512 Jul 11 11:21. -rw-rw-r-- 1 trapper staff 23 Jul 15 10:21 file1 -rw-r trapper mash 41 Jul 15 10:21 file2 -rw-rw-rw- 1 hawkeye mash 41 Jul 15 10:21 file3 -r--r--r-- 1 root root 132 Jan 01 9:30 /etc/passwd -r root shadow 96 Jan 01 9:30 /etc/shadow drwxr-xr x 72 root root 4096 Jan 01 9:30 /etc $ id -a uid=318(hawkeye) gid=300(users) groups=100(staff),300(users) $ ls -ld. file* /etc/passwd /etc/shadow /etc drwxr-xr-x 2 trapper users 512 Jul 11 11:21. -rw-rw-r-- 1 trapper staff 23 Jul 15 10:21 file1 -rw-r trapper mash 41 Jul 15 10:21 file2 -rw-rw-rw- 1 hawkeye mash 41 Jul 15 10:21 file3 -r--r--r-- 1 root root 132 Jan 01 9:30 /etc/passwd -r root shadow 96 Jan 01 9:30 /etc/shadow drwxr-xr x 72 root root 4096 Jan 01 9:30 /etc $ more file1 $ more file2 $ ls -l >file1 $ more /etc/passwd $ more /etc/shadow $ more file1 $ more file2 $ ls -l >file1 $ more /etc/passwd $ more /etc/shadow $ rm file2 $ rm file3 $ cp file1 file4 $ rm /etc/passwd $ rm /etc/shadow $ rm file2 $ rm file3 $ cp file1 file4 $ rm /etc/passwd $ rm /etc/shadow

Set User & Group Ids Programs normally executed with the permissions of the user running the program –a child process inherits is UID and GID from the parent Using set user or set group id allows a program to run with the ownership of the program's file –the child process runs with the UID and GID of the file Used to give users access to files and programs which would otherwise be restricted # ls -l /etc/shadow /usr/bin/passwd -r root shadow 473 Dec 25 09:30 /etc/shadow -r-sr-xr-x1 root root Jan /usr/bin/passwd # ls -l /etc/shadow /usr/bin/passwd -r root shadow 473 Dec 25 09:30 /etc/shadow -r-sr-xr-x1 root root Jan /usr/bin/passwd

The Sticky Bit Files can have a sticky bit –originally used to lock executables into memory –no longer used for this purpose with modern memory paging Unix Shared directories should have the sticky bit set –only the owner can delete files from sticky directories –owner still needs write permission to the directory $ ls -al /tmp drwxrwxrwt 1 root sys 1024 Dec 25 09:30. drwxr-xr-x 1 root sys 512 Dec 25 09:30.. -rwxr--r--1 trapper users 188 Dec 25 09:30 ukulele $ rm -f /tmp/ukulele rm: /tmp/ukulele: permission denied $ ls -al /tmp drwxrwxrwt 1 root sys 1024 Dec 25 09:30. drwxr-xr-x 1 root sys 512 Dec 25 09:30.. -rwxr--r--1 trapper users 188 Dec 25 09:30 ukulele $ rm -f /tmp/ukulele rm: /tmp/ukulele: permission denied

File Permission Commands Change ownership, group chown [-R] user files... chgrp [-R] group files... Change permissions chmod [-R] perms files... perms can be symbolic of form [oug][+=-][rwxst] perms can be octal digits # chmod ugo=rwx /tmp # chmod +t /tmp # chmod ug+s /usr/bin/passwd # chmod ugo=rwx /tmp # chmod +t /tmp # chmod ug+s /usr/bin/passwd # chmod 1777 /tmp # chmod -R 664 /project/bin # chmod 1777 /tmp # chmod -R 664 /project/bin # chown root /usr/bin/passwd # chgrp sys /usr/bin/passwd # chown -R user12 /home/user12 # chown root /usr/bin/passwd # chgrp sys /usr/bin/passwd # chown -R user12 /home/user12

Links The ln command creates a link to a file ln [-snf] file target –create a new link called target to an existing file -s symbolic or soft link -n don't overwrite existing filename -f force overwrite of existing filename (default) Remove links with rm – if symbolic link removes link not actual file –a file is deleted when the last hard link is removed Symbolic links –the link file holds the name of the real file –transparent to all commands except ls and rm Hard links: –must be within a filesystem –only root can link to directories

Using Links Links used to save space or allow files to be known by multiple names Consider files of sales data where each doctor puts their monthly figures in a separate file Using links we can organise the files in different ways: –by doctor –by month operations hawkeyetrapper data hp5101hp5102hp5103tm5101tm5102tm

Looking at links Use ls command to look at links -i include inode number in listing -l show symbolic link names and inode link count -L traverse (hide) symbolic links (follow symbolic link to original file) $ touch nurse1 $ ln nurse1 nurse2 $ ln -s nurse1 nurse3 $ ls -il nurse[1-3] 62 -rw-r--r-- 2 hawkeye users 224 Jul 18 09:41 nurse1 62 -rw-r--r-- 2 hawkeye users 224 Jul 18 09:41 nurse2 63 lrwxrwxrwx 1 hawkeye users 6 Jul 18 09:41 nurse3 -> nurse1 $ ls -ilL nurse3 62 -rw-r--r-- 2 hawkeye users 224 Jul 18 09:41 nurse3 $ touch nurse1 $ ln nurse1 nurse2 $ ln -s nurse1 nurse3 $ ls -il nurse[1-3] 62 -rw-r--r-- 2 hawkeye users 224 Jul 18 09:41 nurse1 62 -rw-r--r-- 2 hawkeye users 224 Jul 18 09:41 nurse2 63 lrwxrwxrwx 1 hawkeye users 6 Jul 18 09:41 nurse3 -> nurse1 $ ls -ilL nurse3 62 -rw-r--r-- 2 hawkeye users 224 Jul 18 09:41 nurse3

Summary The Unix file system is a hierarchical tree structure with a single root node Underlying disk layout is hidden from the casual user Files on a disk are identified by a unique number called the i-node number Directories map names onto i-node numbers which permits file links (more than one name for a file) Access to all aspects of the system is controlled through the file permissions Unix has a standard directory structure used by most systems