In Linux, the file is a central key concept. When administering a Linux system, you have to deal with 1
lots of files and knowing their type is really important. In this lecture 2
we'll see what type of files are available. 3
Linux determines the type of a file via a code in the file header. 4
It doesn't depend on the file extension. 5
In fact, it's quite common in Linux for files to not have any extension at all. 6
These are only a few examples of important system files that do not have an extension. 7
The shadow file, which stores the user's passwords, the group file, which stores the groups and many 8
more. 9
They have no extension. Also all executable files or commands do not have extension. 10
These executable files have no extension. 11
In Windows, they would be .exe files. 12
This is one of the differences between Linux and Windows. In Linux file extensions do not matter so 13
much. They are mostly for humans to find out visually what the specific file could represent. 14
When you see a file name which ends in .log, then it's probably a log file or a file which ends 15
in .conf 16
it's probably a configuration file. 17
This is probably a configuration file because it ends in .conf 18
I want to give you just one example that shows that extension doesn't matter. 19
I have this image on my desktop and I run the file and the path to the file to see its type, so file 20
Desktop/Linux.jpeg 21
And it's a jpeg file. 22
Now I'll rename the file to change its extension to pmg 23
The source file Linux.jpeg and the destination. 24
This is how you rename a file in Linux. Will have a dedicated lecture on this. 25
Now it's a .pmg file; if I run file command again will see that the file type remains the same, even 26
though I've changed its extension. 27
file and the path to the file. 28
it's of type JPEG image data. 29
It's not a pmg file. Linux determines the type via a piece of information in the file header. However, graphical 30
applications might require the file to have a specific extension in order to open it. 31
If you have a text file and change its extension to JPEG, then you cannot open that file any more by double clicking 32
with the mouse on it. 33
If I rename the file again in the write.txt and try to open the file using the graphical environment, 34
using a graphical application, it won't work. 35
So extensions are useful only for graphical applications. 36
It still contains JPEG image data. 37
Let's take a closer look at the output of ls-l command, which is one way of finding what 38
type of specific fileis; this is indicated by the first character. 39
If you see a hyphen, it means that's a regular file -d indicates a directory, which is a special 40
type of file. 41
I'm listing the contents of /etc/. -l indicates a symbolic link, which is like a shortcut, and other 42
possible characters and file types are b, which means a block device, for example, ls-l/ 43
dev/sda1 44
This is a block device and c indicates a char device. 45
All these files are of type char device. 46
Device files represent logical hardware devices like a disk, a partition or a serial console port. 47
If you see an s 48
the file is a type of socket. 49
This is a socket; s on the first position. 50
This is used by processes to communicate and has nothing to do with the socket term used in TCP/IP 51
Networking. 52
And the last possible option for the first character is a p which indicates a named pipe. 53
Let's find the name pipe. 54
This is a nameed pipe. 55
The first character is p. 56
Pipes aren't used all that often. 57
It's possible that you won't use them explicitly at all. 58
However, a named pipe, like a socket, provides an easy way for the processes to communicate. 59
Using named pipes, you could send the output from one command to another and end up with only the data 60
you want to see without selecting and formatting the entire output. 61
Another way to classify a file is to run ls with the capital F option. 62
This will add the symbol after the filename according to its type. 63
A / indicates a directory; no symbol added indicates a regular non-executable file; 64
An @ sign indicates a symlink; 65
and the 66
an = sign indicates a socket; 67
And a pipe |, a vertical bar, indicates a named pipe. And if you find all of this confusing, you can 68
run the file command to find out the type of any file; note that none of the methods shown in this lecture 69
determined the file type based on the file name extension. 70
Let's see some examples with the file command. 71
This is a directory. 72
This is a regular file. 73
An ASCII text file. 74
By the way, -f will add a star, an asterisk to executable files. 75
Let's see a symlink. 76
This is a symlink, so file/etc/vtrgb 77
Symbolic link and file/ and an asterisk 78
will show information about all the files in a directory. 79
This is a socket. 80
This is an empty file. 81
This is named pipe. 82
This is a directory with the sticky bit set and so on.