• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Hyphens or underscores in filenames?

lsquare

Senior member
Right now I'm in the process of renaming some files of mine. I want to use a naming convention that would be recognized not just in Windows, but also Unix, Mac, and Linux. I also would like it to be conform to web standards as well. What's a good practice here? I was doing a bit of Googling and it seems like some are suggesting that hyphens are better than underscores.

Right now I'm avoiding spaces and capitalization. Any other suggestions?
 
Hypens allow google to recognise each individual word, where underscores are treated as one word:

red_bike - would get hits for "red bike"
red-bike - would get hits for "red", "bike" and "red bike"

Try it for yourself:

"laptop reviews"
"laptop-reviews"
"laptop_reviews"

You'll see which has the lowest hits.
 
I prefer hyphens, or making everything one long word, perhaps with the first letter of each word capitalized. Linux has issues with underscores. It works, but it looks ridiculous in a directory listing.

I'm not strict about it, but this is my order of preference...

redbike
RedBike
red-bike
red_bike
 
I personally prefer underscores, but it seems like hyphens are more common on the internet. Maybe it is because links are underlined so the underscores are hidden.
 
I prefer hyphens, or making everything one long word, perhaps with the first letter of each word capitalized. Linux has issues with underscores. It works, but it looks ridiculous in a directory listing.

I'm not strict about it, but this is my order of preference...

redbike
RedBike
red-bike
red_bike

Are you sure about that?
 
Hmm... No, I'm not sure. My clan mate's Linux files server puts weird characters in place for an underscore if I remember right. red_bike will become red#$bike, or something like that. Maybe I'm remembering wrong? Could that be for names with spaces?

You're thinking spaces.

my file.jpg

becomes

my%20file.jpg
 
So far I don't think we have quite reach a consensus here on hyphens or underscores. Which is the "best"?
 
So far I don't think we have quite reach a consensus here on hyphens or underscores. Which is the "best"?

There is no "best". You use what works for you. I use both, as needed. I use hyphens for related information, and underscores as I would a space. So a file for a class (CS 3358), coming from a "Assignment" folder, named "file.cpp" I would name "CS-3358_Assignment_file.cpp", and that system is just for that type of file or folder. So it's whatever works for you. Windows and/or linux shouldn't have any issues with either special characters.
 
There is no "best". You use what works for you. I use both, as needed. I use hyphens for related information, and underscores as I would a space. So a file for a class (CS 3358), coming from a "Assignment" folder, named "file.cpp" I would name "CS-3358_Assignment_file.cpp", and that system is just for that type of file or folder. So it's whatever works for you. Windows and/or linux shouldn't have any issues with either special characters.

I see! Thx for the info. So would you say that hyphens or underscores will have no issues with the web or any modern OS whatsoever?
 
I see! Thx for the info. So would you say that hyphens or underscores will have no issues with the web or any modern OS whatsoever?

Not that I have ever ran into, with XP - Win 7, including Server OS's, as well as several distros of linux. And many of those distros have had apache in use. But if something you use does have an issue, change your system to fit. 🙂
 
I tend to use spaces myself, with bash's tab completion escaping them for me and the fact that GUI apps handle spaces just fine I don't see a problem.
 
Back
Top