21
2011
Linux File Types
“In Linux everything is a file but not all the files are of the same type.”
In Linux everything is considered a file. The processes, the CPU, RAM, and even the Linux kernel memory can be viewed as files under the /proc directory. Devices like monitors, hard drives, modems, keyboards , CD-ROM and printers are files. Surprisingly, even any error messages that might result from what we type is a file. Hence anything that is physically or logically attached to the machine, and that the Linux kernel can see, is represented as a file in Linux.
Linux treats hardware devices as files. Every device has a file corresponding to it (found in the /dev directory) and a program can open this file and read from or write to it just like with any other file. Each time that happens, the kernel intervenes and writes to or reads from the hardware, then passes back the result to the program which is a huge advantage if we are writing programs because we don’t need to know how to actually access the hardware.
For example, the hard disks will be files into /dev, like /dev/hda, or /dev/sdb. The partitions will also be files there: /dev/sda1, /dev/sda2… and so on.
At the time a new file is created, it gets a free inode (index node) which contains the following information :
a) Owner and group owner of the file.
b) File type (regular, directory, …)
c) Permissions on the file( read , write etc )
d) Date and time of creation, last read and change.
e) Date and time this information has been changed in the inode.
f) Number of links to this file ( soft / hard )
g) File size
The only information not included in an inode, is the file name and directory. These are stored in the special directory files.
A file system is a method of storing and organizing computer files and their data. Essentially, it organizes these files into a database for the storage, organization, manipulation, and retrieval by the computer’s operating system. File systems are used on data storage devices such as hard disks or CD-ROMs to maintain the physical location of the files.
The file system is represented hierarchically with ‘/’ (root) being at the top most level and every file existing on the system is located under it somewhere. Within the root directory, several system directories contain files and programs that are features of the Linux system. The root directory also contains a directory called /home that contains the home directories of all the users in the system. Thus in addition to holding files , much like files in a file drawer, a directory also connects to other directories much as a branch in a tree is connected to other branches giving a tree like structure to the Linux file system.
To gain access to files on another device, the operating system must first be informed where in the directory tree those files should appear. This process is called mounting a file system. The directory given to the operating system is called the mount point. Eg: /media is the mount point for removable devices like the DVD’s and the USB’s.
Linux supports many different file systems, but common choices for the system disk include the ext* family (such as ext2, ext3 and ext4), XFS, JFS, ReiserFS and btrfs.
Note: Use tree -L 1 / command to see the Linux file system hierarchy.
Types of files
Regular File : It comes under the Normal File category.
Symbol : - Color : White
Directory : These are special types of files that are lists of other files.
Symbol : d Color : Blue
Symbolic Link : A symbolic link is a reference to another file ( a shortcut to any file ).
Symbol : l Color : Cyan
Socket : Special type of file that provides inter-process networking protected by the file system’s access control
Symbol : s Color : Purple
Named Pipe : A special type of file that acts more or less like sockets and form a way for processes to communicate with each other, without using network socket semantics.
Symbol : p Color : Red
Device File : Network devices do not turn up in the file system but are handled separately. Device files are used to apply access rights and to direct operations on the files to the appropriate device drivers.
There are two types of device files :
Character devices provide only a serial stream of input or output.
Symbol – c Color : Yellow
Block devices are randomly accessible.
Symbol – b Color : Yellow
(Click to enlarge)
Different commands which create special types of files are :
* link invocation :: Make a hard link via the link syscall
Eg: link FILE1 FILE2 calls the link function to create a link named FILE2 to an existing FILE1.
* ln invocation :: Make links between files.
Eg: ln -s TARGET LINK_NAME creates a symbolic link ( the shortcut to any file ) to TARGET with the name LINK_NAME instead of a hard link. Without the -s option it creates a hard link. A hard link is essentially a label or name assigned to a file. It does not create a separate copy of the old file, but rather a different name for exactly the same file contents as the old file. Consequently, any changes made in the oldfile is visible in the new file.
* mkdir invocation :: Make directories.
Eg: mkdir -m745 MY creates a directory MY with permission 745.
* mkfifo invocation :: Make FIFOs (named pipes)
mkfifo [OPTION]… NAME…
* mknod invocation :: Make block or character special files.
mknod [OPTION]… NAME TYPE [MAJOR MINOR]
The major number identifies the device class or group whereas the minor number identifies a specific device.
* readlink invocation :: Print the reference of a symbolic link.
Consider the following symbolic link : art -> article1.odt
Input : readlink art
Output : article1.odt
* rmdir invocation :: Remove empty directories.
Eg: rmdir MY removes an empty MY directory.
Note: rm -rf helps to delete a directory that is not empty.
* unlink invocation :: Remove files via the unlink syscall
For more useful Linux Tips and Tricks, follow @fortystones
Subscribe to fortystones.
Follow @fortystones on Twitter.
Get updated from our Facebook Fanpage.
Related Posts
1 Comment + Add Comment
Leave a comment
Fortystones Lab Projects
Categories
- Articles (43)
- Idea (2)
- Review (5)
- Social Media (29)
- Trending Topics (13)
- Collection (29)
- How To (27)
- Linux (26)
- News (15)
- PHP (6)
- Project (1)
- Tutorials (35)
- Java (4)
- Programming (10)
- Wordpress (7)
Popular Posts
- 40 Basic Linux Command-line Tips and Tricks
- Tips and Tricks for Facebook Chat (Save History/ Video Chat/ Send Files)
- The First on the World Wide Web
- 40 Linux Shell Commands for Beginners
- Online Coding Zones for Programmers
- Special: Facebook Smiley, Special Text Symbols and ASCII Arts
- 13 years of Google: 1997- Present

An article by Raju Khanal







Muchas gracias por el aporte, está muy completo!!