0% found this document useful (0 votes)
19 views

Types of Files in Linux

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Types of Files in Linux

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

TYPES OF

FILES IN

LINUX
BY - Gauri Yadav
LIST OF TOPICS

01 WHAT IS FILE

02 COMMON FILE TYPES IN LINUX

03 IMPORTANCE OF EACH FILE TYPE

04 PRACTICAL IMPLEMENTAION

05 SUMMARY
What is a file?
In Linux, a file is a fundamental unit that serves as a container
for storing data, whether text, programs, configurations, or other
forms of information.
Files in Linux are organized and managed by the file system,
which defines the structure, access permissions, and location of
files on the storage devices. The file system is responsible for
maintaining the hierarchy of directories and files.
Common file types in Linux?
Red Hat Enterprise Linux (RHEL) accommodates seven file
types, with regular and directory files being the most
widespread. Regular files store everyday data, while directories
help organize this information. Additionally, block and character
special devices communicate with hardware, symbolic links act
as handy shortcuts, and less commonly used named pipes and
sockets facilitate inter-process communication.

Linux stands out by not requiring file extensions for type


identification. Instead, Linux users can employ simple
commands like 'file,' 'stat,' and 'ls' to effortlessly discern a file's
content and type. This user-friendly approach allows focus on
the file's purpose rather than getting bogged down by
extensions.

Named pipes and sockets play vital roles in inter-process


communication, their intricacies are reserved for more advanced
exploration.
Importance of each file type
1. Regular File:
A regular file in Linux is a common type of file that
stores data, text, or program instructions. It is a
straightforward container for information, such as text
documents, scripts, or binary data.
They have a fixed size and can be read or written in
any order.
They are identified by a dash (-) as the first character
in the file permissions.
Within a directory or folder, you'll encounter various
file types. Regular files encompass readable content,
spanning text files, documents (like Docx),
programming scripts, as well as binary data. This
category also includes image files like JPG, PNG, SVG,
and compressed files such as ZIP and RAR.
Regular files serve as versatile containers, holding
readable information such as text and documents
alongside more complex data like programming code
and binary information. They extend to embrace a
range of multimedia with image files and streamline
storage with compressed formats.
Q1 How to identify that it’s a regular file?

It can be done in three ways by using 3 commands


1. ls-l
2. file <filename>
3. stat <filename>

Lets create new file add some content too and then check
Method 1: ls-l

lNotice the hyphen in field 1 of column 1 before rw. This


character indicates that the listed file is a regular file. Now,
let's run the file and stat commands on this file and see
what they report:
Method 2: file file2.txt

When the file command in Linux returns an ASCII


value, it indicates that the file predominantly contains
human-readable text. ASCII (American Standard Code
for Information Interchange) represents a character
encoding standard widely used for plain text,
suggesting that the file likely holds textual
information.
The ASCII output implies that the file lacks binary
formatting or complex data structures. Instead, it's
structured using simple character codes, making it
easily readable by text editors and human eyes. This
distinction helps users anticipate the nature of the
file's content and choose appropriate tools for further
examination or manipulation.
Method 3: stat file2.txt

When the stat command in Linux returns "regular file"


as an output, it signifies that the file is a standard,
everyday file. Regular files are the most common type
and can contain a variety of data, such as text, binary
information, or program instructions.
The designation as a "regular file" distinguishes it from
directories and special files like block or character
devices. It indicates a straightforward file without any
specialized functions, making it a conventional data
container within the Linux file system.
Q2 Difference between stat command and file
command?
1. Purpose:
The stat command is used to display detailed
information about a file or file system, including
metadata such as file size, access and modification
times, permissions, and more. It provides a
comprehensive overview of the file's attributes.
The file command, on the other hand, is used to
determine the type of a file by analyzing its content. It
identifies whether a file is a text file, binary file, image,
or another type, based on patterns and signatures in
the file's data.
2.Output:
The output of the stat command is detailed and
provides information about the file's various attributes
in a human-readable format. It includes metadata such
as inode number, size, permissions, timestamps, and
more.
The output of the file command is concise and focuses
on identifying the file type. It returns a brief
description of the file's content, indicating whether it
is a text file, binary data, image, or another recognized
file type.
2. Directory File:
A directory, also known as a folder, is a special type of
file that organizes and stores information about other
files. It serves as a container for organizing and
managing files and subdirectories.
Directories are logical containers that hold files and
Subdirectories.
They have a variable size that depends on the number
of entries they contain.
They can only be read sequentially and can be written
only by the system. They are identified by a letter d as
the first character in the file permissions.

Q1 How to identify that it’s a directory file?

It can be done in three ways by using 3 commands


1. ls-l
2. file <filename>
3. stat <filename>
Lets create new directory add some content too and then
check

Method 1: ls-l

Notice the d in field 1 of column 1 before rwxr. This


character indicates that the listed file is a directory file.
Now, let's run the file and stat commands on this file and
see what they report:

Method 2: file testdir


Method 3: stat testdir

Method 4: ls -l | grep ^d

The command ls -l | grep ^d lists the contents of the


current directory in long format (ls -l) and then filters the
output using grep to display only the lines that represent
directories. The ^d in the grep command specifies that it
should match lines that start with 'd', which is an indicator
in the long format output that the entry is a directory.
3. Special Files:
1. Block Special File:
A block special file in Linux represents a block device,
typically used for storing large amounts of data. It
manages data in fixed-size blocks and is commonly
associated with devices like hard drives.
Block files serve as a direct interface to block devices,
earning them the designation of block devices. These
files, often residing in the /dev directory, act as
gateways to hardware devices. Specifically, block
devices are characterized by their ability to handle
data Input and Output operations in blocks, making
them pivotal for efficient data transfer and storage
within a Linux system.
2. Character Special File:
A character special file is associated with character
devices that handle data character by character. It
provides a direct interface for communication with
devices such as printers, serial ports, or input devices.
A character file, categorized as a hardware file,
engages in the reading and writing of data on a
character-by-character basis. These files facilitate a
continuous serial stream of input or output, offering
direct access to hardware devices. Notable examples
include terminals, serial ports, and other interfaces
where data transmission occurs one character at a
time.
Q1 How to identify that it’s a block file?

Method 1: file sda

Method 2: ls -l | grep ^b

They are identified by a letter b as the first character in the


file permissions.
Q1 How to identify that it’s a char file?

Method 1: file v*

Method 2: ls -l | grep ^c

They are identified by a letter c as the first character in the


file permissions.
4. Named pipe:
A named pipe, or FIFO (First In, First Out), is a special
file that facilitates inter-process communication. It
allows data to flow between processes sequentially,
acting as a communication channel within the file
system.
whatever goes in first emerges first. Essentially, a
named pipe is identified by a file name within the file
system, serving as a conduit for seamless data transfer
from one process to another. This mechanism ensures
that the receiving process reads the data in a
disciplined first-in-first-out manner, preserving the
sequence of bytes.
These are files that allow processes to send data to
other processes or receive data from other processes.
They have no size and can be read or written in any
order.
They are identified by a letter p as the first character in
the file permissions.
Q1 How to create named pipe file?

Method 1: mkfifo <pipe name>

Q2 How to identify that it’s a named pipe file?

Method 1: file mypipe*


Method 2: ls -l | grep ^p
5. Symbol Link:
A symbolic link, or symlink, is a file that acts as a
reference or pointer to another file or directory. It
provides a convenient way to access files and
directories without altering the original file structure.

Q1 How to identify that it’s a Symbol file?

Method 1: file core

Method 2: ls -l | grep ^l
6. Socket:
A socket is a special file that is used to pass information
between applications and enables communication
between two processes. We can create a socket file
using the socket() system call. A socket file is located in
/dev of the root folder or you can use the find / -type s
command to find socket files.

Q1 How to identify that it’s a Socket file?

Method 1: file socket.sock


Summary

Importance of each file type


THANK

YOU

You might also like