1 00:00:00,180 --> 00:00:05,160 Hello the beautiful people and welcome to this video all about file extensions in Linux. 2 00:00:05,160 --> 00:00:08,220 Now on operating systems such as Windows file extensions. 3 00:00:08,220 --> 00:00:11,490 Allow me to tell what type of file that you're dealing with at a glance. 4 00:00:11,490 --> 00:00:17,130 For example, we know that files with names ending in txt are text files and files with names ending 5 00:00:17,130 --> 00:00:23,550 in jpg or PNG are likely to be images, but in Linux, file extensions usually don't matter and the 6 00:00:23,550 --> 00:00:27,210 system tends to look at the contents of the file rather than just its name. 7 00:00:27,330 --> 00:00:30,720 But sometimes file extensions really do matter. 8 00:00:30,720 --> 00:00:36,150 So in this video, we're going to take a bit of a deep dive into understanding file extensions in Linux 9 00:00:36,150 --> 00:00:39,060 and shine some light onto their strange behavior. 10 00:00:39,060 --> 00:00:43,050 And by the end of the video, you'll know what freedoms the Linux operating system gives you when naming 11 00:00:43,050 --> 00:00:46,470 your files, what interesting things can happen, and what you need to be aware of. 12 00:00:46,500 --> 00:00:51,390 Oh, and you'll also have a new command in your toolkit that will help you when dealing with files on 13 00:00:51,390 --> 00:00:52,320 your file system. 14 00:00:52,320 --> 00:00:54,600 So this is all very useful stuff, very exciting stuff. 15 00:00:54,600 --> 00:00:56,880 Let's go ahead and jump right into it. 16 00:00:57,610 --> 00:00:58,120 All right. 17 00:00:58,120 --> 00:01:00,850 So I've gone ahead and put some files here on my desktop. 18 00:01:00,880 --> 00:01:06,640 First of all, I've got an image of Tux, the traditional Penguin logo for Linux here in P and G format. 19 00:01:06,670 --> 00:01:11,830 Now, Tux, in case you're interested, is short for the word tuxedo, which is a fancy type of black 20 00:01:11,830 --> 00:01:16,720 and white suit, usually worn by waiters and partially dressed people at high class parties. 21 00:01:16,750 --> 00:01:21,040 Now penguins are said to look like they're wearing little tuxedos because of their black and white coloring. 22 00:01:21,040 --> 00:01:25,090 And that's where Tux gets his name from the word tuxedo, in case you were interested. 23 00:01:25,090 --> 00:01:30,340 But besides a picture of of the lovely tux here and random trivia, I've also got a text file here with 24 00:01:30,340 --> 00:01:33,130 some Shakespeare in it called Shakespeare Text. 25 00:01:33,130 --> 00:01:37,150 And I also have a spreadsheet file with some random numbers in it. 26 00:01:37,600 --> 00:01:44,820 So let's go ahead and take a look at the file command to see how Linux handles file types. 27 00:01:44,830 --> 00:01:49,810 So if I go ahead and open a terminal using the control alternate keyboard shortcut and just drag it 28 00:01:49,810 --> 00:01:51,820 a bit out of the way so we can still see the files. 29 00:01:52,240 --> 00:01:55,580 I'm going to introduce you to a new command called the File Command. 30 00:01:55,600 --> 00:02:00,430 Now, the file command will tell us basically what type of file that we are dealing with. 31 00:02:00,460 --> 00:02:07,930 So, for example, if we try to have a look at tux here, if we do file tux PNG, we actually need to 32 00:02:07,930 --> 00:02:09,280 go to our desktop first. 33 00:02:09,280 --> 00:02:11,230 So let's shift over to our desktop. 34 00:02:11,590 --> 00:02:14,470 Clear the screen and do file tux. 35 00:02:14,470 --> 00:02:19,720 And I can actually just just so you see, I can actually just with t you go ahead and press tab and 36 00:02:19,720 --> 00:02:21,850 it will autofill that as well just showing you that tab. 37 00:02:21,850 --> 00:02:26,320 Auto completion works perfectly fine for far names, just like it does for folders. 38 00:02:26,320 --> 00:02:28,510 So it's a great, great thing that we learned in the last video. 39 00:02:28,580 --> 00:02:35,890 Okay, so let's have a look file of tux PNG and it will tell us that this is PNG image data. 40 00:02:35,890 --> 00:02:41,370 It'll tell us the size of the file and loads of other stuff as well, but it tells us the file type. 41 00:02:41,380 --> 00:02:41,950 Okay. 42 00:02:41,980 --> 00:02:54,340 Now if I rename txt png if I rename this to tux dot jpg, which is another type of image file, you 43 00:02:54,340 --> 00:02:55,930 can see that it's been renamed there. 44 00:02:55,930 --> 00:02:57,450 But let's do that again. 45 00:02:57,730 --> 00:02:58,120 Let's try. 46 00:02:58,150 --> 00:03:01,690 File of txt jpg and let's see what happens. 47 00:03:02,740 --> 00:03:07,890 Now you can see here that it's still says that it is a p and g file. 48 00:03:07,900 --> 00:03:08,980 Now this is important. 49 00:03:08,980 --> 00:03:13,480 Point number one in Linux file extensions don't matter. 50 00:03:14,020 --> 00:03:19,960 Unlike Windows, Linux doesn't determine file type using the file extension, but instead it reads a 51 00:03:19,960 --> 00:03:22,930 piece of code inserted at the top of every file. 52 00:03:22,930 --> 00:03:28,030 And that piece of code is known as a header and it serves as a kind of label for Linux to read. 53 00:03:28,030 --> 00:03:31,480 And when Linux reads that label, it knows the file type. 54 00:03:31,480 --> 00:03:37,180 So changing just the name of the file won't make a difference because that file header won't have changed. 55 00:03:37,480 --> 00:03:41,350 Okay, so here we have some Shakespeare script in text format. 56 00:03:41,350 --> 00:03:46,690 So if I open that up, you can see that there is plenty of text in there which I just copied and pasted 57 00:03:46,990 --> 00:03:48,690 from Romeo and Juliet. 58 00:03:48,760 --> 00:03:51,570 Okay, so that's the kind of stuff that I do. 59 00:03:51,580 --> 00:03:59,350 So when we check the file type we have here, if we do file Shakespeare text, it'll tell us that it 60 00:03:59,350 --> 00:04:01,570 is an ASCII text file. 61 00:04:02,260 --> 00:04:08,770 But now if I try to turn this into a PDF, so if I rename it and try to say, okay, this is now Shakespeare 62 00:04:08,810 --> 00:04:15,310 dot PDF and I rename it now the system, it appears to have changed the icon. 63 00:04:15,310 --> 00:04:15,580 Right? 64 00:04:15,580 --> 00:04:21,970 It looks like that's a PDF file, but if I try to run the file file command again file Shakespeare dot 65 00:04:21,970 --> 00:04:27,490 pdf, it still tells us that it's ASCII text. 66 00:04:27,580 --> 00:04:35,380 So Linux read the Linux, read the header of the file and saw that it was still a text file. 67 00:04:35,410 --> 00:04:41,140 But what happens when we try to open it because it looks like the system thinks it's a PDF because you 68 00:04:41,140 --> 00:04:44,830 can see the logo is changed but it's still telling us that it's a text file. 69 00:04:44,830 --> 00:04:45,610 What's going on there? 70 00:04:45,610 --> 00:04:47,020 Why is it think it's different? 71 00:04:47,050 --> 00:04:49,090 Well, if we try to open it, what happens? 72 00:04:50,150 --> 00:04:51,650 Well, now we get an error. 73 00:04:51,920 --> 00:04:58,610 We see that the default program to open files with names ending in PDF is a PDF reader. 74 00:04:58,610 --> 00:05:03,620 And when we try to open this file in the PDF Reader, we get an error from the program as it's trying 75 00:05:03,620 --> 00:05:05,360 to open our file as a PDF file. 76 00:05:05,360 --> 00:05:13,010 And what the system basically did is say, Ah, that's a file that ends in PDF, it's probably a PDF 77 00:05:13,010 --> 00:05:17,600 file, so let me be helpful and allow the user to open it in a PDF viewer. 78 00:05:17,930 --> 00:05:24,050 Now obviously a PDF reading program isn't designed to read text files, it's designed to read PDFs, 79 00:05:24,050 --> 00:05:26,050 and that's what's causing the issue here. 80 00:05:26,060 --> 00:05:26,810 Now, this is important. 81 00:05:26,810 --> 00:05:28,490 This is an important distinction to make. 82 00:05:28,520 --> 00:05:34,580 Important point number two, although the operating system will know what file format the actual file 83 00:05:34,580 --> 00:05:40,340 is by reading the header, the extra programs that are installed on top of the operating system such 84 00:05:40,340 --> 00:05:46,370 as this PDF viewer are trying to open the files that might require certain formats or other file extensions 85 00:05:46,370 --> 00:05:47,570 in order to work. 86 00:05:47,570 --> 00:05:52,340 So what's happening is it's all this to make this automatically want to open as a PDF. 87 00:05:52,340 --> 00:05:59,660 It just saw the file name, it just looked at the file name, but the content is still text and it says 88 00:05:59,660 --> 00:06:00,920 here are file type. 89 00:06:00,920 --> 00:06:07,400 Plain text is not supported, but it got the program got tricked, it saw the file name and that's why 90 00:06:07,400 --> 00:06:09,020 it wanted to open it as a PDF. 91 00:06:09,020 --> 00:06:14,810 If I rename it back to text, just change the text, change that back. 92 00:06:14,810 --> 00:06:17,900 You'll see now that it will open fine as a text file. 93 00:06:17,900 --> 00:06:20,390 Okay, so that's the important distinction to make there. 94 00:06:20,390 --> 00:06:24,800 The programs that are installed on top of the operating system such as PDF viewers and stuff like that, 95 00:06:24,800 --> 00:06:30,890 they might need the file to have a specific file extension in order to open them, but the operating 96 00:06:30,890 --> 00:06:33,140 system itself does not care. 97 00:06:33,140 --> 00:06:34,430 So let's see this in a bit more detail. 98 00:06:34,430 --> 00:06:38,330 If I take a look at the spreadsheet here, it's called data downloads. 99 00:06:38,360 --> 00:06:46,020 If I do file of data downloads, it says that it's an ODS file which stands for open document spreadsheets. 100 00:06:46,400 --> 00:06:52,130 Okay, now this means we can open it up in LibreOffice Calc, which is basically the Linux version of 101 00:06:52,130 --> 00:06:54,710 Microsoft Excel or the Apple equivalent. 102 00:06:54,710 --> 00:06:58,850 It's like this spreadsheet program and it's got it's got a few numbers in there. 103 00:06:58,850 --> 00:06:59,350 Okay. 104 00:07:00,710 --> 00:07:08,210 But, um, now if I close the spreadsheet and rename that, for example, to a text file, so if I rename 105 00:07:08,210 --> 00:07:15,500 it to data txt rename that, you can see that now it wants to be opened up in a dot txt format. 106 00:07:16,160 --> 00:07:16,480 Okay. 107 00:07:16,610 --> 00:07:20,030 And now I try to open that up in LibreOffice Calc. 108 00:07:20,030 --> 00:07:25,520 So if I click up here, I type calc and it comes up, I click LibreOffice Calc. 109 00:07:26,430 --> 00:07:27,780 Wait for that to boot up. 110 00:07:28,350 --> 00:07:28,710 Go on. 111 00:07:28,710 --> 00:07:30,750 File open. 112 00:07:31,500 --> 00:07:33,090 Go to my desktop. 113 00:07:33,090 --> 00:07:36,890 So home and then desktop and then try to open up data like text. 114 00:07:38,340 --> 00:07:41,010 You can see now that we've got all kinds of problems happening here. 115 00:07:41,310 --> 00:07:43,860 So if I tried to just open it like that, let's try and click. 116 00:07:43,860 --> 00:07:45,770 Okay, we're going to get an error. 117 00:07:45,780 --> 00:07:46,320 Okay. 118 00:07:46,470 --> 00:07:52,410 And this is because the dot txt file extension is fooling LibreOffice Calc. 119 00:07:52,530 --> 00:07:58,250 LibreOffice Calc made the mistake of reading the file extension and trying to open the file as a dot 120 00:07:58,320 --> 00:08:00,030 text file. 121 00:08:00,600 --> 00:08:02,280 Where is the actual content? 122 00:08:02,280 --> 00:08:05,820 As we can see, here is a spreadsheet file. 123 00:08:05,820 --> 00:08:07,140 It's not a text file. 124 00:08:07,170 --> 00:08:07,510 Okay. 125 00:08:07,590 --> 00:08:15,200 But if we rename that back and we rename it so that it's data downloads now, it will open fine. 126 00:08:15,210 --> 00:08:17,250 So this is the important distinction that we need to make. 127 00:08:17,280 --> 00:08:18,280 I'm going to hammer this home. 128 00:08:18,300 --> 00:08:24,330 The file extension isn't important to the Linux operating system, but it might be important to the 129 00:08:24,330 --> 00:08:27,780 software packages that we install on top of Linux. 130 00:08:27,780 --> 00:08:33,450 So do bear in mind that don't basically don't give your file names, really weird file extensions that 131 00:08:33,450 --> 00:08:39,539 don't match their content because it might confuse third party software that is installed even though 132 00:08:39,539 --> 00:08:41,549 you don't necessarily have to. 133 00:08:41,610 --> 00:08:44,360 Okay, so let's give the spreadsheet a complete lead. 134 00:08:44,370 --> 00:08:45,180 Let's try something else. 135 00:08:45,180 --> 00:08:46,830 Let's see something quite interesting. 136 00:08:46,860 --> 00:08:50,460 Let's give the spreadsheet a completely made up file extension. 137 00:08:50,460 --> 00:08:56,850 So if I call it spreadsheet dot sublime, I'll call it spreadsheet problem. 138 00:08:58,320 --> 00:08:59,640 Now it's not interesting. 139 00:08:59,640 --> 00:09:05,250 Notice how it automatically still wants to open it up in the spreadsheet software. 140 00:09:05,310 --> 00:09:13,080 Now we notice here that we didn't fool the the the software and it still knows it's an ODS file and 141 00:09:13,080 --> 00:09:15,690 we can actually open it up if I just go ahead and double click that. 142 00:09:16,880 --> 00:09:18,680 It's going to open up perfectly. 143 00:09:18,680 --> 00:09:18,990 Fine. 144 00:09:19,010 --> 00:09:20,660 You see, we've got our data in here. 145 00:09:20,690 --> 00:09:22,370 No funny business this time. 146 00:09:22,550 --> 00:09:30,410 So why can this system, why can it open up a weird file name but not a simple one like dot txt? 147 00:09:31,040 --> 00:09:37,370 Well, the reason is the software just simply didn't recognize the dot sablan file extension, so it 148 00:09:37,370 --> 00:09:41,240 might have looked to the operating system to help determine the file type instead. 149 00:09:41,360 --> 00:09:50,960 But when we called it a dot txt file, when we actually named it directly to be txt, the software thought 150 00:09:50,960 --> 00:09:53,960 it would be a bit clever and it thought, aha, I know how to deal with this. 151 00:09:53,960 --> 00:09:57,680 And it made a little bit of a shortcut to itself and was like, I'm just going to open this automatically 152 00:09:57,680 --> 00:09:59,180 as a text file. 153 00:09:59,180 --> 00:10:05,180 But that assumption was wrong in this case because the content is a spreadsheet, we just named it txt 154 00:10:05,210 --> 00:10:10,010 and that caused the program to throw an error when it found out it wasn't a txt file after all, but 155 00:10:10,010 --> 00:10:11,330 actually was a spreadsheet. 156 00:10:11,600 --> 00:10:16,640 Now the bottom line is that you have a lot of freedom to name files, whatever you want in Linux. 157 00:10:16,640 --> 00:10:17,930 You can even call them. 158 00:10:18,320 --> 00:10:23,510 You can even give them file extensions like Dot Shibboleth, which of course you couldn't do in any 159 00:10:23,510 --> 00:10:25,220 other operating system. 160 00:10:25,910 --> 00:10:28,430 This is common for having files. 161 00:10:28,430 --> 00:10:34,190 For example, if I just try and copy and paste this, if I copy and paste this file, you know, you 162 00:10:34,190 --> 00:10:35,630 might have a backup. 163 00:10:36,560 --> 00:10:40,730 You might, for example, call one file in original so you'd say, okay, I'm going to call this one 164 00:10:40,730 --> 00:10:49,820 dot ridge, and then I'd call this one, you know, maybe I'll call another one dot back or a copy it 165 00:10:49,820 --> 00:10:54,800 and call it dot, dot, dot copy or something like that. 166 00:10:54,800 --> 00:10:55,180 Okay. 167 00:10:55,340 --> 00:10:57,980 And this is how you might name your file. 168 00:10:57,980 --> 00:11:01,640 So I'd be like, Ah, this is the original, this is the copy I can see just by looking at the file 169 00:11:01,640 --> 00:11:04,970 name without it actually affecting the way the system works. 170 00:11:05,390 --> 00:11:11,540 So this is sometimes used to allow people to read file extensions that are a lot more human readable 171 00:11:11,540 --> 00:11:15,170 than, you know, things like dot odds or dot whatever. 172 00:11:16,130 --> 00:11:20,780 But just make sure that if you name your files in such a way, don't give them file names. 173 00:11:20,780 --> 00:11:23,960 That might confuse the software that you expect to open them. 174 00:11:23,960 --> 00:11:28,040 Because not all softwares like to play ball with strange file names. 175 00:11:29,440 --> 00:11:29,830 Okay. 176 00:11:29,830 --> 00:11:33,180 So that will bring our discussion of Linux file extensions to a close. 177 00:11:33,190 --> 00:11:37,360 So as a summary of what you learn in this video, you learn that you can use the file command to know 178 00:11:37,360 --> 00:11:39,490 for sure what type of file that you're dealing with. 179 00:11:39,490 --> 00:11:43,840 And you learn that file extensions aren't important to the Linux operating system, which means you 180 00:11:43,840 --> 00:11:45,670 can name files, whatever you want. 181 00:11:45,670 --> 00:11:47,630 Yes, even dot qibla. 182 00:11:47,710 --> 00:11:52,840 But while you're doing that, make sure you try not to confuse third party software that might need 183 00:11:52,840 --> 00:11:57,640 to open the file because it might be expecting specific file extensions. 184 00:11:57,640 --> 00:12:01,720 And if you try to confuse it, then you'll just get errors in a very, very bad time. 185 00:12:01,840 --> 00:12:08,320 So coming up next in the next video, we're going to take your command line skills to a whole new level 186 00:12:08,320 --> 00:12:11,260 by looking at the concept of wild cards. 187 00:12:11,260 --> 00:12:15,460 So let's say you had a really messy desktop and you wanted to move all of your images to one folder 188 00:12:15,460 --> 00:12:19,150 and all of your PDFs to another folder and all of your spreadsheets and office files to another folder 189 00:12:19,330 --> 00:12:20,650 using the command line. 190 00:12:20,650 --> 00:12:24,010 How can you use a command that's actually so specific? 191 00:12:24,370 --> 00:12:27,370 Well, you can do that using wild cards. 192 00:12:27,370 --> 00:12:32,530 Wild cards allow you to make your commands really, really specific and also really general, thereby 193 00:12:32,530 --> 00:12:36,730 allowing you to level up in your control over what commands actually operate on. 194 00:12:36,730 --> 00:12:40,030 Now, this is an incredibly useful ability when dealing with files. 195 00:12:40,030 --> 00:12:44,170 So for another dose of epic superpowers, I'll see you in the next video.