1 Lecture 2 Working with Files and Directories COP 3353 Introduction to UNIX.

Slides:



Advertisements
Similar presentations
Pre-Assessment Questions
Advertisements

©Colin Jamison 2004 Introduction to Linux Colin Jamison.
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.
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
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.
Linux+ Guide to Linux Certification, Second Edition
CS 497C – Introduction to UNIX Lecture 12: - The File System Chin-Chih Chang
Linux Files. Files and directories As in Windows directories are structures which contain –Other directories –Files.
Guide To UNIX Using Linux Third Edition
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.
Using Linux Commands Lab 4. Using the Shell in Linux Commands Syntax  Options: could be added to the commands to change their behavior (-a, -la, --help)
Basic UNIX © McGraw Hill All rights reserved.
L INUX C OMMAND L INE I NTERFACE G UNAANBAN.G
Learning basic Unix command IT 325 operating system.
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
File Systems Sources and Resources: 1. A Students Guide to UNIX, by Hahn 2. Paula Davidson’s Handout on UNIXHandout on UNIX.
1 THE UNIX FILE SYSTEM By Chokechai Chuensukanant ID COSC 513 Operating System.
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 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ı.
Linux Directory Navigation. File & Directory Commands This is a minimal list of Unix commands that you must know for file management: ls (list) mkdir.
1 Lecture 2 Working with Files and Directories COP 3344 Introduction to UNIX.
Unix Basics Chapter 4.
Linux+ Guide to Linux Certification, Second Edition
The UNIX development environment CS 400/600 – Data Structures.
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.
UNIX Commands. Why UNIX Commands Are Noninteractive Command may take input from the output of another command (filters). May be scheduled to run at specific.
Lesson 9-Setting and Using Permissions. Overview Describing file permissions. Using execute permissions with a file. Changing file permissions using mnemonics.
1 Operating Systems and Using Linux Topics What is an Operating System? Linux Overview Frequently Used Linux Commands Reading None.
BIF713 Basic Unix/Linux Commands Getting Help with Commands.
Chapter Two Exploring the UNIX File System and File Security.
Chapter 4: File Security & Permissions Also: Hard and Soft Links, see p77-80 &
Intro to UNIX Presented by: Student Ambassadors: Lauren Lewis Martin Sung.
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.
Using Linux Commands Lab 4. Using the Shell in Linux Commands Syntax  Options: could be added to the commands to change their behavior (-a, -la, --help)
Λειτουργικά Συστήματα – Lab2 Γιάννης Πετράκης. Directory Navigation and Control  The Unix file system is set up like a tree branching out from the root.
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 2a – A Unix Command Sampler (Courtesy of David Notkin, CSE 303)
Linux Commands C151 Multi-User Operating Systems.
2 Manual & Filestore Mauro Jaskelioff. Introduction Using the manual The UNIX filestore File permissions.
Files and Directories in UNIX The first file in UNIX file system is “root” or “/”
UNIX filesystem CS 2204 Class meeting 2 *Notes by Doug Bowman and other members of the CS faculty at Virginia Tech. Copyright
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.
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.
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).
Chapter 2: Exploring the UNIX File System (For Tuesday Section) File and File Systems.
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.
CMSC 104, Version 8/061L03OperatingSystems.ppt Operating Systems and Using Linux Topics What is an Operating System? Linux Overview Frequently Used Linux.
CMSC 104, Version 9/011 Operating Systems and Using Linux Topics What is an Operating System? Linux Overview Frequently Used Linux Commands Reading None.
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
The Command Prompt Commands are the way to “do things” in Unix
Basic UNIX OLC Training.
Using Linux Commands Lab 3.
Exploring the UNIX File System and File Security
The Unix File System.
Module 6 Working with Files and Directories
January 26th, 2004 Class Meeting 2
Presentation transcript:

1 Lecture 2 Working with Files and Directories COP 3353 Introduction to UNIX

2 Files –A well defined repository of information Program or component of a program Arbitrary text An executable (binary text)‏ –Special files called directories contain or point to other files Structure of Directories –Hierarchically structured like an inverted tree –/ is the starting directory or “root” Pathnames –Locating a file by following a sequence of directories until you reach the file –/ is also the separator between the directories and final file

3 Example set of directories and files binhomeetc listerrimmerkryten HologramshipsGuitarBazookoid Starbug /

4 More on pathnames Absolute pathnames start at root –/home/lister/ships/Starbug –/bin Relative pathnames start at current directory –Suppose current directory is “home”, then: –rimmer/Hologram would refer to the same file as: –/home/rimmer/Hologram Special symbols for current directory and parent –“..” refers to parent directory (the directory “above”) –“.” is current directory Referencing user directories – ~rimmer is the absolute pathname to the user directory “rimmer” (in the directory “home” in this example) – ~/ is shorthand for the absolute path to your own user directory

Try these examples: Suppose: –your username is “lister” –your current directory is “ships” Write the absolute pathnames for: –bin –Guitar Write the relative pathnames for: –Starbug –home –Guitar –rimmer Where could you use directory references? (~)

6 UNIX Commands Commands typically refer to a Unix program located, for example, in /usr/bin –Structure of a command is typically: commandname [flags] [parameters] Flags –Commands may accept one or more flags –Flags start with “-” and are separated from other flags and parameters by one or more spaces –Individual flags may be combined under a single ‘–’ Parameters –Parameters are often filenames and/or pathnames –Commands accept one or more parameters, separated by spaces

7 Examples ls –a –l ls –al cp /home/albert/cprogram sources cp../testfiles/part1. wc –c –l thatfile

8 Some file commands ls list files cat view file contents more view file contents (pause each screen)‏ touch creates file / updates time stamp cp copy file to a new file mv move file to a new directory, rename file rm delete file

9 Some directory commands pwd display absolute pathname to current directory mkdir create directory rmdir remove directory cd navigate directories

10 Some useful commands pwd –Prints the absolute pathname of the current directory ls –al –The ls command lists the files in a directory. The a flag displays all the files. The l flag gives detailed information. touch –The touch commands creates an empty file or updates the timestamp of an existing file cp –The copy command copies the contents of a file or directory to another file or directory (two parameters). The i flag asks before it replaces an existing file; the r flag recursively copies all subdirectories also.

11 Useful commands continued mv –The move command renames a file (it takes two arguments)‏ –mv oldfilename newfilename –If the second argument is a directory it moves it to that directory wc –Counts the characters, lines, or words in a file –wc –w essay cd –Changes the current directory to another one –cd assignment1 –cd.. –cd../assignment1 passwd –Run this to change your password

12 Useful commands continued man –Man pages, short for manual pages. –All UNIX and unix-like OS have this documentation application. –Similar to help, is self contained for each command. Command --help –All command have a help menu that can be accessed. –Simple to complex explanation flags and parameters

13 Characters in filenames File names can contain any characters except “/”, but it is recommended that you use upper or lower case letters, numbers, and the characters “-” “.” For example although a file name could contain a space or spaces: confusing name commands using this would not work correctly unless you tell the shell to not break an argument at the spaces by quoting the filename. rm “confusing name”

14 File Permissions 3 types of processes can access a file –user or owner: process spawned by user who created file –group: process spawned by members of the same group –other: process spawned by anyone else Permission types –read: access file or list directory –write: write to / remove file (directory)‏ –execute: run file as a program or enter directory

15 Example Output Current permissions can be viewed using ls -l –First line is the number of disk blocks ( 1 block is 512 bytes) taken up by all the files scop3344]$ ls -al total 596 drwxr-xr-x 3 sudhir fac 4096 Jan 22 17:38. drwxr-xr-x 11 sudhir fac 4096 Jan 3 18:30.. -rw-r--r-- 1 sudhir fac 4631 Jan 18 16:10 Assignment1.txt drwxr-xr-x 3 sudhir fac 4096 Jan 9 17:07 index_files -rw-r--r-- 1 sudhir fac Jan 22 17:35 index.html -rw-r--r-- 1 sudhir fac Jan 18 10:51 Lecture1.pdf -rw-r--r-- 1 sudhir fac Jan 16 09:05 Lecture2.pdf -rw-r--r-- 1 sudhir fac Jan 22 17:24 Lecture3.pdf scop3344]$

16 Columns in the Display First entry in a line is the mode –The first character is d for directory, else - for a normal file –The remain 9 characters in groups of 3 are r, w, x permissions for user, group and other respectively (- indicates not having that permission)‏ Second entry indicates number of links to the file (usually 1)‏ Third entry is the user id of owner and the fourth entry is the group id Fifth entry is the number of bytes of the file Sixth entry is the date the file was last modified

17 Changing Permissions Using the chmod command to set permissions –Numeric (using octal)‏ Directly set the permissions for u, g, o using each 3 bit value as an octal value chmod 754 lecture1.pdf will set to or rwx r-x r-- chmod 700 lecture1.pdf will set to or rwx chmod 644 lecture1.pdf will set to or rw- r-- r--

18 Changing Permissions (cont)‏ –Symbolic Format: chmod [who] [operation] [permissions] who is one or more of u, g, o operation is + (add), - (remove), = (set)‏ Permissions are one or more of r, w, x Examples chmod go-rwx myfile.doc chmod g+w myfile.doc chmod u=rwx,g=rx,o=r myfile.doc

19 Wildcards an asterisk “*” matches any number of characters in a filename –con* will match con, condor, constant.exe –*.c will match all files that end in.c –rm * will remove all the files in a directory a “?” matches any single character in a filename –b?t will match bit, bot, bat. It will not match bt or boot square brackets “[]” will match any one of the characters in the brackets. A hyphen “-” can be used to match any of a range of consecutive characters. –[bhr]at will match bat, hat and rat –chap[5-8].c will match chap5.c, chap6.c, chap7.c and chap8.c