CSCI 330 UNIX and Network Programming Unit II Basic UNIX Usage: File System.

Slides:



Advertisements
Similar presentations
NETW-240 Shells Last Update Copyright Kenneth M. Chipps Ph.D. 1.
Advertisements

ATS Programming Short Course I INTRODUCTORY CONCEPTS Tuesday, Jan. 27 th, 2009 Essential Unix Commands.
Exploring the UNIX File System and File Security
Introducing the Command Line CMSC 121 Introduction to UNIX Much of the material in these slides was taken from Dan Hood’s CMSC 121 Lecture Notes.
Lesson 22 – Introduction to Linux Systems Administration.
Linux+ Guide to Linux Certification, Second Edition
Guide To UNIX Using Linux Third Edition
CSCI 330 T HE UNIX S YSTEM File operations. OPERATIONS ON REGULAR FILES 2 CSCI The UNIX System Create Edit Display Contents Display Contents Print.
7/17/2009 rwjBROOKDALE COMMUNITY COLLEGE1 Unix Comp-145 C HAPTER 2.
Linux Commands LINUX COMMANDS.
L INUX C OMMAND L INE I NTERFACE G UNAANBAN.G
COMP1070/2002/lec4/H.Melikian COMP1070 Lecture #5  Files and directories in UNIX  Various types of files  File attributes  Notion of pathname  Commands.
Guide To UNIX Using Linux Fourth Edition
Brief introduction to UNIX A. Emerson CINECA, High Performance Systems.
1 THE UNIX FILE SYSTEM By Chokechai Chuensukanant ID COSC 513 Operating System.
The file structure and related utilities CS240 Computer Science II.
© Crown copyright Met Office An Introduction to Linux PRECIS Workshop, University of Reading, 23rd – 27th April 2012.
Manage Directories and Files in Linux
Lesson 7-Creating and Changing Directories. Overview Using directories to create order. Managing files in directories. Using pathnames to manage files.
Chapter 9 Part II Linux Command Line Access to Linux Authenticated login using a Linux account is required to access a Linux system. The Linux prompt will.
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.
Basic unix commands that everyone should know (Even if you have a mac) Slightly more advanced:
Linux+ Guide to Linux Certification, Second Edition
Jozef Goetz, expanded by Jozef Goetz, 2009 Credits: Parts of the slides are based on slides created by UNIX textbook authors, Syed M. Sarwar, Robert.
System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007 Reference:  chapter 1, The Unix Programming Environment, Kernighan & Pike, ISBN.
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.
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.
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.
Chapter Two Exploring the UNIX File System and File Security.
Agenda Basic Unix Commands (Chapters 2 & 3) Miscellaneous Commands: whereis, which, whoami, finger, passwd, cal, date Working with Files: cat, more, less.
E X C E E D I N G E X P E C T A T I O N S Basic LINUX Linux System Administration Dr. Hoganson Kennesaw State University Operating Systems Directory structure:
Linux+ Guide to Linux Certification, Third Edition
Linux+ Guide to Linux Certification, Third Edition
Introduction to Programming Using C An Introduction to Operating Systems.
Manage Directories and Files in Linux Part 2. 2 Identify File Types in the Linux System The file types in Linux referred to as normal files and directories.
Λειτουργικά Συστήματα – Lab2 Γιάννης Πετράκης. Directory Navigation and Control  The Unix file system is set up like a tree branching out from the root.
Agenda Basic Unix Commands (Chapters 2 & 3) Miscellaneous Commands: which, passwd, date, ps / kill Working with Files: file, touch, cat, more, less, grep,
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
Linux Commands C151 Multi-User Operating Systems.
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.
BIF713 File and Directory Management. File System A File System is a structure used to organize programs and data on a computer ’ s storage device Files.
UNIX filesystem CS 2204 Class meeting 2 *Notes by Doug Bowman and other members of the CS faculty at Virginia Tech. Copyright
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.
Learning basic Unix command It 325 operating 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).
Linux Tutorial Lesson Two *Getting Help in Linux *Data movement and manipulation *Relative and Absolute path *Processes Note: see chapter 1,2,3 from Linux.
Agenda The Linux File System (chapter 4 in text) Directory Structures / Navigation Terminology File Naming Rules Relative vs Absolute pathnames Unix Commands:
1 Linux Commands. 2 Path You specify a file or directory by its path name:  the full, or absolute, path name or the one relative to a location. The full.
Linux Filesystem Management
Agenda The Linux File System (chapter 4 in text)
UNIX To do work for the class, you will be using the Unix operating system. Once connected to the system, you will be presented with a login screen. Once.
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 Commands Help HANDS ON TRAINING Author: Muhammad Laique
Lecture 2 Working with Files and Directories
Some Linux Commands.
C151 Multi-User Operating Systems
The Command Prompt Commands are the way to “do things” in Unix
UNIX/LINUX Commands Using BASH Copyright © 2017 – Curt Hill.
Module 6 Working with Files and Directories
Lab 2: Terminal Basics.
Linux Commands LINUX COMMANDS.
January 26th, 2004 Class Meeting 2
Presentation transcript:

CSCI 330 UNIX and Network Programming Unit II Basic UNIX Usage: File System

UNIX Shell: traditional user interface “in the terminal at the command line” via “Terminal Emulator” via “putty” Features: interprets and executes commands remembers command history and allows editing allows command submission as background jobs CSCI UNIX and Network Programming2

Command Line Structure % command [-options] [arguments] UNIX is case sensitive Must be a space between command, options and arguments No space between the plus or minus sign and option letter Fields enclosed in [ ] are optional CSCI UNIX and Network Programming3 Command prompt Command name Arguments can be: 1. names of files 2. more information Command modifier: usually one character preceded by + or - sign

Command Line Example % sort list % sort -r list % sort -o sorted list CSCI UNIX and Network Programming4 Command name Command option Option argument Command argument

Some Basic Commands passwd - change password ls- list files more - show content of file, page by page logout- logout from system date - display date and time who - display who is on the system clear - clear terminal screen man - find and display system manual pages CSCI UNIX and Network Programming5

RTFM: The man Command show pages from system manual Syntax: man [options] [-S section] command-name % man date % man -k date % man crontab % man -S 5 crontab Caveats: Some commands are aliases Some commands are part of shell CSCI UNIX and Network Programming6 SectionDescription 1User commands 2System calls 3C library functions 4Special system files 5File formats 6Games 7Miscellaneous features 8System administration utilities

The Unix file system hierarchical organization of files contains directories and files always single tree basic commands to list and manipulate files independent of physical file system organization typical Unix file system types ext4 (formerly ext2, ext3) Reiser4, UFS (… HFS+), JFS, … also: vfat, ntfs CSCI UNIX and Network Programming7

Directory terminology Root Directory: / top-most directory in any UNIX file structure Home Directory: ~ directory owned by a user default location when user logs in Current Directory:. default location for working with files Parent Directory:.. directory immediately above the current directory CSCI UNIX and Network Programming8

Path path: list of names separated by “/” Absolute Path Traces a path from root to a file or a directory Always begins with the root (/) directory Example: /home/student/Desktop/assign1.txt Relative Path Traces a path from the current directory No initial forward slash (/) dot (.) refers to current directory two dots (..) refers to one level up in directory hierarchy Example: Desktop/assign1.txt CSCI UNIX and Network Programming9

Path to file3 CSCI UNIX and Network Programming10 Absolute Path: /usr/staff/joan/file3

Directory commands pwd to show path of current working directory cd to change the current working directory mkdir to create a new directory rmdir to delete an empty directory use “ rm -r ” to remove non-empty directory CSCI UNIX and Network Programming11

List directory content most frequently used file system command: Syntax: ls [options] [path] common options: -a show all files -l show long version of listing -t show files sorted by time stamp -S show files sorted by file size -r show files in reverse sorted order CSCI UNIX and Network Programming12

Long List Option % ls -al total 126 drwxr-xr-x 13 ege csci 1024 Apr 26 15:49. drwxr-xr-x 15 root root 512 Apr 24 15:18.. -rwxr--r-- 1 ege csci 885 Dec 2 13:07.login -rwx ege csci 436 Apr 12 11:59.profile drwx ege csci 512 May 17 14: drwx ege csci 512 Mar 19 13: drwx ege csci 512 Mar 31 10:16 Data -rw-r--r-- 1 ege csci 80 Feb 27 12:23 quiz.txt CSCI UNIX and Network Programming13 List contents of the current directory in long format. is current directory.. is parent directory dot (.) names are hidden files directories plain file

File System Commands Copying files or directories Syntax: cp source(s) target source(s) is one or more items to copy target is either name of copied item, or directory commonly used options: -i if “target” exists, then prompts for confirmation before overwriting -r recursively copy entire directories -p preserve access times and permission modes Moving files or directories Syntax: mv source(s) target CSCI UNIX and Network Programming14

Renaming files or directories use “ mv ” Example: rename file “unix” to “csci330” % mv unix csci330 Caveat: what happens if “csci330” exists and is a directory ? CSCI UNIX and Network Programming15

Deleting files or directories Syntax: rm path-list Commonly used options: -f force remove regardless of permissions -i prompt for confirmation before removing -r removes everything under the indicated directory Example: remove file “old-assign” % rm unix/assign/old-assign CSCI UNIX and Network Programming16

Linking Files Allows one file to be known by different names Link is a reference to a file stored elsewhere 2 types: Hard link (default) Symbolic link (a.k.a. “soft link”) Syntax: ln [-s] target local CSCI UNIX and Network Programming17

Link illustration create entry “bb” in “dir3” as link to file “aa” in “dir1” % cd /home/student/dir2/dir3 % ln /home/student/dir1/aa bb CSCI UNIX and Network Programming18 home student dir3 dir1dir2 aa bb -s

File System Layout file consists of: data blocks: identified by block numbers file meta information: inode contains which blocks make up file, owner, permissions, etc. stored in inode table index into table is inode number directory is table of: file name -> inode number CSCI UNIX and Network Programming19

Hard Link example: ln CSCI UNIX and Network Programming home student dir3 dir1dir2 aa bb aa2407 Contents of dir bb2407 Contents of dir3 inode table disk blocks

Symbolic Link example: ln -s CSCI UNIX and Network Programming home student dir3 dir1dir2 aa bb aa2407 Contents of dir bb2599 Contents of dir3 /home/student/ dir1/aa inode table disk blocks

Link type comparison CSCI UNIX and Network Programming22 Hard LinkSymbolic Link Checks for the existence of the original file The original file continues to exist as long as at least one directory contains it Cannot link to a file in a different file system Created without checking the existence of the original file Cannot access the original file if its path has restricted permissions Can cross physical file systems Can be circular linked to another symbolic linked file

Locating Files: find Syntax: find path-list expression(s) “find” recursively descends through directories in path-list and applies expression to every file Examples: find. -name “*.txt” find /tmp -empty -delete CSCI UNIX and Network Programming23

Many more commands … touch updates time stamp on file or directory can be used to create new, empty file cat displays content of file(s) more, less or pg display the contents of file(s) one page at a time Space bar – to advance to next page b – to go back a page Enter Key – to advance to next line CSCI UNIX and Network Programming24

… more commands … head displays the beginning portion of indicated file(s); the default head size is 10 lines. tail displays the ending portion of indicated file(s) wc display the size of files common options: -l display the number of lines -w display the number of words -c display the number of characters CSCI UNIX and Network Programming25

Comparing Files: diff compare two files line by line Syntax: diff [options] file-1 file-2 reports a series of commands that can be used to convert the first file to the second file via the “ patch ” command CSCI UNIX and Network Programming26

Compress File Contents utilities to compress and uncompress files common on Linux: gzip, gunzip, zcat file extension:.gz Example: % gzip assign1.txt % zcat assign1.txt.gz % gunzip assign1.txt.gz Also: bzip2 better compression Windows compatible: zip/unzip CSCI UNIX and Network Programming27

Sorting Files Syntax: sort [options] file-name Commonly used options: -r sort in reverse order -n numeric sort -t field delimiter (default: blank) -k field1[,field2] -f ignore case CSCI UNIX and Network Programming28

User’s Disk Quota quota is upper limit of amount disk space number of files for each user account command: quota -v displays the user’s disk usage and limits 2 kinds of limits: Soft limit: ex. 100MB Maybe exceeded for one week System will nag Hard limit: ex. 120MB Cannot be exceeded CSCI UNIX and Network Programming29

Sending Files to the Printer Syntax: lpr [options] file option –P to specify printer: lpcsl (others: lpfrl) Example: % lpr –P lpcsl assign1.cc other commands: lpq show print job queue lprm remove job from queue CSCI UNIX and Network Programming30

Summary shell is traditional command line user interface hierarchical organization of files basic commands to list and manipulate files CSCI UNIX and Network Programming31