Naming files in GNU/Linux

Chat about Linux in general
Forum rules
Do not post support questions here. Before you post read the forum rules. Topics in this forum are automatically closed 6 months after creation.
Faust

Naming files in GNU/Linux

Post by Faust »

This is not a help request , I'm just curious as to what conventions folk use to name their files/folders .

Spaces in names causes problems , in the terminal and with some text editors .
Text like " file_name " requires the shift key , and escaping characters is just way too much trouble if it's not vital .

That " other operating system " seems to encourage people to be sloppy about this , and apart from a few reserved characters
it seems that anything goes , and bad habits get formed .

I'm keen to hear other views on this ..... holiday season .... not much going on etc.
:lol:
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
Pjotr
Level 23
Level 23
Posts: 19876
Joined: Mon Mar 07, 2011 10:18 am
Location: The Netherlands (Holland) 🇳🇱
Contact:

Re: Naming files in GNU/Linux

Post by Pjotr »

You might use CamelCaseNaming... :mrgreen:
Tip: 10 things to do after installing Linux Mint 21.3 Virginia
Keep your Linux Mint healthy: Avoid these 10 fatal mistakes
Twitter: twitter.com/easylinuxtips
All in all, horse sense simply makes sense.
Faust

Re: Naming files in GNU/Linux

Post by Faust »

Pjotr wrote: Sun Jul 29, 2018 5:09 am You might use CamelCaseNaming... :mrgreen:
It's just so pretty ; so pleasing to the eye ....

I should have known that someone would mention that ! ..... and catweazel is away :lol:
User avatar
xenopeek
Level 25
Level 25
Posts: 29504
Joined: Wed Jul 06, 2011 3:58 am

Re: Naming files in GNU/Linux

Post by xenopeek »

Faust wrote: Sun Jul 29, 2018 5:03 amSpaces in names causes problems [...] with some text editors .
First I hear of it. Any text editor that can't handle filenames with spaces doesn't deserve you as a user.

As for the terminal, there aren't any problems with filenames with spaces on the terminal either. Sure, if you're using bash shell, you have to properly quote or escape them. The shell does that for you automagically when you press tab to auto complete partially typed filenames.

I use spaces, apostrophes, and letters with accents (diacritics) in filenames. I don't follow why it would be a "good habit" to replace all those with something else. Only the null character and / are prohibited in Linux filenames.
Image
User avatar
shawnhcorey
Level 4
Level 4
Posts: 217
Joined: Thu Jun 17, 2010 11:23 am
Location: The Great White North
Contact:

Re: Naming files in GNU/Linux

Post by shawnhcorey »

Traditional UNIX naming is all lower-case, words separated by hyphens.
Don't stop where the ink does.
User avatar
Portreve
Level 13
Level 13
Posts: 4882
Joined: Mon Apr 18, 2011 12:03 am
Location: Within 20,004 km of YOU!
Contact:

Re: Naming files in GNU/Linux

Post by Portreve »

I'm honestly not sure why escaping spaces in terminal is a big deal.

I name files to be normal and human-readable. If I am putting them into a situation I know has specific conventions, or specific restrictions, I will abide by those (obviously).

Mac OS and Mac OS X only prohibit one character: the full colon. Then again, back in the day, Mac OS allowed 31 character file names when DOS and Win 1.x-3.x only allowed 8. Microsoft's always been behind the curve and had crappier standards.

Oh, and I use the year-month-day standard if dates are required. It makes sorting a breeze.

(Also, back in the day, there was no setting of conventional, expanded, or extended memory in Mac OS, or worrying about IRQs. No Mac user ever had to deal with "I'm using a modem so I can't listen to audio" which was typical on PCs. Just sayin'...)
Flying this flag in support of freedom 🇺🇦

Recommended keyboard layout: English (intl., with AltGR dead keys)

Podcasts: Linux Unplugged, Destination Linux

Also check out Thor Hartmannsson's Linux Tips YouTube Channel
rambo919
Level 5
Level 5
Posts: 675
Joined: Wed May 22, 2013 3:11 pm

Re: Naming files in GNU/Linux

Post by rambo919 »

Depends on what you need to name. Some apps support spaces others get finicky. A common problem for me is trailing spaces so those always die just in case.... also being able to even have a filename with trailing spaces in itself is sloppy and only leads to confusion because you cannot actually SEE that last part of the filename unless you also see the extension and even then if you happen to be too hasty....

Sometimes using underscores instead of spaces is useful for separating specific folders visually, easier to keep track of than capitalization (WordWordwordWord). For media storage capitalization with spaces.
User avatar
AndyMH
Level 21
Level 21
Posts: 13566
Joined: Fri Mar 04, 2016 5:23 pm
Location: Wiltshire

Re: Naming files in GNU/Linux

Post by AndyMH »

I always datestamp my files so it might be 20180802-myfile.txt. Sometimes I use extensions, sometimes not. Usually all lower case, that's me being lazy and not having to hit the shift key as a touch typist.
Thinkcentre M720Q - LM21.3 cinnamon, 4 x T430 - LM21.3 cinnamon, Homebrew desktop i5-8400+GTX1080 Cinnamon 19.0
User avatar
lsemmens
Level 11
Level 11
Posts: 3936
Joined: Wed Sep 10, 2014 9:07 pm
Location: Rural South Australia

Re: Naming files in GNU/Linux

Post by lsemmens »

I use CamelCase or Underscore when I am looking for maximum "compatibibility" Otherwise I can be rather sloppy with file names. The only thing I do insist on is a "proper" extension. At least I can then tell at a glance what type of file it is likely to be without having open it.
Fully mint Household
Out of my mind - please leave a message
lmuserx4849

Re: Naming files in GNU/Linux

Post by lmuserx4849 »

You might enjoy this article by David Wheeler:

Fixing Unix/Linux/POSIX Filenames:
Control Characters (such as Newline), Leading Dashes, and Other Problems


I usually use dash for files and camel case for directories.

I like the underscore, but as you mentioned it requires a shift, plus sometimes, depending on app, it is difficult to tell if it is an underscore or space.
User avatar
Portreve
Level 13
Level 13
Posts: 4882
Joined: Mon Apr 18, 2011 12:03 am
Location: Within 20,004 km of YOU!
Contact:

Re: Naming files in GNU/Linux

Post by Portreve »

lsemmens wrote: Thu Aug 02, 2018 11:53 pm I use CamelCase or Underscore when I am looking for maximum "compatibibility" Otherwise I can be rather sloppy with file names. The only thing I do insist on is a "proper" extension. At least I can then tell at a glance what type of file it is likely to be without having open it.
Just sitting here thinking about if you had to use Mac OS (just for giggles) and realizing file extensions would mean nothing to the operating system.
Flying this flag in support of freedom 🇺🇦

Recommended keyboard layout: English (intl., with AltGR dead keys)

Podcasts: Linux Unplugged, Destination Linux

Also check out Thor Hartmannsson's Linux Tips YouTube Channel
User avatar
AZgl1800
Level 20
Level 20
Posts: 11145
Joined: Thu Dec 31, 2015 3:20 am
Location: Oklahoma where the wind comes Sweeping down the Plains
Contact:

Re: Naming files in GNU/Linux

Post by AZgl1800 »

I always cap the first letter, and use spaces if that suits me, when for images, it always does.

if the need for _ is there, I use that, if the need for - is there, I use that.

otherwise, I use spaces and let it be Readable.
LM21.3 Cinnamon ASUS FX705GM | Donate to Mint https://www.patreon.com/linux_mint
Image
User avatar
lsemmens
Level 11
Level 11
Posts: 3936
Joined: Wed Sep 10, 2014 9:07 pm
Location: Rural South Australia

Re: Naming files in GNU/Linux

Post by lsemmens »

Portreve wrote: Mon Aug 06, 2018 3:02 pm
lsemmens wrote: Thu Aug 02, 2018 11:53 pm I use CamelCase or Underscore when I am looking for maximum "compatibibility" Otherwise I can be rather sloppy with file names. The only thing I do insist on is a "proper" extension. At least I can then tell at a glance what type of file it is likely to be without having open it.
Just sitting here thinking about if you had to use Mac OS (just for giggles) and realizing file extensions would mean nothing to the operating system.
Actually, Portreve, you'll get a laugh out of this. When I was working in the industry I was with an IBM dealership. I had a MAC LCII on my desk. We were owned by an Apple Centre! Their inventory management software had yet to be ported to the PC. I know that extensions are typically unimportant, but they are useful. It's a throwback to my old DOS 8.3 days, I know.
Fully mint Household
Out of my mind - please leave a message
User avatar
Portreve
Level 13
Level 13
Posts: 4882
Joined: Mon Apr 18, 2011 12:03 am
Location: Within 20,004 km of YOU!
Contact:

Re: Naming files in GNU/Linux

Post by Portreve »

Ah ha! So then, here's a trivia question for you:

In Mac OS, how were files classified and associated with software? For bonus points, what program could you use to change those values yourself?
Flying this flag in support of freedom 🇺🇦

Recommended keyboard layout: English (intl., with AltGR dead keys)

Podcasts: Linux Unplugged, Destination Linux

Also check out Thor Hartmannsson's Linux Tips YouTube Channel
User avatar
lsemmens
Level 11
Level 11
Posts: 3936
Joined: Wed Sep 10, 2014 9:07 pm
Location: Rural South Australia

Re: Naming files in GNU/Linux

Post by lsemmens »

TBH I don't know. I just used the machine. I MUCH preferred the PC so I spent my time under the hood of them.
Fully mint Household
Out of my mind - please leave a message
lmuserx4849

Re: Naming files in GNU/Linux

Post by lmuserx4849 »

Portreve wrote: Tue Aug 07, 2018 1:12 pm ...
In Mac OS, how were files classified and associated with software? For bonus points, what program could you use to change those values yourself?
Regarding "Files classified and associated with software", Linux and Mac use mimetypes, which consists of multiple tests, from multiple locations.

"To change those values yourself", most Linux desktops have a GUI, either in the general system settings or in the file manager settings (default applications, file associations) to manage them. In the file manager, you can right-click a file and select Open With > Other and select an application. There usually is some sort of checkbox to make it the default.

If you view or create a .desktop file, it may contain a Mimetype= keyword. You can view the actual file or right-click and select Properties or Settings and see the same info.

Many Linux desktops these days follow the freedesktop specifications on a variety of desktop topics. Anytime you see anything about XDG it's freedesktop.org. They have one on mimetypes: https://www.freedesktop.org/wiki/Specif ... info-spec/
There's a brief and clear description at gnome: https://help.gnome.org/admin/system-adm ... types.html.
Here it is explained at debian: https://wiki.debian.org/MIME

To see all xdg environment variables, XDG_DATA_DIRS:
declare -p ${!XDG@}

If you do the command locate mimeinfo and view one of the cache files in a location like $HOME/.local/share/applications or /usr/share/applications you'll see mimetypes and desktop file names. Your locations may vary (see the above command).

There are a couple of commands that show you the mimetype of a file and the default application. File associations did exist before freedesktop standards. The man page for file and magic(i.e., first bytes of the file are examined) explains how it works.

===> file -i picture.jpg
picture.jpg: image/jpeg; charset=binary

===> xdg-mime query filetype picture.jpg
image/jpeg

===> xdg-mime query default image/jpeg
gwenview.desktop
User avatar
Portreve
Level 13
Level 13
Posts: 4882
Joined: Mon Apr 18, 2011 12:03 am
Location: Within 20,004 km of YOU!
Contact:

Re: Naming files in GNU/Linux

Post by Portreve »

lmuserx4849 wrote: Wed Aug 08, 2018 1:16 pm
Portreve wrote: Tue Aug 07, 2018 1:12 pm ...
In Mac OS, how were files classified and associated with software? For bonus points, what program could you use to change those values yourself?
Regarding "Files classified and associated with software", Linux and Mac use mimetypes, which consists of multiple tests, from multiple locations.
Nope.
"To change those values yourself", most Linux desktops have a GUI, either in the general system settings or in the file manager settings (default applications, file associations) to manage them. In the file manager, you can right-click a file and select Open With > Other and select an application. There usually is some sort of checkbox to make it the default.

If you view or create a .desktop file, it may contain a Mimetype= keyword. You can view the actual file or right-click and select Properties or Settings and see the same info.
I specified Mac OS. :wink:
Flying this flag in support of freedom 🇺🇦

Recommended keyboard layout: English (intl., with AltGR dead keys)

Podcasts: Linux Unplugged, Destination Linux

Also check out Thor Hartmannsson's Linux Tips YouTube Channel
User avatar
Portreve
Level 13
Level 13
Posts: 4882
Joined: Mon Apr 18, 2011 12:03 am
Location: Within 20,004 km of YOU!
Contact:

Re: Naming files in GNU/Linux

Post by Portreve »

So, to be fair, Mac OS to me means what many would call "Classic Mac OS", i.e. Mac OS 1.x -> 9.2.x.

Classic file structures in Classic Mac OS were that every file had two parts to it: a data fork and a resource fork. For your average run of the mill file, there really only was data, but there was always a provision made for resources. The resource fork carried two four-character codes: type, and creator. For example, a font file was type FFIL and creator MOVR.

If you had a couple different graphics programs on your computer, it would have been entirely possible that, in your collection of for example JPEGs, some would be assigned to Program X, and some to Program Y. The file type world be JPEG, and then the creator would be whatever was established for each respective program.

Any program capable of handling JPEGs could presumably open whatever images you had, but simply using the Finder to open the file would result in opening that file with whichever program it was assigned to.

ResEdit was a popular utility produced by Apple to edit files and programs, though most files, being only data, didn't have anything for ResEdit to work with. Except, as you might have already guessed, type and creator codes.
Flying this flag in support of freedom 🇺🇦

Recommended keyboard layout: English (intl., with AltGR dead keys)

Podcasts: Linux Unplugged, Destination Linux

Also check out Thor Hartmannsson's Linux Tips YouTube Channel
User avatar
Flemur
Level 20
Level 20
Posts: 10097
Joined: Mon Aug 20, 2012 9:41 pm
Location: Potemkin Village

Re: Naming files in GNU/Linux

Post by Flemur »

No spaces, delimiters or special characters.

To distinguish my own scripts (commands) from system commands, I use caps to start (most of, cuz sometimes forget) my script names, e.g "Find", and underscores to separate words; "net_stat", linux usually uses minus, e.g. "mint-drivers".
Please edit your original post title to include [SOLVED] if/when it is solved!
Your data and OS are backed up....right?
sgtor
Level 4
Level 4
Posts: 332
Joined: Sat May 13, 2017 9:39 pm

Re: Naming files in GNU/Linux

Post by sgtor »

I tend to use file-name more than file_name but do use both. I don't really worry too much about it.

All the oldtimer Linux users will know this already and maybe everyone else does too but Unix/Linux has always been a superior OS when it comes to file naming too. DOS used to have a an 8 letter filename restriction and 3 letter extension on filenames. That also applied to Windows 3.1. I can't remember what version that changed.

So back when DOS would have you name moms_app.txt you could name it in Linux as Moms_Apple_Pie_Recipe. Not so ambiguous in Linux.
Locked

Return to “Chat about Linux”