Manage Directories and Files in Linux

Slides:



Advertisements
Similar presentations
POS/420 Philip Robbins – March 19, 2013 (Week 2) University of Phoenix Mililani Campus Introduction to Unix.
Advertisements

Linux Booting Procedure
Linux can be generally divided into four major components: 1. KERNEL – OS, ultimate boss The kernel is the core program that runs programs and manages.
A Guide to Unix Using Linux Fourth Edition
Pre-Assessment Questions
CS 497C – Introduction to UNIX Lecture 11: - The File System Chin-Chih Chang
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.
Introduction to Unix (CA263) File System
Exploring the UNIX File System and File Security
GNU/Linux Filesystem 1 st AUT GNU/Linux Festival Computer Engineering & IT Department Bahador Bakhshi.
Linux+ Guide to Linux Certification, Second Edition
Linux Linux File System.
The UNIX File System.
Guide To UNIX Using Linux Third Edition
File System and Directory Structure in Linux. What is File System In a computer, a file system is the way in which files are named and where they are.
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
Course materials may not be reproduced in whole or in part without the prior written permission of IBM. 5.1 © Copyright IBM Corporation 2008 Unit 4 Working.
1 THE UNIX FILE SYSTEM By Chokechai Chuensukanant ID COSC 513 Operating System.
The file structure and related utilities CS240 Computer Science II.
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.
Linux Filesystem Last Update Copyright Kenneth M. Chipps Ph.D. 1.
Unix Basics Chapter 4.
Linux+ Guide to Linux Certification, Second Edition
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.
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:
Manage Directories and Files in Linux. 2 Objectives Understand the Filesystem Hierarchy Standard (FHS) Identify File Types in the Linux System Change.
Chapter Two Exploring the UNIX File System and File Security.
ITR3 lecture 6: intoduction to UNIX Thomas Krichel
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
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.
Λειτουργικά Συστήματα – Lab2 Γιάννης Πετράκης. Directory Navigation and Control  The Unix file system is set up like a tree branching out from the root.
Linux Commands C151 Multi-User Operating Systems.
PTA Linux Series Copyright Professional Training Academy, CSIS, University of Limerick, 2006 © Workshop V Files and the File System Part B – File System.
Slide: 1 UNIX FILE SYSTEM By:Qing Yang ID: Operating System Research Topic December, 2000.
Linux Filesystem WeeSan Lee. Roadmap Disk Partitions The Filesystem Filesystem Mouting & Umounting File Tree File Type File Permission.
Chapter 10: File-System Interface Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Jan 1, 2005 File-System Interface.
The Unix File system (UFS) Presented by: Gurpreet Singh Assistant Professor Department of School of Computing and Engineering Galgotias University.
CS 245 – Part 1 Using Operating Systems and Networks for Programmers Jiang Guo Dept. of Computer Science California State University Los Angeles.
THE FILE SYSTEM Files long-term storage RAM short-term storage Programs, data, and text are all stored in files, which is stored on.
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.
UNIX File System By Vishal Desai. Introduction Basic purpose of file system: Represent and organize the system resources. But UNIX File System also maps.
SUSE Linux Enterprise Desktop Administration Chapter 7 Manage Directories and 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.
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.
Learning basic Unix command It 325 operating system.
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.
LINUX Zhengli Zhu, School of Life Sciences. Outline 1. ABC of Linux 2. Basic orers of Linux 3. Bash Programming.
ORAFACT The Linux File System. ORAFACT Filesystem Support Support for dozens of filesystem types including: Minix, ext2, MS-DOS, UMSDOS, VFAT, NTFS, NFS,
Agenda The Linux File System (chapter 4 in text) Directory Structures / Navigation Terminology File Naming Rules Relative vs Absolute pathnames Unix Commands:
Linux Administration – Finding You Way on the Command Line The Linux File Directory or Tree.
BILKENT UNIVERSITY DEPARTMENT OF COMPUTER TECHNOLOGY AND INFORMATION SYSTEMS CTIS156 INFORMATION TECHNOLOGIES II FILES AND FILE SYSTEM STRUCTURE.
Filesystem Management and Backups
Linux 101 Training Module Linux Basics.
Linux file system "On a UNIX system, everything is a file;
Chapter 6 File Systems CSNB113 SYSTEM ADMINISTRATION
C151 Multi-User Operating Systems
9 Linux on the Desktop.
Exploring the UNIX File System and File Security
Chapter 7 File and file System structure
Chapter 4: The Linux Filesystem
January 26th, 2004 Class Meeting 2
Presentation transcript:

Manage Directories and Files in Linux

Objectives Understand the Filesystem Hierarchy Standard (FHS) Identify File Types in the Linux System Change Directories and List Directory Contents Create and View Files Manage Files and Directories Find Files Search File Content

Understand the Filesystem Hierarchy Standard (FHS) The file system concept of Linux (and, in general, of all UNIX systems) is considerably different than that of other operating systems To understand the concept of the Linux file system, you need to know the following: The Hierarchical Structure of the File System FHS (Filesystem Hierarchy Standard) Root Directory / Essential Binaries for Use by All Users (/bin/) Boot Directory (/boot/)

Understand the FHS (continued) To understand the concept of the Linux file system, you need to know the following (continued): Device Files (/dev/) Configuration Files (/etc/) User Directories (/home/) Libraries (/lib/) Mount Points for Removable Media (/media/*) Application Directory (/opt/) Home Directory of the Administrator (/root/) System Binaries (/sbin/) Data Directories for Services (/srv/)

Understand the FHS (continued) To understand the concept of the Linux file system, you need to know the following (continued): Temporary Area (/tmp/) The Hierarchy below /usr/ Variable Files (/var/) Process Files (/proc/) System Information Directory (/sys/) Mount Point for Temporarily Mounted File Systems (/mnt/) Directories for Mounting Other File Systems

The Hierarchical Structure of the File System

The Hierarchical Structure of the File System (continued)

FHS (Filesystem Hierarchy Standard) The structure of the file system is described in the Filesystem Hierarchy Standard (FHS) It specifies which directories must be located on the first level after the root directory and what they contain It does not specify all details FHS defines a two-layered hierarchy The directories in the top layer (immediately below the root directory “/”) As a second layer, the directories under /usr/ and /var/

Root Directory / The root directory refers to the highest layer of the file system tree Only directories are located here, not files When the system is booted, the partition on which this directory is located is the first one mounted All programs that are run on the system start must be available on this partition The following directories always have to be on the same partition as the root directory: /bin/, /dev/, /etc/, /lib/, and /sbin/

Essential Binaries for Use by All Users (/bin/)

Boot Directory (/boot/) /boot/ contains static files of the boot loader These are files required for the boot process (with the exception of configuration files) The backed-up information for the Master Boot Record (MBR) and the system map files are also stored here These contain information about where exactly the kernel is located on the partition This directory also contains the kernel According to FHS, the kernel can also be located directly in the root directory

Device Files (/dev/) Each hardware component existing in the system is represented as a file in /dev/ The hardware components are addressed via these files by writing or reading to or from one of the files. Two types of Device Files Exist: Character special files (or character devices) ‘talks’ to device character-by-character (1 byte at a time) Examples: printer, virtual terminals, serial devices Block special files (or block devices) ‘talks’ to device 1 block at a time (1 block can be 512bytes to 312KB) Examples: Hard disk, floppy disk, CD burners.

Device Files (/dev/, continued)

Device Files (/dev/, continued)

Configuration Files (/etc/)

User Directories (/home/) Every user on a Linux system has his own area in which to create and remove files: its home directory Individual configuration files can be found in the user’s home directory If there are no special settings, the home directories of all users are located beneath /home/ The home directory of a user be addressed via “~”

Libraries (/lib/) Shared libraries are removed from the actual program, stored in the system, and only called up when the program runs The directory /lib/ contains the libraries that are used by programs in the directories /bin/ and /sbin/ The kernel modules (hardware drivers not compiled into the kernel) are located in the directory /lib/modules/ You can find additional libraries below the directory /usr/

Mount Points for Removable Media (/media/*) OpenSuse creates directories such as the following in the directory /media/ (depending on your hardware) for mounting removable media: /media/cdrom/ /media/cdrecorder/ /media/dvd/ /media/floppy/

Home Directory of the Administrator (/root/) The home directory of the system administrator is not located beneath /home/ like that of a normal user Preferably, it should be on the same partition as the root directory,“/” Only then is it guaranteed that the user root can always log in without a problem and have her own configured environment available

System Binaries (/sbin/) Contains important system administration programs Programs in /sbin/ can also, as a rule, be run by normal users, but only to display configured values

System Binaries (/sbin/, continued)

Data Directories for Services (/srv/) The directory /srv/ contains subdirectories filled with data of various services For example: The files of the Apache web server are located in the directory /srv/www/ The FTP server files are located in the directory /srv/ftp/

Temporary Area (/tmp/) Various programs create temporary files that are stored in /tmp/ until they are deleted The Hierarchy below /usr/ According with the FHS, represents a second hierarchical layer

Variable Files (/var/) Contains a hierarchy described in the FHS This directory and its subdirectories contain files that can be modified while the system is running

Variable Files (/var/, continued)

System Information Directory (/sys/) The directory /sys/ provides information in the form of a tree structure on various hardware buses, hardware devices, active devices, and their drivers

Mount Point for Temporarily Mounted File Systems (/mnt/) Standard directory for integrating file systems It should only be used for temporary purposes da10:~ # mount /dev/hda7 /mnt da10:~ # umount /mnt If you do not include any options with mount, the program tries out several file system formats To specify a specific file system, use the option -t If the file system format is not supported by the kernel, the command is aborted, and you receive an error message In this case, you must compile a new kernel that supports the file system format

Directories for Mounting Other File Systems A directory must exist at the point where you intend to mount the file system This directory is referred to as the mount point In most cases, only the user root can mount and unmount directories Use mount and umount If you mount a file system to a non-empty directory, existing contents of directory will not be accessible Mounted file system does not have to be on a local hard disk

Directories for Mounting Other File Systems (continued) The directories listed below cannot be imported from other machines Some of the directories that can be shared are:

Automated Mounting of Removable Media In past versions of Linux, it was necessary to mount removable media with some command to access them and to unmount them afterwards This has been automated in current kernel versions

Identify File Types in the Linux System The file types in Linux referred to as normal files and directories are also familiar to other operating systems Normal Files Directories Additional types of files are UNIX-specific Device Files Links Sockets FIFOs

Normal Files Normal files: a set of contiguous data addressed with one name This includes all the files normally expected under this term (such as ASCII texts, executable programs, or graphics files) You can use any names you want for these files—there is no division into filename and file type A number of filenames still retain this structure, but these are requirements of the corresponding applications, such as a word processing program or a compiler

Directories Directories contain two entries with which the structure of the hierarchical file system is implemented One of these entries (“.”) points to the directory itself The other entry (“..”) points to the entry one level higher in the hierarchy

Device Files Each piece of hardware (with the exception of network cards) in a Linux system is represented by a device file These files represent links between the hardware components or the device drivers in the kernel and the applications Every program that wants to access hardware must access it through the corresponding device file The programs write to or read from a device file The kernel then ensures that the data finds its way to the hardware or can be read from the file

Links Links are references to files located at other points in the file system Data maintenance is simplified through the use of such links Changes only need to be made to the original file The changes are then automatically valid for all links

Sockets A socket refers to a special file with which data exchange between two locally running processes can be implemented through the file system FIFOs FIFO (first in first out) or named pipe is a term used for files used to exchange data between processes The file can exchange data in one direction only

Change Directories and List Directory Contents The prompt of a shell terminal contains the current directory (such as tux@da10:~) The tilde (~) indicates that you are in the user’s home directory Commands: ls cd pwd

ls

cd cd: change directory

pwd pwd: print working directory pwd -P prints the physical directory without any symbolic links

Create and View Files To create and view files, you need to know how to do the following: Create a New File with touch View a File with cat View a File with less View a File with head and tail

Create a New File with touch touch: changes the time stamp of a file or creates a new file with a size of 0 bytes

Create a New File with touch (continued)

View a File with cat You can use cat to view the contents of a file Comparable to the command “type” in DOS The command must include the filename of the file you want to see

View a File with less less displays the contents of a file page by page Even compressed files (such as .gz and .bz2) can be displayed

View a File with head and tail Used to view the first or last lines of a file By default, they show ten lines head -20 displays the first twenty lines tail -f displays a continuously updated view of the last lines of a file

Manage Files and Directories In this objective, you learn how to: Copy and Move Files and Directories Create Directories Delete Files and Directories Link Files

Copy and Move Files and Directories (continued) To copy the contents of proposals/ and all its files, including hidden files and subdirectories, to the existing directory proposals_old/: To avoid copying the hidden files, do the following:

Copy and Move Files and Directories (continued)

Create Directories You can use the command mkdir (make directory) to create new directories mkdir proposal Use the option -p to create a complete path mkdir -p proposal/january

Delete Files and Directories Use rmdir to delete empty directories rmdir proposal Use rm to delete files and directories rm part* To delete directories (even if not empty) rm –r testdir You can use the two options in Table 5-17 with rm User must have permission to delete file(s)

Link Files Each file is described by an inode To see the inode number you can enter ls –I Each inode has a size of 128 bytes An inode contains all the information about the file besides the filename Link: a reference to a file Create a hard link using ln, which points to the inode of an already existing file Hard links can only be used when both the file and the link are in the same file system Create a symbolic link using ln –s; a symbolic link is assigned its own inode

Link Files (continued)

Link Files (continued) A symbolic link can point to a non-existing object if the object and its corresponding name no longer exist For example, if you erase the file old in the preceding example, in OpenSuse new will be shown in a different color in the output of ls, indicating that it points to a non-existent file An advantage of symbolic links is that you can create links to directories

Find Files In this objective you learn how to find files and programs using the following commands: KFind find locate whereis which type command

KFind

KFind (continued) Table 5-18 shows the results of three different search strings

KFind (continued) Use to narrow search

find Usage: find path criteria action

find (continued) Examples: find / -name game Looks for a file named "game" starting at the root directory (searching all directories including mounted filesystems). The `-name' option makes the search case sensitive. You can use the `-iname' option to find something regardless of case. find /home -user joe Find every file under the directory /home owned by the user joe. find /usr -name *stat Find every file under the directory /usr ending in "stat". find /var/spool -mtime +60 Find every file under the directory /var/spool that was modified more than 60 days ago.

locate locate is an alternative to find –name Examples: The package findutils-locate must be installed find can be quite slow locate searches through a database previously created (/var/lib/locatedb), making it much faster The database is automatically created and updated daily by OpenSuse Use updatedb to update it manually Examples: locate letter_Miller locate umount

locate

whereis whereis returns the binaries (option -b), manual pages (option -m), and the source code (option -s) of the specified command If no option is used, all this information is returned, if the information is available whereis is faster than find, but it is less thorough Example:

which which searches all paths listed in the variable PATH for the specified command and returns the full path of the command It is especially useful if several versions of a command exist in different directories and you want to know which version is executed when entered without specifying a path

type command type command can be used to find out what kind of command is executed when command is entered—a shell built-in command or an external command The option -a delivers all instances of a command bearing this name in the file system