What is regular file in linux

Explanation of “Everything is a File” and Types of Files in Linux

If you are new to Linux, or have used it for a few months, then you must have heard or read statements such as “In Linux, everything is a File”.

Everything is a File and Types of Files in Linux

That is in fact true although it is just a generalization concept, in Unix and its derivatives such as Linux, everything is considered as a file. If something is not a file, then it must be running as a process on the system.

To understand this, take for example the amount of space on your root (/) directory is always consumed by different types of Linux files. When you create a file or transfer a file to your system, it occupies some space on the physical disk and it is considered to be in a specific format (file type).

And also the Linux system does not differentiate between files and directories, but directories do one important job, that is store other files in groups in a hierarchy for easy location. All your hardware components are represented as files and the system communicates with them using these files.

The idea is an important description of a great property of Linux, where input/output resources such as your documents, directories (folders in Mac OS X and Windows), keyboard, monitor, hard-drives, removable media, printers, modems, virtual terminals and also inter-process and network communication are streams of bytes defined by file system space.

A notable advantage of everything being a file is that the same set of Linux tools, utilities and APIs can be used on the above input/output resources.

Although everything in Linux is a file, there are certain special files that are more than just a file for example sockets and named pipes.

What are the different types of files in Linux?

In Linux there are basically three types of files:

  1. Ordinary/Regular files
  2. Special files
  3. Directories

Ordinary/Regular Files

These are files data contain text, data or program instructions and they are the most common type of files you can expect to find on a Linux system and they include:

  1. Readable files
  2. Binary files
  3. Image files
  4. Compressed files and so on.

Special Files

Special files include the following:

Block files : These are device files that provide buffered access to system hardware components. They provide a method of communication with device drivers through the file system.

One important aspect about block files is that they can transfer a large block of data and information at a given time.

Listing block files sockets in a directory:

Sample Output

Character files : These are also device files that provide unbuffered serial access to system hardware components. They work by providing a way of communication with devices by transferring data one character at a time.

Listing character files sockets in a directory:

Sample Output

Symbolic link files : A symbolic link is a reference to another file on the system. Therefore, symbolic link files are files that point to other files, and they can either be directories or regular files.

Читайте также:  Как поменять значок для папки windows 10

Listing symbolic link sockets in a directory:

Sample Output

You can make symbolic links using the ln utility in Linux as in the example below.

In the above example, I created a file called file1.txt in /tmp directory, then created the symbolic link, /home/tecmint/file1.txt to point to /tmp/file1.txt.

Pipes or Named pipes : These are files that allow inter-process communication by connecting the output of one process to the input of another.

A named pipe is actually a file that is used by two process to communicate with each and it acts as a Linux pipe.

Listing pipes sockets in a directory:

Sample Output

You can use the mkfifo utility to create a named pipe in Linux as follows.

In the above example, I created a named pipe called pipe1 , then I passed some data to it using the echo command, after that the shell became un-interactive while processing the input.

Then I opened another shell and run the another command to print out what was passed to pipe.

Socket files : These are files that provide a means of inter-process communication, but they can transfer data and information between process running on different environments.

This means that sockets provide data and information transfer between process running on different machines on a network.

An example to show the work of sockets would be a web browser making a connection to a web server.

Sample Output

This is an example of a socket create in C by using the socket() system call.

  1. AF_INET is the address family(IPv4)
  2. SOCK_STREAM is the type (connection is TCP protocol oriented)
  3. 0 is the protocol(IP Protocol)

To refer to the socket file, use the socket_desc , which is the same as the file descriptor, and use read() and write() system calls to read and write from the socket respectively.

Directories

These are special files that store both ordinary and other special files and they are organized on the Linux file system in a hierarchy starting from the root (/) directory.

Listing sockets in a directory:

Sample Output

You can make a directory using the mkdir command.

Summary

You should now be having a clear understanding of why everything in Linux is a file and the different types of files that can exit on your Linux system.

You can add more to this by reading more about the individual file types and they are created. I hope this find this guide helpful and for any questions and additional information that you would love to share, please leave a comment and we shall discuss more.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

We are thankful for your never ending support.

Источник

What is the main difference between a temporary file and a regular file in Linux?

What is the main difference between a temporary file («tempfile») and a regular file in Linux?

The only main difference I recon between these two inodes is that in general, a «temporary file» has a much shorter life cycle than a «regular file», from whatever reason, while both are by principle, practically temporary (at least from the fact this universe is heading to a total heat death).

2 Answers 2

There is absolutely no difference between a temporary file and a regular file.

A temporary file is a regular file, and a regular file is «regular» as opposed to being a directory, or a device special file, or named pipe etc.

The only difference is, as you point out, the typical use of the file. When a program or script creates a «temporary file», it is typically a regular file that is used to store temporary data that is not needed beyond the lifetime of the process that created it. Such files are often created in $TMPDIR .

File: An object that can be written to, or read from, or both. A file has certain attributes, including access permissions and type. File types include regular file, character special file, block special file, FIFO special file, symbolic link, socket, and directory. Other types of files may be supported by the implementation.

Regular file: A file that is a randomly accessible sequence of bytes, with no further structure imposed by the system.

Читайте также:  Увеличение производительности windows 10 службы

It does not, however, care to say anything about the definition of a «temporary file», because it’s not a specific file type (rather, a way of using regular files).

Источник

File types In Linux/Unix explained in detail.

How many types of files are there in Linux/Unix and what are they? ” This is a common question to every person who starts to learn Linux. O.K, why is it that much important to know file types?

Answer: This is because Linux considers every thing as a file. When ever you start working on Linux/Unix box you have to deal with different file types(linux/unix) to effectively manage them

How many types of file are there in Linux/Unix?

By default Unix have only 3 types of files. They are..

Special files(This category is having 5 sub types in it.)

So in practical we have total 7 types(1+1+5) of files in Linux/Unix. And in Solaris we have 8 types. And you can see the file type indication at leftmost part of “ls -l” command.

Here are those files type.

  1. Block file(b)
  2. Character d evice file(c)
  3. Named pipe file or just a pipe file(p)
  4. Symbolic link file(l)
  5. Socket file(s)

For your information there is one more file type called door file(D) which is present in Sun Solaris as mention earlier. A door is a special file for inter-process communication between a client and server (so total 8 types in Unix machines). We will learn about different types of files as below sequence for every file type.

Regular file type Explained in Linux

These are the files which are indicated with “-” in ls -l command output at the starting of the line. And these files are.

How to create regular files in Linux/Unix?
Ans: Use touch/vi command and redirection operators etc.

How can we list regular files?

Example listing of regular files :

Directory file type explained in Linux/Unix

These type of files contains regular files/folders/special files stored on a physical device. And this type of files will be in blue in color with link greater than or equal 2.

Example listing of directories.

How to create them?
Ans : Use mkdir command

Block file type in Linux

These files are hardware files most of them are present in /dev.

How to create them?
Ans : Use fdisk command or create virtual partition.

How can we list them in my present working directory?

Example listing of Block files(for you to see these file, they are located in /dev).

Character device files in Linux

Provides a serial stream of input or output.Your terminals are classic example for this type of files.

How can we list character files in my present working directory?

Example listing of character files(located in /dev)

Pipe files in Linux/Unix

The other name of pipe is a “named” pipe, which is sometimes called a FIFO. FIFO stands for “First In, First Out” and refers to the property that the order of bytes going in is the same coming out. The “name” of a named pipe is actually a file name within the file system.

How to create them?
Ans: Use mkfifo command.

Читайте также:  Загрузить realtek hd audio manager для windows 10

How can we list character files in my present working directory?

Example listing of pipe files

These are linked files to other files. They are either Directory/Regular File. The inode number for this file and its parent files are same. There are two types of link files available in Linux/Unix ie soft and hard link.

How to create them?
Ans : use ln command

How can we list linked files in my present working directory ?

Socket files in Linux

A socket file is used to pass information between applications for communication purpose

How to create them?
Ans : You can create a socket file using socket() system call available under

Example in C programming

You can refer to this socket file using the sockfd. This is same as the file descriptor, and you can use read(), write() system calls to read and write from the socket.

How can we list Socket files in my present working directory?

Example listing of socket files.

srw-rw-rw- 1 root root 0 2010-02-15 09:35 /dev/log

A tip for you guys. How to find your desired type of file ?

Ans : Use find command with -type option. For example if you want to find socket file, just use below command. find / -type s If you want to find linked file then how? Find / -type l

Источник

What is inode number in Linux ?

A Linux consider everything a file including hardware devices, printers, directories, and processes. Any text, music, video, image or any multimedia file is considered a regular file. All the regular file contains metadata about the file which describe everything about the file like, type, Inode etc.

An inode is an entry in Inode table, containing information (the metadata) about a regular file and directory. An inode is a data structure on a traditional Unix-style file system such as Ext3 or Ext4.

What is inode number in Linux

Inode number also called index number, it consists following attributes of any file:

  • File types ( executable, block special etc )
  • Permissions ( read, write etc )
  • UID ( Owner )
  • GID ( Group )
  • FileSize
  • Time stamps including last access, last modification and last inode number change.
  • File deletion time
  • Number of links ( soft/hard )
  • Location of ile on harddisk.
  • Some other metadata about file.

Check Inodes on Filesystem

You can find a total number of inodes on disk by using ‘-i‘ option with df command.

The below command shows the total number of Inodes on the file system, uses and free inodes details. In case of inodes full on any filesystem, you can’t create a new file on disk even you have enough free space. So each file system must have free disk and inodes to create file.

Find Inode number of File

To check inode number of file use following command. The first field in output is an inode number of the file.

You can also search file with an inode number using find command. For example:

Inode Changes with Copy, Move and Delete

What happens with inode number when copy, move or delete a file on the filesystem.

Copy file: cp allocates a free inode number and placing a new entry in inode table.

Move or Rename a file: if destination is same filesystem as the source, Has no impact on inode number, it only changes the time stamps in inode table.

Delete a file: Deleting a file in Linux decrements the link count and freeing the inode number to be reused.

Free Inodes on Filesystem

In the case of inodes are full. You need to remove unused files from the filesystem to make Inode free. There is no option to increase/decrease inodes on disk. It only created during the creation of filesystem on any disk.

Источник

Оцените статью