Yandex
Update cookies preferences

Linux file types and file systems

Linux supports many file types, each of which is represented by a unique symbol, which plays an important role in system management. In the Linux file system, files are classified not only by their contents, but also by their role and behavior.

What is the Linux file system

When installing a Linux-based OS, you can select different types of file systems, each with its own features and commands: Ext, Ext (2, 3, 4), JFS, XFS, Btrfs, Swap.

Ext

An extended filesystem proposed in 1992. It is one of the first Linux filesystems, developed partly on the basis of the UNIX filesystem. Its purpose was to overcome the restrictions of the previous MINIX system. Ext is hardly used today.

Ext2 is its second version, known since 1993. An improved Ext counterpart, with improvements in performance and storage capacity. It supports up to 2 TB of data, but its use is currently not recommended.

Ext3 is the third version from 2001. Unlike Ext2, Ext3 records changes in a separate log before operations are completed, which helps to recover files after rebooting.

Ext4 is the 2006 version. This file system has eliminated many of the restrictions of previous versions and is considered one of the most popular and widely used in Linux distributions.

JFS is a file system developed by IBM in 1990. The abbreviation stands for Journaling File System. It is characterized by its ability to quickly recover data after a power failure and low consumption of processor resources.

XFS is a high-performance file system created in 1990, then adapted for Linux. It works well with large files, but is less efficient with smaller files. This 64-bit journaled file system is also available for Windows.

Btrfs is an alternative proposed by Oracle in 2009, a competitor to Ext4. It has unique advantages and good performance.

Swap - is not a file system in the traditional sense, but allows the system to use part of the disk to expand operating memory.

File Types

  • Regular files (-). The most popular type, including documents, scripts, and executable programs. In the list, they are indicated by a dash (-) at the beginning of the line.
  • Directories (d) - contain lists of other files and serve to organize the file system as a hierarchy.
  • Symbolic links (l) - links to other files or directories, provide convenient ways to access them and simplify file management.
  • Character device files (c) - specify devices that process data character by character (keyboards and mice), and support I/O operations.
  • Block device files (b) - correspond to devices that work with data in blocks (hard disks and other storage devices), playing a key role in read and write operations.
  • Sockets (s) - used to create connections between processes, both within the same system and over a network, provide data exchange.
  • FIFO (named channels) (p)-channels are queued channels that allow one process to write data and another to read it, allowing inter-process communication.
Each type performs a specific task and carries unique properties that affect system performance and functionality.

Common files in the Linux Filesystem

They are used to store a wide variety of data: text documents, executable programs, multimedia, and system configurations. Unlike specialized files that perform system tasks, regular files mainly contain user data.

To create them in the Linux file system, you can use different commands depending on its intended contents. The simplest way is the touch command, which creates an empty file if it did not already exist before. This is useful for creating files that will be filled in later, or marker files in scripting and programming.
touch example.txt
Another method is redirection. For example, with. this command you can create a new text file by redirecting the output of the command or simply creating a file without input.
echo "Hello, world!" > hi.txt
> newfile.txt

In the directory listing displayed by the ls -l command, common files are indicated by a hyphen (-) in the first character of the line. To check the characteristics of a particular file, you can use the ls -l command by specifying its name in the Linux file system.
ls -l example.txtThe output will show a hyphen (-) at the beginning of the line followed by permissions, number of links, owner and group name, file size, last modified date, and file name.

Catalogs

The Linux file system structure considers key elements in the structure of the file system, acting as containers in which files and other directories are stored. The hierarchical structure simplifies data management and navigation, allowing users and applications to organize and separate files in a logical manner.

The mkdir command is used to create a new directory. If no path is specified, the subdirectory is created in the current working directory. Using mkdir you can create several directories or a directory with nested subdirectories at the same time.
mkdir new_directory
mkdir dir1 dir2 dir3
mkdir -p new_directory/subdir/another

In the output of the command, directories are indicated by a “d” at the beginning of the line, which distinguishes them from regular files and other data types. To get detailed information about a directory, use the ls -ld command with the directory name.

ls -ld new_directory/The output starts with a “d” indicating the directory, and will then list the permissions, number of objects inside, owner name, group name, size, modification date, and directory name.

Symbolic links

Also known as programmatic links, they are special files that point to another file or directory in the Linux file system. A symbolic link does not contain the target file's data, but merely points to its location. This makes symbolic links convenient for creating shortcuts and managing files without having to duplicate their contents.

To create a symbolic link, the ln -s command is used. The target file is specified first, followed by the name of the new link. This creates a symbolic link that refers to the target file anywhere on the file system. This process does not move or copy the data of the original file, but simply creates a pointer to it.
ln -s new_file.txt simvollink_name.txtIn addition, you can create symbolic links to directories, not just files. This is useful for creating links to libraries or including directories in backups without having to move the original data.
ln -s /path/to/original/directory /path/to/simvollinkSymbolic links are indicated by the letter “l” (small “L”) at the beginning of the permissions string in the output of the ls -l command. You can see what the link is pointing to by using the arrow (->). To determine if a file is a symbolic link, and to see which file it points to in the Linux file system hierarchy, you can use the ls -l command.
ls -l symlink_name.txtThis will print a string starting with “l” indicating that this is a symbolic link followed by the path to the target file.

Symbol device files

Serve as an interface to hardware devices that transfer data character-by-character (keyboards, mice, or serial ports). Simplify the interaction of programs with hardware by providing a standardized way to control devices and perform I/O operations.

Most symbolic device files are created automatically, managed by the system and its drivers, but when testing drivers or configuring custom devices, you can create such files manually using the mknod command. This command requires root privileges because it interacts directly with the hardware. The command syntax specifies the device type “c” for character devices, and the high and low numbers that identify the driver and the specific device.
mknod my_char_device c 180 31In this example, the high number “180” indicates the driver and “31” indicates the specific device it controls.

Character device files can be recognized by the letter “c” at the beginning of the permissions string displayed by the ls -l command. To view the characteristics of such files, including their numbers, use the ls -l command in the /dev directory.

Block device files

These are interfaces for devices that process data in blocks, such as hard disk drives and solid state drives. They enable buffered reads and writes, which are critical to the performance and efficiency of file system operations.

Usually created and managed by the system and its drivers. For specific tasks, such as configuring a new driver, block device files can be created manually using the mknod command, which requires specifying the device type “b” for the block device and root privileges due to direct interaction with the hardware.
mknod my_block_device b 8 0In this example, the high number “8” indicates disk devices, and “0” may indicate the first device, such as “/dev/sda”.

In the output of the ls -l command, block device files are indicated by a “b” at the beginning of the line.

ls -l /dev/sdaThis command will show the properties of the first SCSI disk on your system, which will be identified as a block device.

Sockets

Represent points for sending and receiving data between processes both within the same system and across a network, facilitating both local and Internet connections.

Usually created using APIs provided by network programming libraries. Here is sample Python code to create a TCP/IP socket that listens on a local port:
import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind(('localhost', 8080))
sock.listen(1)
The code configures the server to listen for incoming TCP connections on port 8080.

In the file list, sockets are labeled with an “s”. You can usually find them in the /tmp or /var/run directories, and check them with commands to display network status.
ls -l /path/to/socket

FIFO (named channels)

A mechanism for asynchronous communication between processes that allows one process to send data to another without requiring a direct connection.

The mkfifo command is used to create a FIFO. Creates a named channel in the file system that can be accessed by any process that knows its name.
mkfifo my_pipesThis command creates a FIFO named “my_pipes” that can be used to exchange data between processes.

In the output of the ls -l command, FIFOs are denoted by a “p” in the permissions line.

ls -l my_pipesThis command will display the properties of the FIFO named “my_pipes”, confirming its status as a named channel.

Summary

Each file type performs a different function and behaves differently, which affects data organization, communication, and device management. Understanding these differences allows you to optimize workflows, increase data security, and improve information processing.
02 Sep 2024, 10:27:28

VPS in the Netherlands

Browse Configurations

Windows Storage VPS

Browse Configurations