The UNIX File System. File System Definition A file system is a hierarchy of directories,...

Post on 21-Dec-2015

223 views 0 download

Tags:

Transcript of The UNIX File System. File System Definition A file system is a hierarchy of directories,...

The UNIX File System

File System Definition

• A file system is a hierarchy of directories, subdirectories, and files that organize and manage the information on hard disks.

Directories

• Directories are created so users and applications can easily find files.

• Without directories, all files would be in the same location with no organization to them.– Similar to using the backseat of your car

to hold homework assignments and papers.

Hierarchical Directory Structure

• Directories are organized in an ‘upside-down’ tree fashion.

• The root is at the top.• Directories may

contain other directories and files.

• Analogous to file drawers and file folders

Directories

• The root directory is often represented as / (the forward slash symbol).

• Parent directories contain other directories (called children).

• Child directories are located within other directories (called parent directories).

Path Names

• Each file can be represented by its path name.

• The path name simply represents the file’s location in the file system.– Example: /home/user2/dir1/coffees/beans

Path Components

• Directory paths allow users to navigate within the file system.

• Slashes within the path name are delimiters between object names.– Object names can be directories,

subdirectories or files• DOS and Windows uses a backward slash

(\) to separate directories. UNIX and Linux use a forward slash (/).

• A slash (/) in the first position of any path name represents the root directory.

Exploring the Root File System

• The root directory contains sub-directories that contain files:– /bin contains binaries, or executables

needed to start the system and perform system tasks available to all users

– /boot contains files needed by the bootstrap loader as well as kernel images

– /dev contains system device reference files

Continued…

Exploring the Root File System

• Root subdirectories continued:– /etc contains configuration files that the

system uses when the computer starts– /lib contains kernel modules, security

information, and the shared library images– /mnt contains mount points for temporary

mounts by the system administrator– /proc is a virtual file system allocated in

memory only; it tracks the running processes on the system

Continued…

Exploring the Root File System

• Root subdirectories continued:– /root is the home directory of the root

user, or the system administrator– /sbin contains essential network

programs used only by the system administrator

– /tmp is a temporary place to store data during processing cycles

– /var contains subdirectories which have sizes that often change, such as error logs, print jobs, and incoming e-mail

Absolute Path Names

• An absolute path name specifies a file or directory in relation to the entire UNIX file hierarchy.

directorys

Relative Path Names

• A relative path name describes the location of a file or directory as it relates to the current directory.

directory

Path Name Types Comparison

• If the path name starts with /:– It is an absolute path name.

• Ex: /etc/resolv.conf

• If the path does not start with /:– It is a relative path name.

• Ex: user01/file1

• Absolute path names specify the exact location of a file or directory.– In Windows: C:\Windows\System32\file.dll

• Relative path names specify where a file or directory is in relation to the current spot in the file system.– In the Windows folder: System32\file.dll

Useful File System Commands

• pwd (print working directory)– Displays current directory location

• cd (change directory)– Change to a specified directory

• ls (list)– Display contents of directory

Using cd

• cd /home– Absolute Path

• In /home, cd user01/dir1– Relative Path

• cd (by itself) places user in home directory

cd Shortcuts

• cd ..– Moves the user up one directory to the parent

directory– cd ..– cd ../tmp

• cd .– Keeps the user in the current directory– cd ./coffees

• cd ~– Moves the user to the home directory– cd ~– cd ~/file1

The ls Command

• ls displays the directory contents.• ls can be used by itself to list the

contents of the current directory.• ls can be used with a directory path

to display the contents of that directory.– ls– ls /home

The ls –a Command

• Use ls –a to list all files and directories, including hidden files, . and .. directories.

The ls –l Command

• Use ls –l to display long directory listings.

Metacharacters

• Metacharacter are characters that have special meanings to UNIX and Linux commands.

• Examples:*, <, >, | (pipe), !, [, ], ? and others

• The * and ? are also referred to as wildcard characters.

The * Wildcard

* is used to represent one or more characters

The ? Wildcard

? is used to represent one character

The [ ] Metacharacters

Using [ ], anything inside the brackets will be matched

The ; Metacharacter

; is used to separate multiple commands on one line