Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm a beginner in Linux and want to learn to do things properly in this environment. Since the beginning I've noticed that a lot of people involved in Linux (like tutorials and guides) tend to name files omitting spaces and replacing them with the character "_" and I would like to know if there's a reason to do so. Also I want to know what other characters should be avoided when naming files. What about capital letters? I've seen a preference for lowercase letters.

As a last query, what would be the best way to name my songs in Linux. For example, I got a lot of files in the format: track. artist name - song name.mp3, like 01. Crystal Castles - Untrust Us.mp3. Should I change the format to something like track._artist_name_-_song_name.mp3 as in 01._Crystal_Castles_-_Untrust_Us.mp3; it looks a little overloaded for my newbie eyes. I would like to know your opinion on this matter. Thanks.

share|improve this question

4 Answers 4

Technically speaking, the only characters that are explicitly disallowed are / and \0 (the NUL byte) since these have special meanings.

However, there are some conventions that people tend to use for convenience's sake. For example, you noticed that people prefer not to use spaces and instead use _. This is because a spaces are word delimiters on *nix command-lines. As a result, if you use a space in a file-name, you must either quote the file name or escape each space (with a \) for the name to be recognized correctly as a single entity. Though you can use spaces in filenames, the extra effort deters many people from doing so.

Additionally, capital letters are avoided (by some), probably because it takes more effort to type those file names—afterall, pressing Shift is pretty hard!

Your question of "What is the best convention?" is difficult to answer; as with many issues, under *nix, the best solution is what works best for you.

Personally, I keep my audio files in a file hierarchy (~/Music/<Artist>/<Album>/) and each track name like so: ## - <Track Name>.ext.

share|improve this answer
    
Nice answer. I would like to add that for myself, the only exceptions in which I allow for spaces and/or capitalization, is with filenames of songs and video's. –  twan163 Aug 26 at 7:11
  • Upper and Lower Case

    Upper case, lower case, and mixed case are all fine for file names. If some users have a preference for lower case names, it is just because it is faster to type lower case.

  • Spaces

    Spaces are fine in file names with one caveat: such file names require more care when writing shell scripts. A basic tutorial on this subject is here.

  • Colons

    Colons (:) should probably be avoided. This is because, when moving files from one computer to another, it is a common convention, with utilities such as scp, to combine the computer name and file name in the form machinename:filename. Thus, if your file name has a colon, it may lead to confusion.

  • Slashes

    You can't use / as this character is used to separated directory names, just like \ is used on Microsoft systems. If you want to freely transfer files back and forth, you should probably avoid both.

  • Portability

    Many mp3 players use old-style Microsoft VFAT filesystems. On these file systems,:, \, *, and ? are all forbidden. If you will ever transfer your files to such a filesystem, it is best to avoid these characters as well.

share|improve this answer
  • Upper and lower case - note

    *Common filesystems on nix like OS'es allows ThisFile and thisfile to exist in the same folder. This is not possible e.g. on a vfat or ntfs filesystem (and quite a number of other older filsystems).

share|improve this answer

The most important thing is to match the patterns that exist and stick to it. Get to an answer without waste time mulling it over. I understand the irony that I am answering this question ;

Apple follows /Library/Extensions/SomeExtension.file so I set up my working directory like that too: Projects/Client/Project/thing.extension

Incidentally, the frontend dev work I do also follows this logic with JS namingLikeThis.js while CSS something-like-this.css - mixing conventions in my project but not to technologies at large. I asked Bootstrap's creators @fat and @mdo awhile back and its their approach a well. I adopted it and never dedicated serious thought to it again.

It is a bit wonky but solves the conundrum with a defensible answer so I can get to work with less thinking or debate.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.