Lesson 7-Creating and Changing Directories. Overview Using directories to create order. Managing files in directories. Using pathnames to manage files.

Slides:



Advertisements
Similar presentations
Operating Systems File Management.
Advertisements

Pre-Assessment Questions
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 -
UNIX chapter 07 Files and File System Structure
Introduction to Unix (CA263) File System
Exploring the UNIX File System and File Security
Linux+ Guide to Linux Certification, Second Edition
Chapter 5 Accessing Files and Directories. How Directories Get Created OS installation: usr, dev, etc, export, kernel and others places to store installation.
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.
Guide To UNIX Using Linux Third Edition
Guide To UNIX Using Linux Third Edition
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.
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.
Guide To UNIX Using Linux Fourth Edition
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”
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.
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.
Lesson 11-Locating, Printing, and Archiving User Files.
Linux+ Guide to Linux Certification, Second Edition
Linux+ Guide to Linux Certification, Third Edition
Chapter Two Exploring the UNIX File System and File Security.
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.
Lesson 2-Touring Essential Programs. Overview Development of UNIX and Linux. Commands to execute utilities. Communicating instructions to the shell. Navigating.
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.
Chapter Two Exploring the UNIX File System and File Security.
ITR3 lecture 6: intoduction to UNIX Thomas Krichel
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
1 © 2001 John Urrutia. All rights reserved. Chapter 4 The LINUX Filesystem.
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.
Advanced Programming in the UNIX Environment Hop Lee.
Λειτουργικά Συστήματα – Lab2 Γιάννης Πετράκης. Directory Navigation and Control  The Unix file system is set up like a tree branching out from the root.
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.
1 Lecture 2 Working with Files and Directories COP 3353 Introduction to UNIX.
Agenda The Linux File System (chapter 4 in text)
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.
Isecur1ty training center Presented by : Eng. Mohammad Khreesha.
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.
The Kernel At a high level, the kernel in an operating system serves as the bridge between applications and the actual data processing of the hardware.
CSCI 330 UNIX and Network Programming Unit II Basic UNIX Usage: File System.
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.
Lesson 6-Using Utilities to Accomplish Complex Tasks.
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.
CMSC 104, Version 8/061L03OperatingSystems.ppt Operating Systems and Using Linux Topics What is an Operating System? Linux Overview Frequently Used Linux.
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
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.
Lecture 2 Working with Files and Directories
The Command Prompt Commands are the way to “do things” in Unix
UNIX System Overview.
Exploring the UNIX File System and File Security
Unix : Introduction and Commands
File System B. Ramamurthy B.Ramamurthy 11/27/2018.
The Unix File System.
Introduction Paul Flynn
Module 6 Working with Files and Directories
A shell is a user interface.
January 26th, 2004 Class Meeting 2
Presentation transcript:

Lesson 7-Creating and Changing Directories

Overview Using directories to create order. Managing files in directories. Using pathnames to manage files in directories. Accessing files in remote directories. Managing files from more than one directory. Moving and removing directories and their contents.

Using Directories to Create Order A file is a collection of information stored electronically on the hard drive of a system. An inode contains all the information about each file, including the location of the actual file on the disk.

Using Directories to Create Order The home directory. Listing files in a directory. Working with directories. Distinguishing between files and directories. Obtaining information about a directory or its contents.

The Home Directory The “pwd” command displays the path from root to the user’s home directory. The /etc/passwd file holds the user’s home directory path. A file is created and listed in the current home directory by default.

Listing Files in a Directory The “ls” command reads the names of the files listed in the current directory, and then outputs those names. Each file in the directory contains only the name of that file and a number that leads to the inode for that file. The “–i” option instructs ls to include the inodes in its output. Inodes are small pieces of memory created on the hard disk when it is formatted.

Listing Files in a Directory The inode has a list of addresses of the block on the disk where the data that comprise the file is actually located. It addresses up to 13 data blocks on the hard drive. The first ten blocks addressed from the inode contains the actual file data. If a file is too large, additional blocks are allocated to fit the data.

Working with Directories The “mkdir” command is used for creating a new directory. Directories created in uppercase are listed first by the ls command. Each new directory created is called a subdirectory. The “cd” or “change directory” command instructs the shell to locate the directory listed as an argument.

Working with Directories The “pwd” command outputs the absolute path from the top of the file system (root or /) to the current directory. A path is a list of directory names separated by the / (slash) character. The topmost directory is called the root and is symbolized by the first forward slash (/) in the pathname.

Working with Directories The vi editor can be used for creating a file within a directory or subdirectory. The cd command, without any directory name as an argument, returns to the home directory. The “–R” (recursive) option used with ls descends through each subdirectory in the directory tree.

Distinguishing between Files and Directories The “ls –F” command displays directory names with a slash appended at the end. Filenames displayed with an asterisk (*) at the end are executable files. The “–C” option to ls instructs ls to make several columns in the output instead of one.

Obtaining Information About a Directory or its Contents The “ls –l” command displays the permissions and owners of files listed in a directory. The “–d” option with ls command returns a listing of information about the contents of the target directory. The “ls –ld” displays the permissions of the directory, and not the information about the files.

Managing Files in Directories Moving or copying files into a subdirectory. Accessing a file in a subdirectory. Avoiding mistakes when moving files into directories. Renaming files. Removing files from subdirectories.

Moving or Copying Files into a Subdirectory Moving a file or directory does not move the file electronically. The name and the inode number are erased from the current directory and are written in the subdirectory.

Moving or Copying Files into a Subdirectory When a file is copied, a second electronic version is created. The copied file does not have the same inode number as the original. The copied file has its own inode, permission, and data blocks containing the new files actual contents.

Accessing a File in a Subdirectory To access a file in a subdirectory: Locate the inode number of the file. Check the permissions on the directory. Get the directory’s address from the inode. Identify the inode associated with the file. Read the files from the data blocks.

Avoiding Mistakes When Moving Files into Directories The mv utility takes two arguments. The first argument is the name of an existing file. The second argument is a new name assigned to existing file, unless the second argument is a directory. A slash at the end of the second argument interprets the argument as a directory name.

Renaming Files The command to move a file listing from the current directory to a new directory and also to change its filename is mv filename subdirectory/newfilename. Moving a file just moves its listing from one directory to another.

Removing Files from Subdirectories The “rm” command can be used for removing files form a directory or subdirectory. After the rm command, the entry of the file is removed, and the data blocks listed in the inode for that file are released.

Using Pathnames to Manage Files in Directories Accessing or creating a subdirectory. Using pathnames with utilities. Copying files into other directories using paths. Using parent directory names. Copying and moving multiple files to subdirectories. Examining the full path from root to directories and files.

Using Pathnames to Manage Files in Directories Explicitly accessing a user’s home directory. Including other users’ logins in directory paths. Returning to the previous directory.

Accessing or Creating a Subdirectory Providing a full path to the cd command without any spaces can access a subdirectory. Pathnames are the mechanism used to tell the shell what path to follow to access a file or directory not listed in the current directory. Remote directories can also be created by specifying the relative or absolute pathname.

Using Pathnames with Utilities Pathnames can also be used as arguments to utilities. A relative path can be specified for accessing a file without changing the current directory.

Copying Files into Other Directories Using Paths Pathnames are particularly useful with the “cp” and “mv” commands. Any command that takes a filename or directory name as an argument can be given an explicit pathname argument.

Using Parent Directory Names A single dot is used for referring to the current directory. In a directory, the.. (dot-dot) is the listing for its parent directory. The parent directory is the directory located one level above the current directory.

Using Parent Directory Names The parent directory lists the current directory’s name and inode. The. and.. are the two listings that get created when a new directory is created.

Copying and Moving Multiple Files to Subdirectories The move and copy commands are usually used with only two arguments. The cp utility displays a usage error message when more than two arguments are specified and the last argument is not a directory. In the cp command, if the third argument specified is a directory, then the rest of the file arguments are copied into the destination subdirectory.

Copying and Moving Multiple Files to Subdirectories The mv and cp commands can affect multiple files when the last argument is a directory. The.. (dot-dot) listing can be used in the mv command for moving files into the parent directory.

Examining the Full Path from Root to Directories and Files A user can specify a directory’s location with the full path from the top of the file system. The full path starting at root identifies a file explicitly. The pathname for every file describes a particular file uniquely and absolutely. The full pathname to a file is called its absolute pathname.

Explicitly Accessing a User’s Home Directory The “ls ~” command lists all filenames listed in the home directory. The C shell and all shells define the tilde (~) as the path to the user’s home directory. The shell replaces the tilde (~) with the value of the path to the user’s home directory. The shell replaces the tilde (~) in any command line with the absolute path from root to the user’s home directory.

Including Other Users’ Logins in Directory Paths The “echo ~root” option displays the path to the home directory of the user root. The contents of the home directory of a user are displayed if the user has appropriate permissions.

Returning to the Previous Directory The bash and ksh shells maintain the previous directory path as the value of a variable. The tcsh shell maintains a list of previous directories in a list that can be accessed. The value of the variable PWD is the path to the current directory.

Returning to the Previous Directory An alternative way of specifying the previous directory on many bash and ksh shells is to do it with a dash argument. The exit command can be used for exiting from a child bash or ksh to the login shell. The “popd” command instructs the shell to move the directory currently on the top of the list of directories that are added to the list.

Accessing Files in Remote Directories A filename that includes no relative path defaults to the current directory. The./ is the default relative path that is used. Every file on the system has a unique pathname from / (root).

Accessing Files in Remote Directories The “pwd” command displays the absolute path of the present directory. A path always starts at root (/) and includes the appropriate subdirectories.

Managing Files from More Than One Directory A listing for a file in a directory is a link to the file. The ls –l command at the start lists the number of data blocks used by files and directories in the current directory. In a long listing entry, or record, the information for each file or directory is divided into seven fields. The second field in each entry of a file indicates the number of directories where the object is listed.

Managing Files from More Than One Directory Linking files: The “ln” command can be used for linking a file to the current directory. The index card of each file keeps track of the number of directories that list it. Each instance of the file listed in a directory is one link. Removing a file removes it from the directory listing.

Managing Files from More Than One Directory Linking files (continued): The ln utility can be used to link multiple files at a time. The “ls –il” command lists the current files with link count and inodes. The “–s” option to ln creates a file in the current directory that contains information required to locate the linked file.

Managing Files from More Than One Directory Using symbolic links: A symbolic link is a small file in a directory on one file system partition that points to the correct file system and the correct inode for the linked file. In the long listing of the symbolic link, the initial character is an “l” for directories and files. An arrow and path at the end of the listing displays the actual directory where the link points.

Managing Files from More Than One Directory Using symbolic links (continued): The ln utility provides a “–d” option for the root user to create hard links to directories. Ordinary users cannot create directory hard links. Ordinary users can create symbolic links to directories.

Managing Files from More Than One Directory The administrator can divide the hard drive into partitions for installing the system. The partition labeled / holds the core of the hierarchal directory tree. A partition is further divided into small pieces called data blocks, which hold the actual data for the file.

Managing Files from More Than One Directory Each partition holds a single file system and has a set of unique inode numbers for that partition. The inode contains the whole of a file, including its descriptive characteristics and the addresses of the blocks where the file data resides.

Moving and Removing Directories and their Contents Renaming a directory only changes the name of the directory, the inode number and its location remains unchanged. A directory can also be moved from a different location in the hierarchal file structure without affecting the child contents of the directory.

The “rmdir” command is used for removing an empty directory. The “–r” option instructs the rm command to recursively remove file. Moving and Removing Directories and their Contents

Summary Files reside in one or more data blocks on the hard drive. Each file in a directory is assigned a unique inode. A directory is a special kind of file with very specific contents, namely the names of files and directories, each with its associated inode number. The passwd file holds the location of a user’s home directory.

Summary The mkdir command is used for creating remote directories. The tilde (~) is interpreted as the user’s home directory. The name.. (dot-dot) is interpreted as the parent directory. The “rm –r dirname” command recursively removes the contents of the directory specified.