1 File System of Unix 2 References “UNIX&Linux Shell 設計程式篇 ” 第一章 – 請參考 pages 18 - 32 “Practical UNIX Programming - A Guide to Concurrency, Communication,

Slides:



Advertisements
Similar presentations
MORE FILE ATTRIBUTES. ls –l to display file attributes (properties) Listing of a specific directory Ownership and group ownership Different file permissions.
Advertisements

1 Introduction to UNIX Ke Liu
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 -
5 Basic utilities When a user logs in to the Linux operating system the directory that they will start in is their home directory. Most users will have.
Reference, primitive, call by XXX 必也正名乎 誌謝 : 部份文字取於前輩 TAHO 的文章.
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.
JAVA 程式設計與資料結構 第十四章 Linked List. Introduction Linked List 的結構就是將物件排成一列, 有點像是 Array ,但是我們卻無法直接經 由 index 得到其中的物件 在 Linked List 中,每一個點我們稱之為 node ,第一個 node.
The UNIX File System CS465. File Systems What is a file system? A means of organizing information on the computer. A file system is a logical view, not.
Linux+ Guide to Linux Certification, Second Edition
1-6 動畫的文件屬性 舞台是動畫實際播放的畫面, 所以舞台的大 小與長寬比例對將來動畫的呈現有很大的 影響。 Flash 預設的舞台尺寸是 550 Pixels × 400 Pixels, 背景為白色, 如果要更改舞台大小與 背景色, 請執行『修改 / 文件』命令, 開啟文 件屬性 (Document.
CIS 240 Introduction to UNIX Instructor: Sue Sampson.
6/24/2015B.RamamurthyPage 1 File System B. Ramamurthy.
CS 497C – Introduction to UNIX Lecture 12: - The File System Chin-Chih Chang
函式 Function Part.2 東海大學物理系‧資訊教育 施奇廷. 遞迴( Recursion ) 函式可以「呼叫自己」,這種動作稱為 「遞迴」 此程式的執行結果相當於陷入無窮迴圈, 無法停止(只能按 Ctrl-C ) 這給我們一個暗示:函式的遞迴呼叫可以 達到部分迴圈的效果.
Extreme Discrete Summation ★★★★☆ 題組: Contest Archive with Online Judge 題號: Extreme Discrete Summation 解題者:蔡宗翰 解題日期: 2008 年 10 月 13 日.
Enhancements to the Linux Kernel for Blocking Buffer Overflow Based Attacks Massimo Bernaschi Emanuele Gabrielli Luigi V. Mancini.
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.
Basic UNIX © McGraw Hill All rights reserved.
Getting Started with Linux Linux System Administration Permissions.
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi.
CS 141 Labs are mandatory. Attendance will be taken in each lab. Make account on moodle. Projects will be submitted via moodle.
COMP1070/2002/lec4/H.Melikian COMP1070 Lecture #5  Files and directories in UNIX  Various types of files  File attributes  Notion of pathname  Commands.
File Systems Sources and Resources: 1. A Students Guide to UNIX, by Hahn 2. Paula Davidson’s Handout on UNIXHandout on UNIX.
The file structure and related utilities CS240 Computer Science II.
Unix Primer. Unix Shell The shell is a command programming language that provides an interface to the UNIX operating system. The shell is a “regular”
Lesson 7-Creating and Changing Directories. Overview Using directories to create order. Managing files in directories. Using pathnames to manage files.
CHAPTER 1 UNIX FOR NONPROGRAMMERS By U ğ ur Halıcı.
Files & Directories Objectives –to be able to describe and use the Unix file system model and concepts Contents –directory structure –file system concepts.
1 Lecture 2 Working with Files and Directories COP 3344 Introduction to UNIX.
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.
INTRODUCTION TO LINUX Jacob Chan. GNU/Linux Consists of Linux kernel, GNU utilities, and open source and commercial applications Works like Unix –Multi-user.
Lesson 9-Setting and Using Permissions. Overview Describing file permissions. Using execute permissions with a file. Changing file permissions using mnemonics.
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:
Second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX Commands cal – will print a calendar.
BIF713 Basic Unix/Linux Commands Getting Help with Commands.
Linux+ Guide to Linux Certification, Third Edition
Linux+ Guide to Linux Certification, Third Edition
PacNOG 6: Nadi, Fiji UNIX ™/ /Linux Permissions Hervey Allen Network Startup Resource Center.
Privileges: who can control what Introduction to Unix June 16, 2009 Papeete, French Polynesia Hervey Allen.
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.
Openwebmail. 安裝 openwebmail 必要套件 yum -y install gcc perl-Text-Iconv perl-CGI perl- YAML perl-CPAN perl-suidperl httpd service httpd start chkconfig httpd.
File Systems, telnet and ftp Sources and Resources: 1. A Students Guide to UNIX, by Hahn 2. Paula Davidson’s Handout on UNIXHandout on UNIX.
1 Lecture 2 Working with Files and Directories COP 3353 Introduction to UNIX.
Agenda The Linux File System (chapter 4 in text)
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.
1 Introduction to Unix. 2 What is UNIX?  UNIX is an Operating System (OS).  An operating system is a control program that helps the user communicate.
A Brief Overview of Unix Brandon Bohrer. Topics What is Unix? – Quick introduction Documentation – Where to get it, how to use it Text Editors – Know.
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.
Lecturer: Hao-Hua Chu TA: Wen-Chang HSU.  Read and understand the nachos file system  Enhance file system in Nachos  Relax maximum size of a file.
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.
Agenda The Linux File System (chapter 4 in text) Directory Structures / Navigation Terminology File Naming Rules Relative vs Absolute pathnames Unix Commands:
Linux Filesystem Management
Privileges: who can control what
Permissions: who can control what Unix/IP Preparation Course July 19, 2009 Eugene, Oregon, USA
Agenda The Linux File System (chapter 4 in text)
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.
Linux file system "On a UNIX system, everything is a file;
Lecture 2 Working with Files and Directories
File System B. Ramamurthy B.Ramamurthy 11/27/2018.
Chapter 4: The Linux Filesystem
January 26th, 2004 Class Meeting 2
Presentation transcript:

1 File System of Unix

2 References “UNIX&Linux Shell 設計程式篇 ” 第一章 – 請參考 pages “Practical UNIX Programming - A Guide to Concurrency, Communication, and Multithreading” : Chapter 3 Files

3 Online Introduction of File System Original File Some important Shell Commands

4 Introduction of File System

5  ls -la -rw-r wrlai 980 Mar 23 12:00.cshrc -rw wrlai 2302 Sep 10 16:32.login -rw----r-- 1 wrlai 2354 Feb 22 10:35.mailrc --x--x--- 1 wrlai 3302 Jan 14 16:32 makefile -rw-rw--- 1 wrlai 3302 Jan 14 16:32 myfile -rw-r--r-- 1 wrlai 3880 Feb 12 10:00 abc drwxr-xr-x 1 wrlai 880 Feb 12 10:00 test drwxr-xr-x 1 wrlai 880 Feb 12 10:00 project An Example of Files

6 File System Files –Ordinary files ( - ) –Directory files ( d ) –Special Files : socket ( s )、 names pipe ( p )、 symbolic link ( l )、 character device(terminal) ( c )、 block device(disk) ( b ) Hierarchical File System –Tree-like structure –Each node presents a file

7 The Tree Structure wrlai.cshrc.login.mailrcproject Cprogram proj1proj2 a.outfile1.cc t1.cct2.cch1* myfile abc

8 The directory you are working in, is called working directory or current directory. cd Cprogram When you are first log in, the working directory is your home directory. –Use 〜 to present the home directory cd 〜 Current/ Home Directory

9 cd cd 用於改變 shell 的 working directory –cd 是 shell 的內建命令(不會執行 fork 和 exec ) –Child shell 用 cd 改變目錄不會影響 Parent shell 的目錄 Example : cd / (改變目錄到 / ) pwd (顯示目前所在的目錄位置) /

10 Original Files

11 Files Every file has a filename. No two files in the same directory can have the same name. A full (absolute) pathname is its filename and the complete path. Ex: /usr/prof/alex/project/assign1.c A relative file name is its filename and path from current directory. Ex: alex/project/assign1.c in

12 Unix File Representation A Unix file has a description which is stored in a structure called an inode. Each file is segmented and located in a tree- structured representation. Features of inode : –fairly efficient for small files –flexible if the size of the file changes

13 inode file information: size (in bytes) owner UID and GID relevant times (3) link and block counts permissions direct pointers to beginning file blocks single indirect pointers double indirect pointers triple indirect pointers the time of creation the time of last access the time of last modification... file block point block...

14 inode – Small File file information: size (in bytes) owner UID and GID relevant times (3) link and block counts permissions direct pointers 1, 2, 3 single indirect pointers double indirect pointers triple indirect pointers the time of creation the time of last access the time of last modification 1 2 3

15 inode – Larger File file information: size (in bytes) owner UID and GID relevant times (3) link and block counts permissions direct pointers 1, 2, …, 12 single indirect pointers double indirect pointers triple indirect pointers the time of creation the time of last access the time of last modification file block point block...

16  ls -la -rw-rw wrlai cs 3302 Jan 14 16:32 myfile File Information The name of file The time and date the file was created or last modified The size of the file in bytes The name of group The name of the owner The number of hard links Access Permissions ( 9 bits )

17 Type of file (one bit) : d : directory - : ordinary file s : socket p : names pipe (FIFO) l : symbolic link c : character device (terminal) b : block device (disk) Access Permissions ( 1/3 )

18 T hree types of users can access a file ( Owner/Group/Other ) A user can attempt to access a file in three ways ( Read/Write/Execute ) –Ordinary file Read : you can read from file Write : you can write to the file Execute : you can execute the file –Directory Read : you can read the directory Write : you can create, move, copy or remove entries Execute : you can search (i.e., enter) the directory Access Permissions ( 2/3 )

19 - r w - r w - r - - File mode (- indicates an ordinary file) Owner’s privileges (rw- means readable and writeable but not executable) Group’s privileges (rw- means readable and writable but not executable) Other’s privileges (r-- means readable but not writable or executable) Access Permissions ( 3/3 )

20 You can use chmod to change the access permissions of a file Example : % ls -l myfile -rw-rw-rw- 1 wrlai cs 3302 May 20 12:20 myfile % chmod g+x myfile -rw-rwxrw- 1 wrlai cs 3302 May 20 12:20 myfile % chmod o-w myfile -rw-rwxr-- 1 wrlai cs 3302 May 20 12:20 myfile Change Mode ( 1/4 )

21 WHO u User g Group o Other a All (ugo) Operator - Remove permission + Add permission = Set permission Permissions r Read w Write x Execute l Set locking privilege s Set user or group ID mode t Set save text (sticky bit) mode u User’s current permissions g Group’s current permission o Other’s current permissions Change Mode ( 2/4 )

22 Change Mode ( 3/4 ) -r--r--r-- 1 wrlai cs 3302 May 20 12:20 myfile % chmod 666 myfile -rw-rw-rw- 1 wrlai cs 3302 May 20 12:20 myfile read write execute Value read write execute Yes Yes Yes Yes Yes Yes - Yes Yes Yes Yes Yes Yes

23 Change Mode ( 4/4 ) % chmod 666 myfile -rw-rw-rw- 1 wrlai cs 3302 May 20 12:20 myfile % chmod 676 myfile -rw-rwxrw- 1 wrlai cs 3302 May 20 12:20 myfile % chmod 674 myfile -rw-rwxr-- 1 wrlai cs 3302 May 20 12:20 myfile

24 16 bits Attribute ( 1/3 ) Every file has 16 attribute bits. File Type ( bits ) –12 : S_IFIC ( Named pipe ) –13 : S_IFCHR/S_IFBLK ( Character or Block ) –14 : S_IFDIR ( Directory ) –15 : S_IFREG ( Original file ) –Only one bit can be set in bits

25 16 bits Attribute ( 2/3 ) Access permissions ( 0-8 bits ) rwxrwxrwx Sticky bit 黏著位元( bit 9 ): S_ISVTX – 當此 bit=1 , file 會一直留在記憶體中而不會被 swap out 。 – 對於 Original files ,使用者執行位元為 t (而非 x ),表示此 bit=1 。例如: ls 、 sh 、 vi 。 – 對於 Directory ,使用者執行位元為 t ,表示只 有超級使用者可刪除此目錄。

26 16 bits Attribute ( 3/3 ) Set Group ID ( bit 10 ): S_ISGID – 當此 bit=1 ,表示對此 file ,每個人均有和 file 擁有者相同的執行權( bit 6 = ‘s’ ) 。 – 執行此 file 的使用者, EUID 改成和 file 擁 有者相同的 UID 。 Set User ID ( bit 11 ): S_ISUID – 當此 bit=1 ,表示對此 file , Group 內的人均 有和 file 擁有者相同的執行權 。

27 UID 、 GID 、 EUID 、 EGID In /etc/passwd, every user has his –UID : real User ID –GID : Group ID (可以有很多個) Login shell 時, EUID=UID 、 EGID=GID 。 –EUID : Effective User ID –EGID : Effective Group ID 這四個 ID 用於決定某一使用者對於某一 檔案的使用權。

28 Example of UID & EUID 某一使用者的 UID = ncliu ,但可以利用 passwd 修改 /etc/passwd 的內容,如同擁 有和 root 相同的權限( EUID = root ) 。 被執行的指令 UID EUID SUID /bin/passwd ncliu root on

29 Some important Shell Commands

30 The rm command allows you to remove files. You need to have write permission. Is it possible to restore a file that has been removed ? NO ! rm - remove ( 1/3 )

31 % ls -l myfile.* - rw - rw - rw - 1 wrlai cs 1898 Jan 5... myfile.1 -r -- r -- r -- 1 wrlai cs 1898 jan 7... myfile.2 % rm myfile.* rm : override protection 444 for myfile.2 ? y % rm -i testfile.*  i ( interactive ) : ask user before remove rm : remove testfile.1 ? y rm : remove testfile.2 ? y rm - remove ( 2/3 )

32 rm - remove ( 3/3 ) % rm -f myfile.*  f ( force ) : regardless the file permissions % ls -l drw-rw-rw- 1 wrlai cs 1898 Jan 5... dummy % rm -r dummy  r ( recursive ) : remove all files and subdirectories within dummy How about these commands list below : % rm -r * % rm -ir dummy % rm -fr dummy

33 Wildchar ? 代表單一 character. * 代表任何的 string. 萬用字元 `v*[0-9]` 是 regular expression, v 開頭, 最後是數字的檔案. % ls sample1.c sample111.c % ls sample?.c sample1.c % ls sample*.c sample1.c sample111.c

34 alias You can add the following command in your.bachrc alias rm=“rm –i” Then you open this account next time, you type rm abc It will ask user before remove

35 To move a file to a different directory % mv [ -if ] file... directory To rename a file or directory % mv [ -if ] oldname newname If the target to which you move a file already exists, mv will replace the file. If you want to be caution about losing data, use -i % mv -i original destination mv - move

36 Make a copy of a file % cp [-ip ] file1 file2 –i ( interactive ): ask the permission before replacing a file that already exists –p ( preserve ): the destination file have the same modification times and permissions as the source file Copy files to a different directory %cp [-ip ] file... directory cp - copy ( 1/2 )

37 Copy a directory to another directory % cp -r [-ip ] directory1 directory2 % cp -r essays backups –r ( recurive ): will copy essays and all its files and subdirectories to backups (directory) cp - copy ( 2/2 )

38 To make a directory % mkdir [-mp] directory... –m : Specify the mode, in octal, for the new directory –p : Create both the directory, and any parent directories that don’t already exist. mkdir - make directory

39 To remove a directory % rmdir [-ps] directory... –p : Remove the directory and any empty parent directories –s : Suppress warning messages Is it possible to remove your working directory ? rmdir - remove directory

40 To change the owner and group associated with a file. % chown % chgrp [-Rh] groupID files –R : Recursive operation –h : Change the ownership or group of the symbolic link file itself, not the file to which it refers Note: In some system, these commands are not permit to anyone but the superuser. chown, chgrp

41 To locate misplaced files % find. -name sample1.c -print >./C-language/sample1.c –to search through the current subtree (. ) for a file named “sample1.c” % find /usr -name `v*[0-9]` -print –to search the file with its name start with v and end with a digit in the /usr subtree find ( 1/2 )

42 % find /etc -size print –to search files with size larger than 1000 blocks (512 bytes) in the /etc subtree –‘+’ : larger than ; ‘=‘ : equal to (exactly) ; ‘-’ : less than % find / -name core -exec rm { } \ ; –to search the entire file system for the files named core and remove them) Note : Be careful to use find to locate files starting from the root ( / ). find ( 2/2 )

43 Simple Test Try to change one of your executable programs –Only you can read/write/execution. The other can’t do anything. –All of people can read it, but only you can write and execute it. Use the command “man” to find the detail about “ls”.