Linux Files

One of the things that made the Unix operating system unique when it was first created back in the 1970s was that it treats everything on the computer system as a file: hardware devices, data, network connections, everything. That simplified the way programs interact with hardware, and with each other, because no matter where your data comes from, the Unix operating system handles it the same way. While that may seem odd, it’s what revolutionized the computer world and made the Unix operating system so popular.

However, because everything is a file, there are some issues that you’ll run into. One of those issues is trying to identify file types. This section walks through how Linux handles file names and shows some hints on how you can determine file types on a Linux system.

Determining File Types

Linux data files cover a pretty wide range of file types—everything from text data to executable programs. Because Linux files aren’t required to use a file extension, it can sometimes be difficult to tell what files are programs, what files are text data, and what files are binary data. Fortunately there’s a command line utility that can help.

The file command returns the type of the file specified. If the file is a data file, it also attempts to detect just what the file contains:

An output of the file command is shown.
Description

In this example, the myprog.c file is a C program text file, and the myprog file is a binary executable program.

File Names

The first thing you’ll notice as you peruse through the directories on your Linux system is that Linux has a different file naming standard than Windows. In the Windows world, you’re probably used to seeing a three- or four-character file extension added onto each file (such as .docx for Word documents). Linux doesn’t require file extensions to identify file types on the system (although they’re allowed if you like to use them).

Linux file names can be any length of characters, although 255 is a practical limit for file names (when file names get longer than that some programs have trouble handling them). Linux file names can contain upper and lower case letters, numbers, and most special characters (the only characters not allowed are the forward slash and the NULL character). Linux file names can contain spaces, as well as foreign language characters. However, the file name should always start with a letter or number.

Here’s an example of some valid Linux file names:

Line 1: testing. Line 2: A space test space file dot t x t. Line 3: 4 underscore data underscore points. Line 4: my dot long dot program dot name.

Hidden Files

Another feature of Linux file names that is different from Windows is hidden files. Hidden files don’t appear in normal file listings. In the Windows world, you use file properties to make a file hidden from normal viewing. When a normal user displays the directory listing, the hidden files don’t appear, but when an administrator displays the directory listing, the hidden files magically appear in the output. This feature helps protect important system files from being accidentally deleted or overwritten.

Linux doesn’t use file properties to make a file hidden. Instead, it uses the file name. File names that start with a period are considered hidden files, in that they don’t appear in a normal listing when you use the ls command or displayed when using a graphical file manager tool. You can however use options to display hidden files in the ls command or the file manager tools. FIGURE 7-2 shows setting the Files graphical file manager tool in Ubuntu to display hidden files.

A screenshot displays hidden files using Files in Ubuntu.

FIGURE 7-2 Displaying hidden files using Files in Ubuntu.Courtesy of Canonical Ltd.

Description

To display hidden files with the ls command, you need to include the –a command line parameter:

An output shows hidden files using the l s command with the hyphen a command line parameter.

An output shows hidden files using the l s command with the hyphen a command line parameter.
Description

In this example, the ls command by itself only shows a few directories in the Home directory. Adding the –a parameter shows all of the hidden files in the directory. Many Linux programs store any settings that you make as a hidden file in each users’ Home directory.

File Inodes

Linux has to keep track of a lot of information for each file on the system. The way it does that is by using index nodes, also called inodes. The Linux operating system creates an inode for each file on the system to store the file properties. The inodes are hidden from view; only the operating system can access them. Each inode is also assigned a number, called the inode number. This is what Linux uses to reference the file, not the file name. The inode numbers are unique on each physical disk partition.

Linux also creates a table on each disk partition, called the inode table. The inode table contains a listing that matches each inode number assigned to each file on the disk partition. As you create and delete files, Linux automatically updates the inode table behind the scenes. However, if the system should abruptly shut down (such as due to a power failure) the inode table can become corrupt. Fortunately for us, there are utilities that can help reorganize the inode table and help prevent data loss. Unfortunately though, if the inode table does become unrepairable, you won’t be able to access the files on the disk partition, even if the actual files are still there!

To view the inode number for files, use the -i option in the ls command. You can combine it with the -l option to produce a long listing to show more details about the file:

An output shows the result of using the l s command with the hyphen i l option.
Description

The first number displayed in the long listing is the inode number for each file. Notice that the inode number for the myprog.c file is the same as the copy.c file. That means there is a hard link between those two files. The hard link points to the same physical disk location as the original file, so the inode numbers are the same.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.19.174