File Naming Convention

I am a noob in the ‘Nix arena.

I use a standardized naming convention.
YYYY.MM.DD Long File Name.pdf

In the Windows world this sorts properly in the default file manager or browser views. These are hosted on a ‘nix platform accessed via HTTP by Windows and Phone users.

Question for the ‘nix smart guys here: do you seen any conflict or usability issue with this naming convention?
 
I agree with gotnull on the merits of avoiding whitespace in filenames.

Other than doing that, I frequently use a very similar naming scheme (like "YYYY-MM-DD-LongFileName.pdf". The only other thing I can add is if you do, or ever intend to, serve them to Windows via Samba, be careful about the length of the full absolute path name (e.g. \\ShareName\Blah\Bling\Something.pdf). I occasionally run into a problem when they get too long, and "too long" is (at least to me) surprisingly short. I forget the details, but it's something like depending on how you configure Samba, you have two choices:
  1. It gets served in 8.3 format.
  2. It doesn't get served at all. Won't even show up in Windows Explorer, for example.
I am not a Samba expert or anything, so I wouldn't be surprised (and, hint hint, would be happy) to learn that there's a better solution. But as far as I've been able to tell, you can pick #1 or #2. No other choices.
 
We own the provider, so I am teaching out to inquire about the platform and file system.

It serves a few thousand users via http browser. I don’t care if the internal file system substitutes 0x20 for blank spaces as long as it displays correctly to the user.

I’m just curious if my naming convention is introducing a risk of the file system.
 
Except the max length of a filename (1023 chars for ZFS, I guess, but I'm not sure, since today's filesystems allow way longer filenames than what I see is practical) and which characters are not allowed to be used in a filename - I don't find the convention quickly. Almost all characters are allowed but a few exceptions, like e.g. NULL - it's not the point if the filesystem gets harmed, nor the file could get lost.
The point is that UTF-8 and some certain characters can cause troubles in other ways.

Example: ? is a valid character to be used in a filename. Since it's also a wildcard you can quickly see it's no good idea to have such in a filename.
Also the need to escape special characters like writing '\ ' instead of ' ', and paranthesis and others can cause trouble.

So, it's no actual rule but many people including myself don't use spaces and other chars in filenames, but replace them e.g. with _ or -
When I name files myself I only use a-z A-Z 1-0 _ - and .
I find that's fully sufficient to name files so they can be identified unequivocally. Filenames are not to be confused with the content of a file, like the headline of a paper. As long as you don't use some ancient FAT limited to 8.3 chars for a filename, there is enough space to say in normal characters what a file is.

It's also neither mandatory nor needed but very common to let all filenames end with .xyz to see directly, what kind of file it is: .txt textfile, .sh shellscript, .c - you get the picture.

I also prefer lower case letters on my production files. It's simply practical reasons. Since I do most of my work and 100% of all filehandling in the shell it's less effort to avoid pressing the shift key all the time.

Within my /home/ and all its subdirectories all directories start with a unique letter. There is one directory /home/files/programs and one /home/files/Playlists but no other dir starting with P or p in /home/files/. Lower case letters for the more frequently used ones. I find this pretty handy, since I only need to press one button and let shell's autocompletion do the rest.

Prefix a date I also do, but only on documents. Documents in the meaning of documents, not this fancy MS Windows meaning. Files that are not going to be changed anymore but for which I need to have a timestamp safe from the filesystem's one, when a chronological order is more important than alphabetical, in other words: letters, invoices, official stuff. Then I use YYYYMMDD-, this way they are sorted chronologically by filename. Some could say, 'YYYY is optimistic. YY is enough.' Sure, but I'm not 40 anymore. I still have stuff from the 1990s.
For all other files the filesystem's file's timestamp is enough for me to know. Naming all and each file YYMMDD- I personally do not find practical in daily use. But that's 100% personal taste.
Note (from man ls):
Code:
 If the modification time of the file is more than 6 months in the past or
     future, and the -D or -T are not specified, then the year of the last modi-
     fication is displayed in place of the hour and minute fields.
This can cause a bit confusion for newbies, particulary when New Year fells in those 6 months. :cool:

Anyway my recommendation is to always give files a considered name.
Naming a file hw.c instead of hello_world.c will cost you way more time than you saved by not thinking of a better filename, when in a couple of months you stumble over it and try to remember, finding out what this thing is.
Some thing named test I also do, but when I forget to remove that garbage right after the test and then stumble over it a few weeks later, 'what the ...?' - those can really trash up your place.

Using a system a while and your /home/ will fill up with a lot many files. So considering a good system how to name and sort files, above all make use of and look for a considered system of subdirectories, in the first place is way - WAY - less effort, than face the situation to clean up a trashed up place afterwards.
Particulary nobody fancies cleaning up, keep more order in the first place is always less effort than cleaning up afterwards. Keep order = no fun. Cleaning up = even less fun. 🥸

Tip: Always directly remove files not needed anymore. When deinstalling a package you installed just to take a look at it, always directly afterwards also remove its config files in your /home/ again.

Tip: Check out some ls(1) options. You also can get a lot more overview of a directory's content than by just using considered filenames when instead plain ls you do for example ls -gh, ls -lSh, or particulary I love the -t option: ls -gat. I just need to look at the top of the list to see quickly only the files changed recently, not scanning the whole directory's full list. It's my very personal taste I prefer single column lists. That's why my examples all contain -l or -g.

Tip: In your shell's config file (~/.shrc for bourne shell, ~/.cshrc for [t]csh) are by default aliases defined for quick ls command usage. Feel free to change those to your personal taste, or add own ones.

Anyway, you define and decide what's practical for you.

When I get a file from somewhere else, particulary Windows, I replace all characters not matching my convention: ()[]{}:#?!'`´"%& etc. also use Ae instead of Ä, oe instead of ö, etc (when your not dealing with English only you have to deal a lot with "exotic" characters.)
Since this is one of the more freqent tasks, especially when moving a lot of files from Windows to FreeBSD, or to be more correct from NTFS to ZFS or UFS, I have written me a tiny, simple shellscript that automatically replaces/removes unwanted chars from filenames. Just run it in a directory with files with weird names and voilá, all filenames are nice and don't contain no ugly garbage no more. :cool:
Hannes Kretzer - Devotion & Decay (official video) [RLKHiW_7XZM].mp4 🤮
becomes
Hannes_Kretzer-Devotion_and_Decay-official_video.mp4 🥳

(Hannes Kretzer is the musician who made the soundtrack of Avorion. Alas after several upgrades the game eventually sucked, but the music is very meditative. I find it very nice for background while working. 😌)
 
Oh, the comment Maturin made about a having personal preference for lowercase characters reminds me of a possible issue with your convention: In FreeBSD, filenames are case-sensitive; in Windows, they are not. So there could be problems in situations like a Windows user using some editor that by default saves text files as *.TXT. If everything's pure Windows, they can open up blah.txt, edit it, and save it, and now the display name of the file is blah.TXT instead of blah.txt, but it's just the way that the name is displayed.

But if that Windows user uses that same editor to open up a file blah.txt on a non-Windows server, makes some change to it, and saves it, there are now two different files, blah.txt and blah.TXT, with different content than each other. That sort of thing could cause all sorts of nasty surprises in various situations.
 
Oh, and one more little thing that's taken me by surprise in the past: Sorting the filenames won't necessarily be the same on the two platforms. First of all, due to the case-sensitivity/insensitivity thing. But another thing too:

There are probably ways to reconfigure this behavior, and I'm probably forgetting the details of what gets sorted where how, but at least by default in my experience, it's like one platform sorts numbers as strings of individual digits, and the other sorts them as... uh... numbers. Like, on one platform you might see:

1.txt
2.txt
3.txt
(...)
9.txt
10.txt
11.txt

But on the other:

1.txt
10.txt
11.txt
2.txt
3.txt
(...)
9.txt

Obviously your YYYY.MM.DD prefix won't be succeptible to that, but it still could be a problem for filenames starting with the same date (e.g. "2026.09.18 Awesome File 2" vs. "2026.09.18 Awesome File 10").
 
... uh... numbers [...]

1.txt
10.txt
11.txt
2.txt
3.txt
(...)
9.txt
you can use ls -v
Code:
-v      Sort following a natural ordering, using strverscmp(3)  instead  of
         strcoll(3)  as  the comparison function.  E.g., files lexicographi-
         cally ordered "bloem1", "bloem10", and "bloem9"  would  instead  be
         ordered "bloem1", "bloem9", and "bloem10", as one would perhaps ex-
         pect.

But having numbers in filenames with preceding zeros, so 01-... to 09-... is the safest way to get the correct order in any case(*), also when importing the files in some app, like for a playlist.
That's why my file renaming routines e.g. in my CD_to_ogg script test if the number of files is >=10, and if so prefix a 0 for each title 1 to 9.


(*) not quite true. Some players don't take the filenames to sort but the mp3-tag. So it's a good idea to see those also contain correct entries. Or, quick&dirty, what I do: Just kill the tags. Then the player must use the filenames for sorting. 😁
 
Back
Top