910 likes | 1.08k Views
Introduction to the Unix operating system CIS 118 Jeff Moro. Presentation 2: Disk and Filesystems April 2, 2008 Linda Sutherland. Disk and Filesystem du df free mount umount pwd. Disk and Filesystem in Linux.
E N D
Introduction to the Unix operating systemCIS 118 Jeff Moro Presentation 2: Disk and Filesystems April 2, 2008 Linda Sutherland
Disk and Filesystem in Linux • "On a UNIX system, everything is a file; if something is not a file, it is a process.“ • To keep things simple, saying that everything is a file is an acceptable generalization
Disk and Filesystem in Linux • A Linux system makes no difference between a file and a directory, since a directory is just a file containing names of other files. • Programs, services, texts, images, and so forth, are all files. • Input and output devices, and generally all devices, are considered to be files, according to the system.
Disk and Filesystem in Linux • In order to manage all those files in an orderly fashion, we like to think of them in an ordered tree-like structure on the hard disk, as we think of MS-DOS file structure for example • We can use this image of the tree, even if this is not a fully accurate image
Disk and Filesystem • Most files are just files, called regular files • They contain normal data, for example text files, executable files or programs, input for or output from a program and so on.
Disk and Filesystems in Linux Other types of files: • Directories: files that are lists of other files • Special files: the mechanism used for input and output. Most special files are in /dev • Links: a system to make a file or directory visible in multiple parts of the system's file tree
Disk and Filesystems in Linux Other types of files: • (Domain) sockets: a special file type, similar to TCP/IP sockets, providing inter-process networking protected by the file system's access control. • Named pipes: act more or less like sockets and form a way for processes to communicate with each other, without using network socket semantics
Disk and Filesystems in Linux • Partitions: • Another part of the file structure is partitions • Linux uses more than one partition on the same disk • One of the goals of having different partitions is to achieve higher data security in case of disaster
Disk and Filesystems in Linux • By dividing the hard disk in partitions, data can be grouped and separated. • When an accident occurs, only the data in the partition that got the hit will be damaged, while the data on the other partitions will most likely survive.
Disk and Filesystem in Linux There are two kinds of major partitions on a Linux system: • data partition: normal Linux system data, and • swap partition: expansion of the computer's physical memory, extra memory on hard disk.
Disk and Filesystems in Linux • Most systems contain • a root partition (which holds all the data to start up and run the system) , • one or more data partitions • and one or more swap partitions
Disk and Filesystems in Linux • Linux supports a variety of other file system types • Systems in mixed environments may contain partitions for other system data, such as a partition with a FAT or VFAT file system for MS Windows data
Disk and Filesystems in Linux • The standard root partition or root directory is indicated with a single forward slash / • It contains all other directories and files on the system, including
Disk and Filesystems in Linux • the system configuration files • most basic commands and server programs • system libraries • some temporary space • the home directory of the administrative user
Disk and Filesystems in Linux • Swap space (indicated with swap) is only accessible for the system itself, and is hidden from view during normal operations • Swap space is the portion of the hard dive used as temporary memory by Linux systems • Swap is the system that ensures that you can keep on working, whatever happens
Disk and Filesystems in Linux • In many distributions, the kernel is on a separate partition as well because it is the most important file of your system • If this is the case, you will find that you also have a /boot partition, holding your kernel and accompanying data files
Disk and Filesystems in Linux • The rest of the hard disk is generally divided in data partitions, although it may be that all of the non-system critical data resides on one partition, for example when you perform a standard workstation installation
Disk and Filesystems in Linux • When non-critical data is separated on different partitions, it usually happens following a set pattern
Disk and Filesystem in Linux • a partition for user programs (/usr) • a partition containing the users' personal data (/home) • a partition to store temporary data like print- and mail-queues (/var) • a partition for third party and extra software (/opt)
Disk and Filesystems in Linux • Once the partitions are made, changing sizes or properties of existing partitions is possible with appropriate software.
Disk and Filesystems in Linux • The division of hard disks into partitions is determined by the system administrator. • On larger systems, he or she may even spread one partition over several hard disks • Most distributions allow for standard setups optimized for workstations (average users) and for general server purposes
Disk and Filesystems in Linux • A workstation or client installation is for use by mainly one and the same person. • The selected software for installation reflects this and the stress is on common user packages, such as nice desktop themes, development tools, client programs for E-mail, multimedia software, web and other services.
Disk and Filesystems in Linux • Everything is put together on one large partition, providing the largest amount of disk space possible for personal use, but with the disadvantage of possible data integrity loss during problem situations
Disk and Filesystems in Linux • On a server, system data tends to be separate from user data. • Programs that offer services are kept in a different place than the data handled by this service
Disk and Filesystems in Linux Different partitions will be created on such systems: • a partition with all data necessary to boot the machine • a partition with configuration data and server programs • one or more partitions containing the server data such as database tables, user mails, an ftp archive etc.
Disk and Filesystems in Linux • a partition with user programs and applications • one or more partitions for the user specific files (home directories) • one or more swap partitions (virtual memory)
Disk and Filesystems in Linux • For convenience, the Linux file system is usually thought of in a tree structure. • On a standard Linux system you will find the layout generally follows the scheme presented next:
Disk and Filesystems in Linux • This is a layout from a RedHat system. Depending on the system administrator, the operating system and the mission of the Linux machine, the structure may vary, and directories may be left out or added at will.
Disk and Filesystems in Linux • The tree of the file system starts at the trunk or slash, indicated by a forward slash (/). • This directory, containing all underlying directories and files, is also called the root directory or "the root" of the file system.
Disk and Filesystems in Linux • Directories that are only one level below the root directory are often preceded by a slash, to indicate their position and prevent confusion with other directories that could have the same name. • When starting with a new system, it is always a good idea to take a look in the root directory
Disk and Filesystems in Linux Subdirectories of the root directory
du command • The basic syntax is du [options] [directories]
du Command • "du" stands for disk usage • This command is used to show the amount of disk space consumed by one or more directories (or directory trees) • Prints disk usage (as the number of 1KB blocks used by each directory and subdirectory • Default is the working directory
du command When used with no options or arguments (i.e., names of directories or files), du lists • the names and space consumption of each of the directories and subdirectories which reside in the directory tree that begins with the current directory (i.e., the directory in which the user is currently working)
du command • du can provide information about any directory trees or files on the system whose names are given as arguments. For example, du directory1/directory2 • This reports the names and sizes for each directory in the directory tree that begins with a directory named directory2 that resides in a directory named directory1, which, in turn, is located in the current directory:
du command • This command: du /sbin/file1 /sbin/file2 • will report the sizes of the two files named file1 and file2 that are located in the /sbin directory
du command • One of the most useful options is -h (i.e., human readable), which can make the output easier to read by displaying it in kilobytes (K), megabytes (M) and gigabytes (G) rather than just in the default kilobytes
du command • du -h Thus, this command can be used to show the sizes of all the subdirectories in the current directory as well as the total size of the current directory, all formatted with the appropriate K, M or G:
du command -a, -all Print disk usage for all files, not just subdirectories -b, -bytes Print sizes in bytes
du command -c, -total In addition to normal output, print grand total of all arguments h, -human-readable Print sizes in human-readable format
du command - -H, -si Like –h, but show as power of 1000 rather than 1024 -k, -kilobytes Print sizes in kilobytes (this is the default)
du command -l, -count-links Count the size of all files, whether or not they have already appeared (i.e., via a hard link) -exclude=pattern Exclude files that match pattern
du command -max-depth=num Report sizes for directories only down to num levels below the starting point (which is level 0) -m Print sizes in megabytes -s, -summarize Print only the grand total for each named directory
du command -s, -summarize Print only the grand total for each named directory -S, -separate dirs Do not include the size of subdirectories -x, -one-file-system Skip directories on different filesystems
du command -help Print help message, then exit -version Print the version and then exit