COMP1070/2002/lec4/H.Melikian COMP1070 Lecture #5  Files and directories in UNIX  Various types of files  File attributes  Notion of pathname  Commands.

Slides:



Advertisements
Similar presentations
Pre-Assessment Questions
Advertisements

UNIX chapter 07 Files and File System Structure
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.
ATS Programming Short Course I INTRODUCTORY CONCEPTS Tuesday, Jan. 27 th, 2009 Essential Unix Commands.
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
CSE 303 Lecture 2 Introduction to bash shell
Unix Basics. Systems Programming: Unix Basics 2 Unix Basics  Unix directories  Important Unix file commands  File and Directory Access Rights through.
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.
Basic UNIX © McGraw Hill All rights reserved.
7/17/2009 rwjBROOKDALE COMMUNITY COLLEGE1 Unix Comp-145 C HAPTER 2.
A Mini UNIX Tutorial. What’s UNIX?  An operating system run on many servers/workstations  Invented by AT&T Bell Labs in late 60’s  Currently there.
CS 141 Labs are mandatory. Attendance will be taken in each lab. Make account on moodle. Projects will be submitted via moodle.
Systems Programming Concepts
Learning basic Unix command IT 325 operating system.
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 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.
2 Manual & Filestore. Introduction Using the manual The UNIX filestore File permissions.
Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell.
1 Lecture 2 Working with Files and Directories COP 3344 Introduction to UNIX.
Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell.
Unix Basics Chapter 4.
Title Slide CSS 404/504 The UNIX Operating System (2) By Ralph B. Bisland, Jr.
Linux+ Guide to Linux Certification, Second Edition
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.
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.
Second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX Commands cal – will print a calendar.
Chapter Two Exploring the UNIX File System and File Security.
ITR3 lecture 6: intoduction to UNIX Thomas Krichel
UNIX An Introduction. Brief History UNIX UNIX Created at Bell Labs, 1969 Created at Bell Labs, 1969 BSD during mid 70s BSD during mid 70s AT&T began offering.
Linux+ Guide to Linux Certification, Third Edition
Linux+ Guide to Linux Certification, Third Edition
1 © 2001 John Urrutia. All rights reserved. Chapter 4 The LINUX Filesystem.
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.
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.
1 Lecture 2 Working with Files and Directories COP 3353 Introduction to UNIX.
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.
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.
Learning basic Unix command It 325 operating system.
Scripting Languages Course 1 Diana Trandab ă ț Master in Computational Linguistics - 1 st year
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.
Learning Unix/Linux Based on slides from: Eric Bishop.
Agenda The Linux File System (chapter 4 in text)
Tutorial of Unix Command & shell scriptS 5027
Linux 101 Training Module Linux Basics.
Lecture 2 Working with Files and Directories
Some Linux Commands.
File and File System Structure
C151 Multi-User Operating Systems
The Command Prompt Commands are the way to “do things” in Unix
Introduction to Unix: Fundamental Commands
CSE 374 Programming Concepts & Tools
Tutorial of Unix Command & shell scriptS 5027
Tutorial of Unix Command & shell scriptS 5027
Exploring the UNIX File System and File Security
Tutorial of Unix Command & shell scriptS 5027
Module 6 Working with Files and Directories
January 26th, 2004 Class Meeting 2
Presentation transcript:

COMP1070/2002/lec4/H.Melikian COMP1070 Lecture #5  Files and directories in UNIX  Various types of files  File attributes  Notion of pathname  Commands manipulating files and directories

COMP1070/2002/lec4/H.Melikian Files and Deroctories File related operations create, read, write, modify and execute File – sequence of bytes. Directories, network cards, disk drives, a keyboard, a printer also are files Types of files simple./ ordinary directory symbolic(soft) links special files(device) named Pipe (FIFO)

COMP1070/2002/lec4/H.Melikian Directory File names 14 – 256 characters (System v ) Extensions - name.extension like prog.c, letter.doc, pine.exe A Directory contains the names of other files and/or directories ( subdirectories)- folder

COMP1070/2002/lec4/H.Melikian File system Organization The UNIX file system is structured hierarchically ( upside down treelike). It starts at root directory ( / ) and goes down. When you login the unix puts you in a specidic dir, called home or login directory ( specified in c shell by ~ ) Pwd – present working directory or current directory

COMP1070/2002/lec4/H.Melikian Pathnames Files are specified by pathname. There are three ways to specify pathname 1. Starting with the root directory( absolute) 2. Starting with the pwd 3. Starting users home directory (relative ) Standard directories and files Root ( /), /bin ( binary executables), /dev, /etc (for system admin) /lib, /tmp, /users, /usr ( UNIX utilities, manuals) /var ( mails..) /etc/passwd file contains one line foe every user.

COMP1070/2002/lec4/H.Melikian Navigating the file system Command to browse file system: cd[directory], ls[option][pathname-list], pwd Hidden files.,.., addressbook,.cshrc,.login,.pinerc,.profile...

COMP1070/2002/lec4/H.Melikian Creating and removing files (Directories) You can create file using various editors containing plane text or specific application tools (compilers)to create nontext file. To create directory we use mkdir command mkdir [option]dirname To remove directory we use rmdir command rmdir[options]dirname Options: –r and -p

COMP1070/2002/lec4/H.Melikian Determining file Attributes Ttype % ls -l (l for long listing!)You will see long listing of files with various options.

COMP1070/2002/lec4/H.Melikian Access rights on files r (or -), indicates read permission (or otherwise), that is, the presence or absence of permission to read and copy the file w (or -), indicates write permission (or otherwise), that is, the permission (or otherwise) to change a file x (or -), indicates execution permission (or otherwise), that is, the permission to execute a file, where appropriate Access rights on directories. r allows users to list files in the directory; w means that users may delete files from the directory or move files into it; x means the right to access files in the directory. This implies that you may read files in the directory provided you have read permission on the individual files.

COMP1070/2002/lec4/H.Melikian Changing access rights chmod (changing a file mode) Only the owner of a file can use chmod to change the permissions of a file. The options of chmod are as follows Symbol Meaning u user, g group, o other a all r read, w write (and delete) x execute (and access dir) +add permission - take away permission For example, to remove read write and execute permissions on the file biglist for the group and others, type % chmod go-rwx letter.txt This will leave the other permissions unaffected. To give read and write permissions on the file letter.txt to all, % chmod a+rw letter.txt

COMP1070/2002/lec4/H.Melikian Default File Access Privileges Octal representation of file privileges r – 4, w –2, x – 1 wre = 4+2+1=7 or Example: % chmode 755 letter.txt umask[ mask]- sets access permission bit on newly created files and directories. File access permition = 777 – mask where mask is octal number Commonly use mask is 022 Hence default access permission is set to 755 To display the current value of mask % unmask 022 %

COMP1070/2002/lec4/H.Melikian Copying Files cp (copy) % cp file1 file2 is the command which makes a copy of file1 in the current working directory and calls it file2 What we are going to do now, is to take a file stored in an open access area of the file system, and use the cp command to copy it to your unixstuff directory. First, cd to your unixstuff directory. % cd ~/unixstuff

COMP1070/2002/lec4/H.Melikian Moving files mv (move) mv file1 file2 moves (or renames) file1 to file2 To move a file from one place to another, use the mv command. This has the effect of moving rather than copying the file, so you end up with only one file rather than two. It can also be used to rename a file, by "moving" the file to the same directory, but giving it a different name. We are now going to move the file science.bak to your backup directory. First, change directories to your unixstuff directory (can you remember how?). Then, inside the unixstuff directory, type % mv science.bak backups/. Type ls and ls backups to see if it has worked.

COMP1070/2002/lec4/H.Melikian Removing files and directories rm (remove), rmdir (remove directory) To delete (remove) a file, use the rm command. As an example, we are going to create a copy of the science.txt file then delete it. Inside your unixstuff directory, type % cp science.txt tempfile.txt % ls (to check if it has created the file) % rm tempfile.txt % ls (to check if it has deleted the file) You can use the rmdir command to remove a directory (make sure it is empty first). Try to remove the backups directory. You will not be able to since UNIX will not let you remove a non-empty directory.

COMP1070/2002/lec4/H.Melikian Simple searching using less Using less, you can search though a text file for a keyword (pattern). For example, to search through science.txt for the word science, type % less science.txt then, still in less (i.e. don't press q to quit), type a slash followed by the word to search /science As you can see, less finds and highlights the keyword. Type n to search for the next occurrence of the word.

COMP1070/2002/lec4/H.Melikian Simple searching using grep grep is one of many standard UNIX utilities. It searches files for specified words or patterns. First clear the screen, then type % grep science science.txt As you can see, grep has printed out each line containing the word science % grep Science science.txt The grep command is "case sensitive"; it distinguishes between Science and science. To ignore upper/lower case distinctions, use the -i option, i.e. type % grep -i science science.txt To search for a phrase or pattern, you must enclose it in single quotes (the apostrophe symbol). For example to search for spinning top, type % grep -i 'spinning top' science.txt Some of the other options of grep are: -v display those lines that do NOT match -n precede each matching line with the line number -c print only the total count of matched lines % grep -ivc science science.txt

COMP1070/2002/lec4/H.Melikian Summary cp file1 file2 copy file1 and call it file2 mv file1 file2 move or rename file1 to file2 rm file remove a file rmdir directory remove a directory cat file display a file more file display a file a page at a time head file display the first few lines of a file tail file display the last few lines of a file grep 'keyword' file search a file for keywords wc file count number of lines/words/characters in file

COMP1070/2002/lec4/H.Melikian HW #2 1. Write a short description of the following UNIX commands using man utility then send it to me. chmod, grep,, rm, cat. 2. Use script program on UNIX, to write your unix season into the file called typrscript( by default). You working season must include implementation of all the listed command with their most common options Assigned 09/16/02 Due 09/23/02 by midnight 12:00 (p.m.) PS. To submit you have to use the fallowing command % mail melikian< typescript

COMP1070/2002/lec4/H.Melikian A typical UNIX file system structure