Overview
Partitions and Filesystems
- On Linux Systems, Disk Drives and Other Storage Media are Typically Divided into Partitions.
- Also Typically, A Partition is Formatted with a Filesystems.
- A Filesystem is a Data-Structure written to the Media that allows users to store and access the data.
Common Filesystems
/-----------------------------------------------------------------------\ | Filesystem | Used For | |-----------------------------------------------------------------------| | | | ISO 9660 | CD | | MSDOS | FloppyDisk | | | | Ext2 | FloppyDisk & Older Linux System | | Ext3 | Newer Linux Filesystems | | Ext4 | Newest Linux Filesystems | | | | GFS & GFS2 | SAN | | | \-----------------------------------------------------------------------/
Inodes
- An Inode Table contains a list of all files in ext2, ext3 or ext4 filesystems.
- An Individual Entry in the Inode Table is called
inode
(index node). - The
inode
is referenced by its inode number, which is unique within a Filesystem. - The
inode
contains the metadata about the files (Everythings in Linux is a File) Such As:
- The File Type
- File Permissions
- Link Count
- User ID
- Group ID
- File Size
- Time Stamps
- Location Of The Data On The HardDisk
- Other Metadata About The Files
NOTE!: Link Count - The Number Of Filenames Associated With The Inode Number.
Directories
- We Commonly Think of a Directory as a Container, For The Files and Other Directories.
- In Fact, The Directory is a Mapping Between The Filenames and Inode Numbers.
- Filenames used by Humans to Reference a File
-
Inode Numbers used by Computers to Reference a File
- When the filename is referenced by the command or application, Linux referenced the directory in which the file resides, To Determines the inode number associated with the filename.
Check inode numbers
NOTE!: The inode
number for the MyData
file is 786629
cp command and inodes
- Allocates a free
inode
number, Placing a new entry in the Inode Table. - Creates a new Directory Entry, Associating a name with the
inode
number. - Copies Data in to the New File.
Examples:
mv command and inodes
- IF THE DESTINATION OF THE MV COMMAND IS ON THE SAME FILESYSTEM AS THE SOURCE
- Creates New Directory Entry, With The New Filename.
- Deletes Old Directory Entry, With The Old Filename.
NOTE!: Has No Impact On The Inode Table Except For The Timestamp Or The Location Of The Data NO DATA IS MOVED!
Examples:
NOTE!: When We Move The Files On The Same Filesystem Then The File’s Inode Number & Data On The Hard Disk Does Not Move.
What Moves Is The Entry In The Directory Only
- IF THE DESTINATION OF THE MV COMMAND IS ON THE DIFFERENT FILESYSTEM:
- THE MV COMMAND ACT AS A COPY AND REMOVE
rm command and inodes
- Removes the Directory Entry
- Place the Data Blocks on the Free List.
- Decrements the link count - Made inode number available for reuse.
NOTE!: DATA IS NOT ACTUALLY REMOVED, BUT WILL BE OVERWRITTEN WHEN THE DATA BLOCKS ARE REUSED BY SOME OTHER FILES
Hard Links
-
The Hard Link is a path name that references an
inode
number, All the files are hard linked at least once. - A Hard Links adds an additional Directory Entry to reference a single file.
- One Physical File On The System
- Each Directory Entry Reference The Same Inode Number
- Increment The Link Count
- The
rm
command decrement the link count - File exists as long as one link remains
- When the link count is zero, The file is removed
A Hard Link Restrictions
-
Can Not Span Across The Filesystems, Partitions or Drives. They share the
inode
number andinode
table which is unique on the filesystem -
It Is Not Possible To Use
ln
Command To Create Additional Hard Links To Directories.
Syntax:
Examples:
The Most Notable Effect Here Is
- The
fedora
&redhat
two files pointing to the sameinode
number. - The
fedora
&redhat
both are regular files, An additional hard link is not a separate file type. - The link count has been incremented to 2 because two pathname point to the same file.
Symbolic(Soft) Links
- The Symbolic(Soft) Link is a file that points to another file.
-
Most actions such as cat or less will be performed on the underlying file except the
rm
command. - The
ls -l
command display the link name and referenced file.
- File Type:
l
for symmbolic(soft) link - The Size Of The Symbolic Link = Number Of Characters In The Pathname (11 Characters in
/etc/passwd
)
Syntax:
Examples:
The Most Notable Effect Here Is
- A Symbolic Links has its own inode number That means symbolic link is a separate file from the original file.
- The Symbolic Links Permissions are odd and irrelevant Which is symbolic link control access rights.
The Seven Fundamental Filetypes Of Linux & Unix
/-----------------------------------------------\ | - | Regular File | | d | Directory | | l | Symbolic Link | | b | Block Special File | | c | Character Special File | | p | Named Pipe | | s | Socket | \-----------------------------------------------/
Block Special File
- Block Special File is used to communicate with hardware a block of data at a time 512 Bytes, 1024 Bytes, 2048 Bytes: Whatever is appropriate for that type of hardware.
Character Special File
- Character Special File is used to communicate with hardware one character at a time.
- Generally Block & Character Special Files are located in the
/dev
Directory. - Run the following command to see the listing:
Named Pipe
- Named Pipe is a file that passes data between the processes.
- Named Pipe does not store any data itself but passes data between One process writing data into a named pipe & Another process reading data from the named pipe
- Named Pipe can be created using the
mkfifo
command.
Socket
- The Socket File is a stylized mechanism for inter-process communications.
- It is extremely rare for a user or even a system administrator to explicitly create a socket.
Checking Free Space
df command
- Reports Disk Space Usages On Per Filesystem Basis.
- It Reports Total Disk Space, Used Space, Available Space, Used % and Mounted on Informations.
Options:
Examples:
du command
- Reports Disk Space Usages On Given Directory & All Subdirectories.
Options:
Examples:
baobab
- The baobab is a Graphical Disk Usage Analyzer.
- Applications -> System Tools -> Disk Usage Analyzer
- Reports Disk Space Uses Graphically.
Removable Media
- Before Accessing The Removable Media, The Filesystem’s on the Removable Media Must Be Mounted.
- In GNOME & KDE, Removable Media is usually Auto-Mounted in
/media/label
. -
Where label is Disk Label or Device ID.
- In console root manually mounts devices
Examples:
Floppy Disk
- The
mtools
is a utilities to access DOS Disks in Linux & Unix. - Mtools is a collection of tools to allow Linux & Unix systems to manipulate MS-DOS files: read, write, and move around files on an MS-DOS Filesystem (Typically a floppy disk).
Examples:
CDs & DVDs
- Automatically Mounted In GNOME/KDE
- Accessible From:
- CD-ROM Desktop Icon
- Computer Desktop Icon -> CD/DVD Drive
/media/cdrom
OR/media/disk_label
Ejected With
- eject
- eject
/dev/cdrom
- Right Click -> Eject
USB Media
- Detected By The Kernel As SCSI Devices.
/dev/sda
,/dev/sdaX
,/dev/sdb
,/dev/sdbX
, etc. - Automatically Mounted In GNOME/KDE
- Accessible From:
- Removable Disk Desktop Icon
- Computer Desktop Icon -> Removable Disk
/media/disk
OR/media/disk_label
Ejected With
- umount
/dev/sdaX
- umount
/dev/sdbX
- Right Click -> Safely Remove Device
Archiving Files & Compressing Archives
- Tape Archive (
tar
) is used to creates Archives. - The Tar Saves Many Files Together into a Single Disk Archive & Restore Individual Files from the Archive.
-
Easier to Backup, Store and Transfer The Files.
- The Tar Also Support The Following Compression Algorithms:
- gzip - gunzip Extension of .tar.gz OR .tgz
- bzip2 - bunzip2 Extension of .tar.bz2
Creating Listing & Extracting File Archives
Action Argument
-c
: Create An Archive-t
: List An Archive-x
: Extract An Archive
Typically Required
-f
: Use Archive File
Optional Argument
-v
: Verbose-z
: Use gzip Compression-j
: Use bzip2 Compression
Examples:
Gzip or Gunzip Compression
Bzip2 or Bunzip2 Compression
Creating Extracting File Archives - Other Tools
Zip & Unzip
- Support pkzip comapatible archives.
Examples:
Graphical Archive Manager:
- Applications -> Accessories -> Archive Manager
- The file-roller is a Multi Format Graphical Archive Manager.