STOP! Don't Name That File Without First Watching This Video.

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
today I want to talk to you about file naming conventions what is a file naming convention it is a framework or a set of guidelines that helps you in naming files on your system hopefully you give file names descriptive names things that help you immediately identify what that file is it also helps you search through files on your system because by giving them descriptive names and by sticking to a convention a certain set of rules in your naming you know the kinds of search patterns actually search for files on your system right imagine you have a large database of files and you didn't employ a file naming convention and you used really generic non-descriptive names so you had file one file two file three file 1 million you have no idea how to identify these files from each other you don't know the contents of any of these files because of the names are also non-descriptive generic names and you really can't search for a particular file on your system because again the name games don't really tell you anything they don't give you a clue to what that file actually is so it's pretty obvious what the benefits of using a file naming convention are it's why a lot of large organizations and projects and corporations they have their own file naming conventions that they expect all of their people to actually abide by that way if you're adding a file to a file server and it's a collaborative effort that a lot of people are contributing to that everybody is using lowercase rather than uppercase names or hyphens rather than underscores or whatever it happens to be they come up with their own guidelines that way the naming convention is the same it just makes organization a lot easier and for you the individual User it's really important to establish your own file naming convention now before you start collecting large amounts of files and data on your system if you're one of these people that are data hoarding you're going and downloading all of this stuff from the internet and you have terabytes of data on your file system system and you didn't rename this stuff yourself you just took the names as it came from you as you downloaded all this stuff on the internet and then you've got some file names with uppercase some with lowercase some with hyphens underscores spaces it's not there's no consistency to it and ultimately what this will lead to is misplace files or lost data so let's talk about creating your own file naming convention what are the steps so what do you actually need to include as part of a file name the biggest thing you need to do is make sure that your file names are descriptive in some way that the name of that file actually gives you some clue as to what the contents of that file may be for example uh project names that's if you've got a GitHub gitlab project you're a programmer or developer having the name of the project as part of the file name might make sense in some cases the author name right makes sense in a lot of cases uh date uh timestamp if you work from multiple locations you create files from multiple locations that all go into a database for example sometimes I do stuff at home sometimes I do stuff at work or multiple office locations for a workplace sometimes adding the location to the file name makes a lot of sense also version numbers for projects again typically for software projects but that makes a lot of sense as well to always include a version number but other than adding a descriptive name there's other things you need to consider as far as the format of the file name when you're coming up with your naming convention let me switch over to my desktop and let me go ahead and launch a terminal and I'm gonna zoom in if I do a LS it'll be easier to do with this file management stuff in a terminal today that way I can zoom in that way you can actually see some of the file names going on in my home directory let me scroll back toward the top here now probably 95 of the files and directories in my home directory I didn't name myself these were automatically generated files and directories that were created when I installed certain programs and you can see some of the inconsistency here with the naming of these files and directories you can see ATT underscore backups and then the directory right after it audacity Dash data right one of them uses an underscore one of them uses a hyphen or a dash or a minus symbol if I scroll down you can see some other directories there's a underscore here are hyphens here is another underscore and then of course all the directory names we've talked about so far looked at these were all lower case but if I keep on then we get to the uppercase directories write the game again with the uppercase letter and I actually have mine organized so that the uppercase and lowercase are not separated but a lot of times the ls output in your terminal will actually group them first lowercase then uppercase which can be confusing and really I think one of the most important rules with any file naming convention I think everybody should follow this particular rule every file name should be lowercase it should just be all lowercase and the reason for this is because there are some operating systems that are a case insensitive when it comes to file names such as Microsoft Windows meaning let me get back to the terminal let me get to the command line here Microsoft Windows is going to see file one with a capital f and file one with a lowercase f as the exact same fall which means Microsoft Windows can't handle that it's a duplicate right so if you're downloading something from the web and one of the them is capital file one and the next one is lowercase file one guess what Windows is going to do the second file one is going to overwrite the first one because it sees them essentially as the exact same name because it doesn't care about capitalization now the problem is every sane operating system on the planet such as Linux sees file 1 with a capital f and file one with a lowercase f as two different files which logically makes sense but again because Windows doesn't and you're going to interact with Windows computers at some point especially the way we are connected nowadays through the internet you know Windows machines talk to Linux machines talk to MAC machines Etc of just because of the limitations of Windows even if you're not a Windows user I'm not a Windows user still just for convention because I'm going to put stuff on the internet that Windows users May download it's best just to stick to all lowercase all the time when it comes to file names now I know some of you are going to say well I've got files on my system that begin with capital letters or employee capital letters somewhere in the name how do I go back and change those to lower case the great thing about Linux is we have a lot of really cool command line utilities that can really take care of this problem almost instantly for you I did a video a while back on renaming files on a Linux system and I talked about some command line programs such as the rename command on Arch Linux it's actually Pearl Dash rename but I think on Debian and Ubuntu based system has just renamed without the parole at the beginning but let me CD into a test directory I have got a test directory that's got some files in it and let me create some files with some uppercase letters so I'm going to do a touch and I'm gonna do touch test all caps right so if I do a LS you can see there is test well I can use that Pearl rename command again on Debian or Ubuntu it's just rename without the Pearl at the beginning and then I give it the following y slash capital A through capital Z and then slash lowercase a dash lowercase z so essentially this is a substitution command standard kind of substitution command you would use with things like Sid for example it's going to find every instance of capital A through capital Z and replace it with the lowercase A through Z and which files I mean I could specify a file but I'm just going to do it to every file in this particular directory so this would be really useful if you had like a thousand files in a directory and they employed uppercase characters and you wanted to lower case them all you could just run that command if I do a LS you can see test all caps that's now test lowercase how cool is that another naming convention that I think everyone should employ is make sure that you don't include spaces ever in a file or directory name spaces do not belong if you want to actually separate words don't use spaces use either hyphens or underscores because spaces just cause problems let me name something with a space so maybe I want to do space and then I've got to escape the space here in the cap the command line so I've got to do a backslash space to actually symbolize a space in the name and then I'll do file and if I do LS now I should have space space fall right as a name and that's kind of confusing because I included the word space and then an actual space and then file and many people if you're not employing a file naming convention already at the same thing with the capitalization you're you already got thousands of files on your system that have spaces how do you get rid of the spaces well the same rename command we used before and remember Arch is Pearl Dash rename Debian and Ubuntu I believe is just rename and we could do the same substitution except instead of doing what a through z we're going to do a substitution of spaces what are we going to substitute spaces with well in my case I'm going to choose hyphens if you want to you could choose underscores but I'll choose the hyphen and if I do it LS after running that command space file with a space between the words is now space Dash file now I used hyphens to separate those words if you wanted you could also use underscores that's what a lot of people would choose so if I did that you could see space with the hyphen space with the underscore file and which one is the best I prefer hyphens and it seems most people these days prefer hyphens for a separator the underscore of the people that use underscores would argue that it's a little easier to read well it's easier to read in some circumstances the problem is especially when you're dealing with hyperlinks web links on a web page and you have file names directory names that have those underscores well if the hyperlinks are underlined and then you have underscores as part of the name that's kind of that's hard to read it's hard to recognize that those underscores are even there if these text itself is also underlined now generally speaking most people are going to tell you that if you choose hyphens or underscores for your separators stick with one and only use one so if you choose hyphens always use hyphens never use underscores and the same thing with underscores always use underscores never use hyphens and this really becomes a real argument in favor of hyphens because if you only use underscores well things like date and time Stamps will look a little weird being separated with underscores rather than hyphens and a lot of people what they'll end up doing is they'll make exceptions right the file names will include underscores except for the time snap because you know that really needs to be a hyphen so it actually looks right so you end up employing both and for me since you're going to use hyphens anyway for things like time stamps or for hyphenated words even that will come up in file names just use hyphens all the time and again it seems that most people these days just recommend sticking with hyphens rather than underscores but there are some big exceptions for example Wikipedia on the web if you go to Wikipedia right now and click on any webpage page in Wikipedia they are using underscores for their file names you can look at the URL for that particular page and the file name for that URL is going to include underscores rather than hyphens but again it's not about necessarily all of us using the same file naming convention it's whatever one you pick be consistent with yourself another good rule of thumb to follow is don't include any special characters in your file names so things like an exclamation point question mark colon curly braces and brackets things like that don't include any of that stuff in a file name and the reason for that is because if these files end up on the web and false even if they're not intentionally designed to be for example a web page so many times people are sharing them through web links and the web does not handle special characters as part as file pass so don't include that as part of your file name ever it just should become a rule so you never accidentally have a situation where you create a file name with some of these special characters that a web browser is going to just throw a fit about and some special characters that I would definitely avoid because they have different meanings especially like on Linux don't use a dollar sign as part of a file name because dollar sign at the shell means something right it typically is uh means a variable and don't use ampersine you know the and sign don't use that symbol actually write the word and if you want it as part of a description for a file name don't use a slash ever in a file name because slashes are part of file pass right that's the separator between directories and a file path so don't use it in a file name and lastly let's talk about dates if you're going to add a date to a file name which is a good idea make sure the date is always in the same format and the format it needs to be in is ISO 8601 which is year month day with the year being the four digit Year let me show you this so we want the date to be in this format right there right so four y's two M's two D's if you want to separate it I mean obviously I mentioned typically you'd have dates and time separated with hyphens you get separated if you think that's easier to read which most people probably would or you can leave it as all one string that's fine as well so let me show you how I would name a file maybe I was writing some show notes for today's presentation today's video I wouldn't make a name such as fall naming notes and then I would add a date for example today's date let me actually look at what today is 2022-10-01 that would be the name right a matter of fact I could go ahead and create this I could do touch and then that file name if I do it LS you can see that's a really nice file name it's descriptive tells me exactly what that file contains as far as the contents and it has a date in case I had file naming notes on different days I know exactly the date of that particular fall now I know a lot of people are going to say that's kind of tedious especially adding a date to every single file name you ever create but you can automate this process so I'm in the fish Shield today so let me clear the screen here one thing I can do if there's a date command there's a standard date command that's part of the command line on Linux if I do date there is what the date command typically outputs now if I only want the iso 8601 format that we talked about earlier I could use date with the dash capital I flag and that actually gives me the exact date in the format I want to be a part of a file name so what I could do is inside the shield here in fish I could set this variable date and I could set that to be date Dash I now if you were in bash you would have to do a different command let me go ahead and run this and Bash you would do date equals and then dollar sign and then date Dash I now what these commands will do is they tell the shell as long as I'm in this current session of this shill anytime I use the variable date it is the output of the date Dash I command is all we've done so I've already run set date to date Dash I so now I could create a file name I could do what I did before I could do Touch file Dash naming Dash notes Dash and then what I could do is now just do dollar sign date and if I hit enter and I do an LS nothing happens because we already have file naming notes 20 22-201 so all it did is just touch the same file we had already created so let me actually remove the existing file and let me rerun that command just to verify that that works so Touch file Dash naming Dash notes Dash and then dollar sign all caps date and now LS and you can see there is the fall that it created and if you also wanted to add a timestamp along with the date you could do that just run a man on the date command and you can see all the options as far as output for the date command you can include all kinds of stuff as far as time date and different formats the week of the year of your time zone information if you wanted that so you could do all of that one thing about adding times uh stamps if you're going to add the time make sure that you don't actually use colons as part of a clock time because that's something most people would do because it stands out it's very readily apparent that hey that's the time here's the thing colons are a special character we've already talked about don't use special characters as part of your file name so replace those colons in the time to just using hyphens so these were just some basic guidelines some of my thoughts as far as file naming convention regions that I like to employ maybe you guys will find this useful I do think everyone should spend at least a little bit of time thinking about how they name things on their system again just so things are better organized and just so stuff doesn't get lost on your file system now before I go I need to thank a few special people I need to thank the producers of this episode Gabe James Matt maximum Mitchell Paul West Mario bone homie Alex armor Dragon Chuck commandering read Yokai George Lee Marsh drum need urian Alexander Paul peace origin Fedora Polytech realities for less for private role and Stephen tool sniffler and Willie I messed that up and I was speaking in a really high-pitched voice there for no reason at all but these guys they're my highest year patrons they are the producers of this episode the show is also brought to you by each and every one of these fine ladies and gentlemen all these names you're seeing on the screen right now these are all my supporters over on patreon because I depend on you guys the community if you like my work and you want to see more videos about Linux and fruit open source software subscribe to distro tube over on patreon peace guys do you prefer hyphens or underscore Wars tell us in the comments down below
Info
Channel: DistroTube
Views: 60,325
Rating: undefined out of 5
Keywords: linux, mac os, windows, bsd, operating systems, gnu coreutils, file names, file naming conventions, file naming system, file naming best practices, rename command, date command, file name timestamp, linux for beginners, linux terminal, windows vs linux, windows vs mac, dashes vs underscores, hyphens vs underscores, spaces in file names, terminal commands, learn linux, switch to linux, distrotube, linux terminal tricks, linux tutorial, linux tips
Id: Wu0CxdflECY
Channel Id: undefined
Length: 18min 37sec (1117 seconds)
Published: Thu Oct 06 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.