We have seen how we can check files of a directory from another directory, we have seen how we can navigate to different directories in the file systems, we know how we can see files in a directory, the concept of our absolute path and relative path is now not confusing to us anymore. Now we will try to dive deeper. We can save various files in Linux. Although we can save any type of file, Linux does not know what type a file is or what information is saved in a file. Understanding the content of a file is responsibility of the program and represent to the user, which is being used to open the file. For example, we can save pictures, videos, programming files and other type of files in a directory, Linux/UNIX cares least, all it knows is how to store the information safe and how to retrieve from disk.
Although Linux does not even know what is contained in a file, we can have an idea about any file with a program. Name of this special program file. We will see some examples of this program -
We can navigate to a directory and use this command to see what a file contains and we can use a proper command to open a file. This helps us at times when dealing with different file types or a file whose extension is unknown to us -
In the previous example, we used absolute path and relative path to run the file command; time for some more examples which will strengthen the understanding of absolute path, relative path and file command as well-
The file command sometimes not only shows the type of the file content but some details as well, which sometimes proves to be very useful.
Now time to check some more facts about Linux/UNIX File System -
File or directory name is case sensitive
That means file1.txt, file1.txt, fIle1.txt, fiLe1.txt, filE1.txt, FILE1.txt are all different files on UNIX/Linux. So if we save a file as file1.txt and want to open as File1.txt, we can not do that. Let's look at an example -
Notice that there is a file named file1.txr in my home directory but when I tried to open the file by typing less File1.txr , Linux showed me an error and explained to us that the file I want to open is not in that directory.
The Linux system does not necessitate a file to have an extension
The extension is the part of the file name from the last . to the rest of the last of the file name. Let's check some files and there extensions -
Here Stellar Astrophysics, The Hackers Underground Handbook are directories, the rest are files and the extension of the Pythagorean Theorem.pdf file is .pdf and ebooksclub.org__Modern_Graph_Theory.djvu file extension is .djvu
In many cases, extensions can be used to understand the file and run the required commands on the file, but the file system does not mandate a file to have extension, there may not be any extension of the file. For example, there is no extension of the files below -
But the amazing thing is that despite the file extension is missing, we can run the file command and know what kind of file it can be-
If the first character of a file or directory name is . in UNIX/Linux system it is called a hidden file, and generally these files are not visible. We have to use another method to check the hidden files (we will see how they are done). Usually hidden files serve the purpose of security and prevents unnecessary damage to system or configuration files. Generally any Linux system has many configurations, on which the system runs, so if a normal user changes or deletes these files, the system will not work properly, so these files are typically hidden files. Although there are other methods for file security, hidden files are also useful.
Besides security, there is another reason behind it, all the files are not always necessary, it is difficult to find the required files if every time system shows us all files. Let's see what are the files present in my home directory -
Looking at the difference between the two outputs, you can understand why hidden files are important for day to day use.
Next we will take a look at the other file system commands and check what more we can do with them.