Docsity

Files in Linux - Programming, Završni radovi od Programiranje

Delimični pregled teksta

Preuzmite Files in Linux - Programming i više Završni radovi u PDF od Programiranje samo na Docsity!

Programming basics

Files in Linux

Contents

    1. Introduction........................................................................................................................1-
  • 1.1.History...................................................................................................................2-
  • 1.2.Growth in popularity........................................................................................
  • 1.3. Linux Development........................................................................................................
  • 1.4.Using Linux................................................................................................6-
    1. Files in Linux........................................................................................................8-
  • 2.1. Ordinary files in Linux................................................................................10-
  • 2.2.Directories in Linux................................................................................12-
  • 2.3.Symbolic links in Linux........................................................................15-
  • 2.4. Hard links in Linux................................................................................18-
  • 2.5.Device files........................................................................................................20-
  • 2.6. Fifo and Socket files in Linux................................................................22-
    1. Conclusion................................................................................................................

greatest influence outside of Bell Laboratories. At this university, they began work on VAX UNIX 32V, from which they created the 3BSD version. 1 Soon DARPA (Defense Advanced Research Projects Agency) ordered from Berkeley a standard UNIX system for use in management. A 4BSD version was also created. This version provided networking according to the DARPA Internet Network Protocol (TCP/IP). Berkeley University developed many terminal drivers, a new user interface (C shell), new text editors, compilers for Pascal and Lisp, as well as many other system programs. The abbreviation BSD comes from Berkley Software Distribution. UNIX is one of the best and most popular operating systems in the world. It was originally designed as a tool for scientists and programmers to work on the most powerful computers of the time, and was later adapted for various other purposes. Despite its designed - "complicated" user interface, and lack of standardization, it became the most widely used operating system in business applications. A large number of other, now popular, operating systems use some version of the UNIX system as their basis.

1.1. History Unix - The Unix operating system was conceived and created in 1969 at AT&T's Bell Laboratories, USA. The main creators were Ken Thompson, Dennis Ritchie, Douglas McElroy and Joe Osana. The system was first introduced in 1971 and was written entirely in assembly language, which was common practice at the time. In 1973, in a pioneering attempt, Unix was rewritten in the C programming language, by Dennis Ritchie, except for the kernel itself and the code for working with input and output devices (due to the speed of these critical parts of the system). The presence of an operating system written in a high-level programming language made it easier to port to different computer systems. Due to legal ambiguity that forced AT&T to license the operating system to anyone who requested it, UNIX grew rapidly and became widely accepted by academic institutions and businesses. In 1984, AT&T and Bell Labs separated. After the legal hurdles were cleared, Bell Labs began selling UNIX as a proprietary software product. GNU - The GNU Project, started in 1983 by Richard Stallman, aimed to create a complete software system that would be compatible with Unix and would consist exclusively of free software. Work on the completely free GNU system began in 1984. Later, in 1985, Stallman founded the Free Software Foundation and wrote the GNU General Public License during 1989. By the early 1990s, many of the programs needed for an operating system (program libraries, compilers, text editors, the Unix shell, and the graphics system) were complete. Critical parts such as device connectors, system services (software daemons), and the system kernel itself were missing. Since GNU did not have a usable kernel even in 1991, Linus Torvalds began programming the kernel of his own operating system. The lack of a usable GNU kernel, the significant limitations of Minix and its relatively high price, and the unclear legal status of the BSD Unix variant forced him to do so. BSD - Development of the 386BSD operating system, from which NetBSD and FreeBSD were later developed, began before 1992, i.e. before Linux, but was slowed down and hampered by legal difficulties over licensing the name and code of Junix, from which other BSD Unix variants

family of microprocessors in order to achieve technological independence. In Spain, some regions have developed their own Linux distributions and they are widely used in education and official institutions. Examples include gnuLinEx in Extremadura and Guadalinex in Andalusia. Portugal uses its own Linux distribution, Caixa Mágica, which is used in netbooks in Magalhaes and in the state education program e-escola. France and Germany are also increasingly adopting the free Linux operating system. 4 1.3. Linux development Linux has a similar architecture and concepts to Unix and Minix, but does not share the same source code. The main difference between Linux and many other operating systems today is that the Linux kernel and many parts of the operating system that support it are free, open source software. Linux is not the only such system, but Linux is the most widely used such system. Some free software licenses are based on the principle of copyleft, which is a type of reciprocity: any work derived from copyleft software must itself become copyleft software. The most common software license, the GNU General Public License, is a form of copyleft and is used for the Linux kernel and many parts of the GNU project. Linux distributions are designed to be easily interoperability with other operating systems and with established computing standards. Linux systems follow the POSIX standard, SUS, ISO, and ANSI standards where possible. Despite this, only one Linux distribution has received POSIX certification, Linux-FT. Free software projects, although developed on a common basis, are often independent of each other. The fact that software licenses allow for redistribution provides the basis for large projects to collect software produced by smaller projects. This is then published and made available to everyone as a Linux distribution. A Linux distribution, often abbreviated "distro", is a collection of software packages that are freely available for burning to disk and later installation on a computer. This allows the user to customize the operating system to their needs. Distributions are maintained by individuals, freelance teams, voluntary organizations, and commercial entities. A distribution has a default configuration of the Linux kernel, system security, and software packages into a coherent whole.

1.4.Using Linux The Linux kernel is designed to run on a wide range of computer architectures, from small ARM processors to large IBM System z9 mainframes. Devices range from mobile phones to supercomputers. There are specialized distributions for less common architectures. The ELKS kernel can run on 16-bit Intel 8086 or Intel 80286 microprocessors, while the Mikroklinux kernel can run on systems without a memory management unit. The Linux kernel has even been adapted to run on systems designed to run only on the manufacturer's operating system, such as Macintosh computers with PowerPC and Intel processors, personal digital assistants (PDAs), video game consoles, portable music players, and mobile phones. There are several industry associations and hardware conferences dedicated to maintaining and improving support for a wide range of hardware under Linux. One of these is FreedomHEC. Desktop computers - KDE plasma desktop graphical environment, one of many environments available on desktop computers running Linux. LAMP stack (along with Squid) The popularity of Linux on standard desktops and laptops has grown over the years. Currently, most distributions also include a graphical desktop environment, with Gnome, Unity, and KDE Plasma desktop environments being the most popular. The features of Linux on desktops are a controversial topic. In 2007, Kon Kolivas accused the Linux community of optimizing the performance of the kernel on servers and neglecting desktops. As a result, he abandoned further development of the Linux kernel. After that, he gave an interview in which he revealed his opinions on Linux development. Since then, significant efforts have been made to improve the user experience on desktop Linux systems.

Servers, mainframes, and supercomputers - Linux distributions have long been used as server operating systems and are very prominent in that role. In September 2006, Netcraft reported that eight of the ten most trusted Internet hosting companies use Linux distributions on their servers. As of June 2008, Linux distributions held five of the top ten spots, FreeBSD three of the ten, and Windows two of the ten. As of February 2010, Linux distributions hold six of the top ten spots, FreeBSD two of the ten, and Microsoft Windows one of the ten. Linux distributions form the basis of the LAMP (Linux, Apache, MySQL, Perl/PHP/Python) server software stack, which has gained popularity among development teams and is one of the most common platforms for hosting websites. Linux distributions have become quite popular on mainframe computers, largely due to their price and free software model. 7

  1. Files in Linux Linux is an operating system based on the Unix philosophy, one of whose basic principles is that everything is a file. This concept implies that almost all resources in the system – documents, programs, devices, processes and communication channels – are represented and treated as files. This organization allows for simpler system management, better access control and high flexibility. Files in Linux are the basic unit for storing and processing data. They are used to store user documents, system configuration data, executable programs, as well as for communication between processes and hardware components. Thanks to a unified approach to files, Linux ensures stability, security and efficiency in work. HIERARCHICAL FILE ORGANIZATION - Linux uses a hierarchical file system structure, which starts with the root directory, denoted by the / sign. All other files and directories are located within this structure. Unlike some other operating systems, Linux does not use separate drive letters, but includes all devices and partitions in a single file system tree. Each file in the system has a unique path that determines its location within the hierarchy. The path can be absolute, when it starts from the root directory, or relative, when it refers to the current working directory. This method of organization allows for clarity and logical grouping of data. BASIC FILE CHARACTERISTICS - Every file in Linux has certain attributes that define its behavior and how it is used. Basic file characteristics include the file name, file type, size, date and time of creation or last modification, and access permissions.

A file name in Linux can contain almost any character except the / character, and is case- sensitive. This means that files with the same name but different case are treated as completely different files. This feature requires care on the part of the user, but at the same time allows for greater flexibility in naming. FILE PERMISSIONS AND OWNERSHIP - Security in Linux relies heavily on the system of file permissions and ownership. Each file has an owner and group, as well as a set of permissions that determine who can read, write, or execute the file. These permissions are divided into permissions for the file owner, group members, and other users. This division allows for precise control of access to data and prevents unauthorized changes or misuse of files. In addition to basic permissions, Linux supports more advanced mechanisms such as special permissions and access control lists, which further enhance system security. 8 FILE TYPES IN LINUX There are many different types of files in Linux, each with its own purpose and function. In addition to regular files and directories, there are also special files that are used to communicate with hardware or other processes. This variety of file types allows Linux to manage different system resources in a unique way. Although they are all treated as files, each type has its own specific rules of behavior and usage. Understanding these differences is of great importance for system administration and effective use of Linux. THE IMPORTANCE OF FILES IN LINUX SYSTEM OPERATION Files are the foundation of the Linux operating system. Files are used to store data, execute programs, configure system services, and communicate between different system components. Thanks to the unique concept of files, Linux provides stable and reliable operation, even in complex environments. Understanding how Linux manages files is a key step towards better understanding the system, whether you are an ordinary user or a system administrator.

FILE NAME AND EXTENSION

Unlike some other operating systems, Linux does not rely on a file extension to determine its type or usage. The extension serves solely as a convention to help users identify the type of file. For example, files with the extension .txt are typically used for text, while .sh denotes scripts. File names in Linux are case-sensitive, meaning that file.txt and File.txt are two different files. This feature requires more care when working with it, but allows for greater flexibility in naming. PERMISSIONS ON REGULAR FILES Every regular file in Linux has defined access permissions that determine who can read, modify, or execute that file. The basic permissions are read, write, and execute. These are assigned to the file's owner, group, and other users of the system. 10 The executable permission is of particular importance for regular files, as it determines whether the file can be run as a program or script. A file that does not have executable permission cannot be run directly, even if it contains valid program code. ORDINARY FILES LIKE PROGRAMS AND SCRIPTS - In Linux, programs and scripts are also ordinary files. The difference is that executable files have the appropriate execution permission and a properly defined format. This allows for easy management of programs, as they are treated in the same way as other files. Scripts, such as shell or Python scripts, are plain text files that contain commands that are executed sequentially. They are often used for task automation and system administration, which further emphasizes the importance of plain files in everyday work. CREATING, MODIFYING, AND DELETING ORDINARY FILES - Ordinary files can be created in Linux in several ways – using the command line, a graphical environment, or through applications. The user can easily create a new file, modify existing content, or delete a file, if they have the appropriate permissions. It is important to note that in Linux, deleting a file actually removes the link to the data on the disk, while the space itself is freed only when there is no longer a single reference to that file. This mechanism allows for efficient memory management and stable system operation. THE IMPORTANCE OF ORDINARY FILES - Ordinary files are the foundation of Linux and the most important way to store and process data. Without them, it would not be possible to use programs, save documents, or configure the system. Their simple structure and universal application make Linux a powerful and flexible operating system.

2.2. Directories in Linux

  1. BASIC CONCEPT OF DIRECTORY A directory in the Linux operating system is a special type of file whose primary purpose is to organize other files and directories. Although it is often represented as a "folder" in graphical environments, at the system level a directory is a file that contains information about other files. It does not contain the contents of the files themselves, but rather data that allows the system to know where those files are located and how to access them. One of the basic principles of the Unix/Linux philosophy is that everything is a file, which means that directories follow the same rules as other files: they have an owner, access permissions, creation and modification times, and a clearly defined role in the system.
  2. THE ROLE OF DIRECTORIES IN THE FILE SYSTEM Directories allow for hierarchical organization of file systems. Instead of all files being in one place, they are arranged into logical units that make it easier to manage, search, and protect data. This structure is especially important in large systems that contain thousands or millions of files. Thanks to directories, users can separate system files from user data, programs from documents, and private files from those intended for sharing. This significantly contributes to the security and stability of the system.
  3. ROOT DIRECTORY (/)

Directory permissions have a special meaning and directly affect security and access control in a Linux system. Although they use the same symbols as for regular files, their function is different. Read permission (r) - Read permission on a directory allows a user to see a list of the names of the files and subdirectories within it. This means that a user can list the contents of the directory, but not necessarily access the files themselves. If a directory does not have read permission, a user cannot see what is inside it, even if they have permission to read individual files within that directory. Write permission (w). - Write permission on a directory allows you to create new files and directories, delete existing ones, and rename entries within a directory. It is important to note that this permission does not control the modification of the contents of files, but rather the management of the entries in the directory itself. For example, a user can delete a file in a directory if they have write permission on the directory, even if they do not have write permission on the file itself. This rule is very important for understanding security in Linux. 13 Execution permission (x) The execute permission on a directory is one of the most important. It allows you to enter the directory and access the files within it, provided that the user knows their name. Without this permission, it is not possible to access the files, even if the other permissions are present. In practice, all three permissions are most often required for normal operation with a directory: read, write, and execute.

  1. DIRECTORY CODE PERMISSION COMBINATIONS Combinations of permissions determine the specific behavior of a directory: r + x – allows viewing content and accessing files, w + x – allows adding and deleting files, but not viewing the contents, r without x – allows viewing the file list, but not access, x without r – allows access to files if the name is known, but not to view the list. These combinations are often used in system administration for fine-grained access control.
  2. CREATING AND DELETING DIRECTORIES

Directories can only be created and deleted if the user has the appropriate permissions on the parent directory. Creating a directory does not require any special permissions on the directory itself, as it does not yet exist. Deleting a directory involves removing its entry from the parent directory. Deleting an empty directory requires write and execute permissions on the parent directory.

  1. EMPTY AND NON-EMPTY DIRECTORIES An empty directory is one that contains only the special entries. and ... A non-empty directory also contains other files or subdirectories. Deleting a non-empty directory requires that all files and subdirectories within it be removed first, which prevents accidental data loss and contributes to security.
  2. HIDDEN DIRECTORIES Hidden directories in Linux are those whose names begin with a period. They are not visible in the usual directory listing, but are fully accessible to the user who knows about their existence. These directories are often used to store configuration files and user program settings, which helps keep the desktop environment neat and tidy. 14
  3. SYSTEM DIRECTORIES Linux uses a large number of system directories that have a strictly defined purpose. They contain system files, configurations, and programs necessary for the operating system to work. The organization of these directories allows for system stability, easy maintenance, and easier software updates.
  4. SECURITY SIGNIFICANCE OF THE DIRECTORY Directories play a key role in the security of a Linux system. By controlling directory permissions, administrators can restrict access to sensitive data and prevent unauthorized changes. Properly configured directory permissions are the foundation of a stable and secure system and one of the most important aspects of Linux administration. 2.3. Symbolic links in Linux

for the existence of the target when the link is created, but only when it is accessed. This behavior is fully defined and described in the official Linux documentation.

  1. PERMISSIONS AND SYMBOLIC LINKS Symbolic link permissions are not used in practice for access control. When a link is accessed, the system actually checks the permissions of the target file or directory, not the link itself. This is an important conceptual difference from regular files and one of the most common topics on operating systems exams.
  2. DIFFERENCE BETWEEN A SYMBOLIC LINK AND A HARD LINK One of the most important topics regarding symbolic links is their comparison with hard links. Although both serve to connect files, the way they work is fundamentally different. A symbolic link is a special file that contains the path to a target file or directory. A hard link, on the other hand, is an additional entry in a directory that points to the same inode as the original file. Therefore, symbolic links can point to directories and files located on other file systems, while hard links have these limitations. If the target file is deleted, the symbolic link continues to exist but becomes invalid, while a hard link continues to function as long as there is at least one entry pointing to that inode. 16
  3. BEHAVIOR WHEN DELETING A TARGET FILE When the target file or directory to which a symbolic link points is deleted, the symbolic link itself is not automatically deleted. It remains in the file system, but points to a location that no longer exists. In this case, any attempt to access the symbolic link results in an error. This behavior is a direct consequence of the fact that a symbolic link does not contain data about the file itself, but only a path to it. This feature is clearly defined in the POSIX standard and described in the official Linux documentation.
  4. SYMBOLIC LINKS AND RECURSION Symbolic links can lead to recursive structures in the file system. For example, a directory may contain a symbolic link that points to one of its superdirectories. Such structures can cause problems with recursive operations, such as searching or copying directories.

For this reason, many tools do not follow symbolic links by default when recursively traversing the file system, unless explicitly requested to do so. This behavior is documented in the man pages of standard Linux tools.

  1. THE ROLE OF SYMBOLIC LINKS IN THE SYSTEM Symbolic links are used extensively in Linux systems for flexible file organization. They allow the same resource to appear in multiple places in the file system without duplicating data. A common example is system directories and libraries, where symbolic links are used to manage different versions of the same software. This practice allows for easier system updates and maintenance.
  2. ADVANTAGES OF SYMBOLIC LINKS The main advantage of symbolic links is their flexibility. They can connect files and directories located in different locations, and even on different file systems. In addition, symbolic links do not require additional storage space, as they do not duplicate the contents of files. This makes them an efficient solution for system organization and management.
  3. DISADVANTAGES OF SYMBOLIC LINKS One of the main disadvantages of symbolic links is the possibility of creating invalid links due to the deletion or relocation of the target file. Also, excessive use of symbolic links can make it difficult to understand the file system structure. From a security perspective, improper use of symbolic links can lead to undesirable consequences, especially in system directories. 17
  4. SECURITY ASPECTS Symbolic links can pose a security risk if used without adequate permission controls. Attacks that exploit symbolic links are well-known in Unix/Linux systems, which is why many programs have special mechanisms to protect against such scenarios. Therefore, it is important to carefully manage symbolic links, especially in directories that are accessed by multiple users. 2.4. Hard links in Linux