Unix file naming convention [closed]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
55
down vote

favorite
20












I was wondering what is the naming convention for files in Unix? I am not sure about this, but I think there is perhaps a universal naming convention that one should follow?



For example, I want to name a file say: backup with part 2 and random



Should I do it like this:



backup_part2_random



OR



backup-part2-random



OR



backup.part2.random



I hope the question is clear. Basically, I want to choose a format that conforms to the Unix philosophy.










share|improve this question















closed as primarily opinion-based by Jeff Schaller, Isaac, slm♦ Aug 23 at 22:12


Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.










  • 3




    As a general comment re the "conventions" ... I've just read all the answers so far, and it struck me how odd it is that there is almost an obscession with using only one case in a system where (I think) one of its strengths is the ability to meaningfully use both cases... Was the original design (case-sensitive) an over design)... just musing
    – Peter.O
    Feb 14 '11 at 12:34










  • my opinion: there is no convention. file names are just strings. pick your favourite style.
    – glenn jackman
    Feb 14 '11 at 13:24






  • 1




    It's because nobody wants to remember the capitalisation of commands, so they all use the same.
    – LtWorf
    Sep 2 '16 at 12:41














up vote
55
down vote

favorite
20












I was wondering what is the naming convention for files in Unix? I am not sure about this, but I think there is perhaps a universal naming convention that one should follow?



For example, I want to name a file say: backup with part 2 and random



Should I do it like this:



backup_part2_random



OR



backup-part2-random



OR



backup.part2.random



I hope the question is clear. Basically, I want to choose a format that conforms to the Unix philosophy.










share|improve this question















closed as primarily opinion-based by Jeff Schaller, Isaac, slm♦ Aug 23 at 22:12


Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.










  • 3




    As a general comment re the "conventions" ... I've just read all the answers so far, and it struck me how odd it is that there is almost an obscession with using only one case in a system where (I think) one of its strengths is the ability to meaningfully use both cases... Was the original design (case-sensitive) an over design)... just musing
    – Peter.O
    Feb 14 '11 at 12:34










  • my opinion: there is no convention. file names are just strings. pick your favourite style.
    – glenn jackman
    Feb 14 '11 at 13:24






  • 1




    It's because nobody wants to remember the capitalisation of commands, so they all use the same.
    – LtWorf
    Sep 2 '16 at 12:41












up vote
55
down vote

favorite
20









up vote
55
down vote

favorite
20






20





I was wondering what is the naming convention for files in Unix? I am not sure about this, but I think there is perhaps a universal naming convention that one should follow?



For example, I want to name a file say: backup with part 2 and random



Should I do it like this:



backup_part2_random



OR



backup-part2-random



OR



backup.part2.random



I hope the question is clear. Basically, I want to choose a format that conforms to the Unix philosophy.










share|improve this question















I was wondering what is the naming convention for files in Unix? I am not sure about this, but I think there is perhaps a universal naming convention that one should follow?



For example, I want to name a file say: backup with part 2 and random



Should I do it like this:



backup_part2_random



OR



backup-part2-random



OR



backup.part2.random



I hope the question is clear. Basically, I want to choose a format that conforms to the Unix philosophy.







filenames






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Aug 23 at 22:11









slm♦

238k65494664




238k65494664










asked Feb 13 '11 at 12:32







user4740











closed as primarily opinion-based by Jeff Schaller, Isaac, slm♦ Aug 23 at 22:12


Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.






closed as primarily opinion-based by Jeff Schaller, Isaac, slm♦ Aug 23 at 22:12


Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.









  • 3




    As a general comment re the "conventions" ... I've just read all the answers so far, and it struck me how odd it is that there is almost an obscession with using only one case in a system where (I think) one of its strengths is the ability to meaningfully use both cases... Was the original design (case-sensitive) an over design)... just musing
    – Peter.O
    Feb 14 '11 at 12:34










  • my opinion: there is no convention. file names are just strings. pick your favourite style.
    – glenn jackman
    Feb 14 '11 at 13:24






  • 1




    It's because nobody wants to remember the capitalisation of commands, so they all use the same.
    – LtWorf
    Sep 2 '16 at 12:41












  • 3




    As a general comment re the "conventions" ... I've just read all the answers so far, and it struck me how odd it is that there is almost an obscession with using only one case in a system where (I think) one of its strengths is the ability to meaningfully use both cases... Was the original design (case-sensitive) an over design)... just musing
    – Peter.O
    Feb 14 '11 at 12:34










  • my opinion: there is no convention. file names are just strings. pick your favourite style.
    – glenn jackman
    Feb 14 '11 at 13:24






  • 1




    It's because nobody wants to remember the capitalisation of commands, so they all use the same.
    – LtWorf
    Sep 2 '16 at 12:41







3




3




As a general comment re the "conventions" ... I've just read all the answers so far, and it struck me how odd it is that there is almost an obscession with using only one case in a system where (I think) one of its strengths is the ability to meaningfully use both cases... Was the original design (case-sensitive) an over design)... just musing
– Peter.O
Feb 14 '11 at 12:34




As a general comment re the "conventions" ... I've just read all the answers so far, and it struck me how odd it is that there is almost an obscession with using only one case in a system where (I think) one of its strengths is the ability to meaningfully use both cases... Was the original design (case-sensitive) an over design)... just musing
– Peter.O
Feb 14 '11 at 12:34












my opinion: there is no convention. file names are just strings. pick your favourite style.
– glenn jackman
Feb 14 '11 at 13:24




my opinion: there is no convention. file names are just strings. pick your favourite style.
– glenn jackman
Feb 14 '11 at 13:24




1




1




It's because nobody wants to remember the capitalisation of commands, so they all use the same.
– LtWorf
Sep 2 '16 at 12:41




It's because nobody wants to remember the capitalisation of commands, so they all use the same.
– LtWorf
Sep 2 '16 at 12:41










14 Answers
14






active

oldest

votes

















up vote
51
down vote













. is used to separate a filetype extension, e.g. foo.txt.



- or _ is used to separate logical words, e.g. my-big-file.txt or sometimes my_big_file.txt. - is better because you don't have to press the Shift key (at least with a standard US English PC keyboard), others prefer _ because it looks more like a space.



So if I understand your example, backup-part2-random or backup_part2_random would be closest to the normal Unix convention.




CamelCase is normally not used on Linux/Unix systems. Have a look at file names in /bin and /usr/bin. CamelCase is the exception rather than the rule on Unix and Linux systems.



(NetworkManager is the only example I can think of that uses CamelCase, and it was written by a Mac developer. Many have complained about this choice of name. On Ubuntu, they have actually renamed the script to network-manager.)



For example, on /usr/bin on my system:



$ ls -d [A-Z]* | wc -w # files starting with a capital
6
$ ls -d *_* | wc -w # files containing an underscore
178
$ ls -d *-* | wc -w # files containing a minus/dash
409


and even then, none of the files starting with a capital uses CamelCase:



$ ls -d [A-Z]*
GET HEAD POST X11 Xvnc Xvnc4





share|improve this answer






















  • The . char can also be used to rotate things, not only to specify an extension. For example my.log my.log.1 my.log.2.gz.
    – Depado
    Nov 19 '15 at 17:13










  • So the hyphen/minus/dash is more common that the underscore.
    – Hugo
    Mar 4 '16 at 9:26










  • @Hugo Yes. The above shows minus (409) vs underscore (178).
    – Mikel
    Mar 4 '16 at 17:31










  • Thanks. Do you have any references for these conventions?
    – Proletariat
    Mar 7 '16 at 16:21






  • 2




    +1 for the references. (@Proletariat, the ls output from /usr/bin is a reference. This is a question about conventions.)
    – Wildcard
    Jan 24 '17 at 5:14

















up vote
35
down vote













Far more important that a particular convention is being consistent. Pick a style, and stick with it.






share|improve this answer





























    up vote
    15
    down vote













    My take on Unix/Linux filename conventions:



    • Unix/Linux filesystems don't inherently support the notion of an extension. The concept of a file extension completely exists as something supported by utilities such as cp, ls, or the shell you are using. I believe it is this way on NTFS as well, but I could be wrong.


    • Executables, including shell scripts, usually never have any type of extension. Scripts will have a hashbang line (i.e. #!/bin/bash) that identifies what program should interpret it.


    • Any executable that is two letters long is super important. So don't name your executables two-letter filenames. Any file in /etc ending in tab is also super important, such as fstab, mtab, inittab.

    • Sometimes .d is appended to directory names, particularly in /etc, but this isn't widespread (UPDATE: https://serverfault.com/questions/240181/what-does-the-suffix-d-mean-in-linux)


    • rc is widely used for configuration scripts or files, either prepending (e.g., rc.local) or suffixing (.vimrc)

    • The Unix/Linux community has never had a three-character limit on extensions and frowns upon shortening well know extensions to fit. For example, don't use .htm at the end of HTML files on Unix/Linux, use .html.

    • In a set of files, a filename is sometimes capitalized, or in all caps, so it appears at the head of a directory listing. The classic example is Makefile in source packages. Only do this for stuff like README.


    • ~ is used to identify a backup file or a directory, as in important_stuff~, or /etc~. Many shells will expand a lone ~ to $HOME.

    • Library files almost always begin with lib. Exception is zlib and probably a few others.

    • Scripts that are called by inetd sometimes are tagged with a leading in., such as in.tftpd.

    • The ending z in vmlinuz means zipped, but I've never seen any other file named this way.





    share|improve this answer


















    • 2




      I often see shell scripts with a .sh "extension" on them. I personally find it somewhat annoying, but I have to admit that I may be ignorant of some good reason for using the .sh.
      – Dan Moulding
      Feb 14 '11 at 19:07






    • 1




      A thing comes to mind that it's useful to emphasize the fact that it is a text-based script and not a binary.
      – LawrenceC
      Feb 14 '11 at 20:00






    • 1




      @DanMoulding, personally, I use .sh on scripts which are (1) not intended to be run interactively, but only from other scripts/programs, or (2) are designed for sourcing rather than execution. For the former they must be executable; for the latter I leave the executable bit off and use the shebang line only for documentation of what shell the functions are written for.
      – Wildcard
      Jan 24 '17 at 5:19







    • 2




      @Wildcard I have since (6 years ago) gotten into this same habit. The extension actually makes a lot of sense for sourcing script bits. For instance, from an executable script written for zsh (i.e. #!/bin/zsh at the top) you know you can safely source another file with the .zsh extension and be sure that it contains legal zsh code. If your executable script is strictly Bourne Shell compliant (i.e. #!/bin/sh at the top), then you'd know that sourcing that .zsh file is going to be problematic.
      – Dan Moulding
      Jan 25 '17 at 21:00







    • 3




      I find using ".sh", ".py", ".pl", etc., is convenient, and some text editors (e.g., Geany) use those to make a first guess at the proper syntax highlighting scheme.
      – bgvaughan
      Jun 29 '17 at 15:18

















    up vote
    8
    down vote













    In unix filename is just a string, unlike DOS, where filename was composed from name and extension. So any of given filenames is completely acceptable.



    But many programs still use file suffixes beginning with dot to distinguish different file types, i.e. Apache Web Server uses suffixes to set correct MIME type in answer headers.






    share|improve this answer
















    • 5




      While gelraen is 100% correct: Unix/Linux as such does not care about file extensions, modern flavours of Linux do care in so far as some shell extensions provide special identification (colours or otherwise) of certain file types and file managers provide automatic associations with programs. But just as important is for the human user to know which file is what type. To that end it is convenient to stick to a standard scheme not just consistent for yourself but with others. In this respect things should not be overly different than MS Windows (or MIME).
      – asoundmove
      Feb 13 '11 at 21:24










    • That said sometimes several different extension styles can match the same purpose. Thus .tar.gz is equivalent to .tgz, .tar.bz2 = .tbz, .ps.gz is often shortened as .ps (confusingly) and I'm sure there are many more.
      – asoundmove
      Feb 13 '11 at 21:28










    • @asoundmove .ps.gz means it's a compressed .ps file. Just like .tar.gz means compressed .tar file.
      – jonescb
      Feb 14 '11 at 15:42







    • 1




      @jonescb, yes of course. My point about it being confusing is that when I see .ps I expect a non compressed file (which I should be able to cat or less), but often .ps files are compressed and should in fact be .ps.gz for clarity (as they require zcat or zless for source code viewing). Some people decided to just suffix compressed PostScript files with .ps anyway because some common ps viewers actually don't mind whether they are compressed or not.
      – asoundmove
      Feb 14 '11 at 23:03


















    up vote
    6
    down vote













    Characters you should not use in filenames:




    | ; , ! @ # $ ( ) < > / " ' ` ~
    [ ] = + & ^




    Character delimiters you should use to make names easier to read:




    _ - . :




    (In some cases ":" has special meaning though)






    share|improve this answer
















    • 5




      Of course, you can't even use "/" in filenames. Everything else is possible. And if you want to make it hard to access, even useful ;-)
      – Jürgen A. Erhard
      Feb 14 '11 at 12:48










    • The list is actually a lot longer, including control and non-ASCII characters. Yes, you can have a backspace as part of a *nix file name.
      – l0b0
      Jun 20 '11 at 12:13










    • More to the point, most *nix systems only disallow two specific characters in file names: the / path separator, and the (ASCII zero) string terminator.
      – Michael Kjörling
      Jun 26 '13 at 21:45

















    up vote
    5
    down vote













    To add to what others have said, I'd just say that while accented letters and many special characters are legal in filenames they can cause issues in any of the following scenarios:



    • You share your filesystem with other computers, particularly with different operating systems;

    • You share files with others (and although email tends to be quite good with conversions, sometimes it just does not work);

    • You use shell scripts to automate some tasks (spaces are particularly problematic, though there are many ways to deal with them);

    • You use a file share from another computer.

    ...






    share|improve this answer





























      up vote
      4
      down vote













      Stick to alphanumeric filenames. Avoid spaces or replace spaces with underscores ( _ ). Limit punctuation in file names to periods (.), underscores ( _ ), and hyphens (-). Generally filenames are lowercase, but I use CamelCase when I have multiple words in the filename.



      Use extensions which indicate the type of file. Programs do not need extensions as the execute bit is used to indicate programs, and the shells know how to run programs of various types. It is common but not required to (.sh) for shell scripts, and (.pl) for perl scripts. The Windows executable extensions .bat, .com, .scr, and .exe indicate Windows executables on Unix.



      Pick a standard and stick to it. But it won't break things if you avoid it.



      Hidden (or dot) files have names starting with a period. These normally don't show up in directory listings. Use 'ls -a' to include the dot files in the list.






      share|improve this answer


















      • 3




        CamelCase is an anti pattern on Unix. The OP was asking about conventions.
        – Mikel
        Feb 13 '11 at 21:46






      • 2




        It's not "bad" versus "good". It's "this is how it's usually done". It's a convention the OP was asking for. The reason? It could be because Unix people don't like pressing Shift, it could be because old systems only had UPPERCASE, or for another reason. I'm not sure.
        – Mikel
        Feb 14 '11 at 3:03










      • @Mikel I also program Java where CamelCase is a convention. Sometimes patterns and conventions conflict.
        – BillThor
        Feb 14 '11 at 17:16











      • .scr is also a Windows executable extension.
        – LawrenceC
        Feb 25 '11 at 0:17






      • 1




        @ultrasawblade Thanks, shows how often I script Windows. I tried to skip the rarer executable extensions like cmd, pif, vb*, wsh, and the rest of them.
        – BillThor
        Feb 25 '11 at 19:37


















      up vote
      4
      down vote













      Two thoughts:




      1. In the Naming Variables, Functions, and Files section of the GNU Coding Standards you'll find:




        Please use underscores to separate words in a name, so that the Emacs word commands can be useful within them. Stick to lower case;




        While IMO saying "You should use _ because emacs" seems a bit dated, it is nevertheless in their 'standards' document.




      2. Let's suppose for a moment that we all agree that the linux kernel is the be-all-and-end-all* of linux projects, and that the conventions used there are what could be considered 'standard' convention.



        grep-ing source for the linux kernel you'll find the following:




        • 44.6% of the time only dash is used


        • 54.1% of the time only underscore


        • 1.2% of the time a file uses both.


      Interestingly, the source for git weighs in at 85% for dashes, 3.8% for underscores, and 11.1% for both.



      The choice is clear, debate over. ;)



      Personal opinion: I use dashes for aesthetic and shift key reasons. If you're working on a team, take a vote. But to reiterate what's been said, be consistent.



      * or "be_all and end_all" if you like






      share|improve this answer



























        up vote
        0
        down vote













        I agree with David Oneill that you should just go with something.



        But it is nice if the files is sortable in the same dir,
        so dont number 0..10 but number 00..10.



        When using dates in names, go with a standard date format like ISO8601.



        And dont be afraid to use multiple chars to separate logical parts in the name. If you use _ (that was 3 _), then you can simplify the regexps on filenames later on.



        So your example could then be something like this:



        backup_2011-06-19T114012___part002___random


        Easy to read and easy to parse with scripts.






        share|improve this answer



























          up vote
          0
          down vote













          Words in a filename can be either separated with _ or - according to Unix convention.



          If you use -, it's easier to type, saves you from pressing SHIFT. But since - takes so little space, it is a bit hard to read word separations compared to _. Using _ to separate words makes it look much cleaner since _ takes up more space.



          In shell scripting and other computer programming, _ are used for multi word variables, like MY_ENVIRONMENT_FILE. Making the filenames use _ as well keeps it consistent: MY_ENVIRONMENT_FILE=~/my_environment_file.



          In web development, - is preferred for file naming. One reason is probably because the underline in weblinks can hide the underscores and might make it difficult if you are typing the weblink by hand.



          In most editors and as well as web pages, this_long_word can be fully selected with a double click but not this-long-word.






          share|improve this answer




















          • Hmmm, why are you reading your filenames in a variable-width font? Open up your terminal and - and _ take up just exactly the same space! :)
            – Wildcard
            Jan 24 '17 at 5:27











          • Haha, you are right. I use the SourceCodePro+Powerline+Awesome Regular patched font. Even with monospace fonts, _ looks cleaner even though it takes the same space as -. I should have used the word "apparently". Regarding the _ and - when using monospace fonts, the difference can be best explained with this analogical picture: evsc.net/v8/wp/wp-content/uploads/2010/09/…
            – GMaster
            Jan 24 '17 at 5:46


















          up vote
          0
          down vote













          One convention is to use "_" to replace spaces as separators between words. Other characters could be used to replace spaces, but there are slightly stronger conventional uses for "-" and "." in pathnames, so "_" is usually preferred.



          Spaces are legal in pathnames, but are conventionally avoided, because they require quoting the pathname ("foo bar") or escaping the spaces (foo bar). A properly written shell script will quote variables that may include spaces, particularly pathnames, but failing to do so is a common oversight, and it's a lot of extra typing when doing a one-off command entered at the command line.



          Using "-" to separate clusters of numbers, as in timestamps or serial numbers, is a convention commonly used outside the context of filesystems. Using "." to separate "file extensions" that indicate the type of file is very common, and some important tools depend on it. For instance, the package management system on Red Hat Enterprise Linux and its derivatives, RPM, expects package files to end with ".rpm". The traditional tarball is a tar file (".tar") that has been gzipped (".gz"), and so ends in ".tar.gz".



          So putting these together, you often end up with filenames that look like, "home_backup_2017-07-01.tar.gz"






          share|improve this answer



























            up vote
            0
            down vote













            use - for naming files

            and _ for functions
            . for extensions



            cat << EOF > foo-bar.sh 
            foo_bar()
            echo baz

            EOF





            share|improve this answer





























              up vote
              -1
              down vote













              There is definitely a standard for Linux. If you look at the file names in any Linux system they are lower case with dashes: /usr/bin/ssh-keygen. This is specified in one of the Linux Standards Base documents that I cannot find right now. It is also specified by GNU which says to use underscores for variable names and dashes for file names.






              share|improve this answer



























                up vote
                -2
                down vote













                To add to what everyone else has said:



                1-Even though Linux doesn't care much about extensions, Windows does, so make sure any file you ever plan on giving anyone has the appropriate extension.



                2-Camel caps seems to be the easiest to use scripts with, no special characters to worry about escape sequences.






                share|improve this answer


















                • 4




                  -1. CamelCase is NOT used on Linux.
                  – Mikel
                  Feb 13 '11 at 21:50
















                14 Answers
                14






                active

                oldest

                votes








                14 Answers
                14






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes








                up vote
                51
                down vote













                . is used to separate a filetype extension, e.g. foo.txt.



                - or _ is used to separate logical words, e.g. my-big-file.txt or sometimes my_big_file.txt. - is better because you don't have to press the Shift key (at least with a standard US English PC keyboard), others prefer _ because it looks more like a space.



                So if I understand your example, backup-part2-random or backup_part2_random would be closest to the normal Unix convention.




                CamelCase is normally not used on Linux/Unix systems. Have a look at file names in /bin and /usr/bin. CamelCase is the exception rather than the rule on Unix and Linux systems.



                (NetworkManager is the only example I can think of that uses CamelCase, and it was written by a Mac developer. Many have complained about this choice of name. On Ubuntu, they have actually renamed the script to network-manager.)



                For example, on /usr/bin on my system:



                $ ls -d [A-Z]* | wc -w # files starting with a capital
                6
                $ ls -d *_* | wc -w # files containing an underscore
                178
                $ ls -d *-* | wc -w # files containing a minus/dash
                409


                and even then, none of the files starting with a capital uses CamelCase:



                $ ls -d [A-Z]*
                GET HEAD POST X11 Xvnc Xvnc4





                share|improve this answer






















                • The . char can also be used to rotate things, not only to specify an extension. For example my.log my.log.1 my.log.2.gz.
                  – Depado
                  Nov 19 '15 at 17:13










                • So the hyphen/minus/dash is more common that the underscore.
                  – Hugo
                  Mar 4 '16 at 9:26










                • @Hugo Yes. The above shows minus (409) vs underscore (178).
                  – Mikel
                  Mar 4 '16 at 17:31










                • Thanks. Do you have any references for these conventions?
                  – Proletariat
                  Mar 7 '16 at 16:21






                • 2




                  +1 for the references. (@Proletariat, the ls output from /usr/bin is a reference. This is a question about conventions.)
                  – Wildcard
                  Jan 24 '17 at 5:14














                up vote
                51
                down vote













                . is used to separate a filetype extension, e.g. foo.txt.



                - or _ is used to separate logical words, e.g. my-big-file.txt or sometimes my_big_file.txt. - is better because you don't have to press the Shift key (at least with a standard US English PC keyboard), others prefer _ because it looks more like a space.



                So if I understand your example, backup-part2-random or backup_part2_random would be closest to the normal Unix convention.




                CamelCase is normally not used on Linux/Unix systems. Have a look at file names in /bin and /usr/bin. CamelCase is the exception rather than the rule on Unix and Linux systems.



                (NetworkManager is the only example I can think of that uses CamelCase, and it was written by a Mac developer. Many have complained about this choice of name. On Ubuntu, they have actually renamed the script to network-manager.)



                For example, on /usr/bin on my system:



                $ ls -d [A-Z]* | wc -w # files starting with a capital
                6
                $ ls -d *_* | wc -w # files containing an underscore
                178
                $ ls -d *-* | wc -w # files containing a minus/dash
                409


                and even then, none of the files starting with a capital uses CamelCase:



                $ ls -d [A-Z]*
                GET HEAD POST X11 Xvnc Xvnc4





                share|improve this answer






















                • The . char can also be used to rotate things, not only to specify an extension. For example my.log my.log.1 my.log.2.gz.
                  – Depado
                  Nov 19 '15 at 17:13










                • So the hyphen/minus/dash is more common that the underscore.
                  – Hugo
                  Mar 4 '16 at 9:26










                • @Hugo Yes. The above shows minus (409) vs underscore (178).
                  – Mikel
                  Mar 4 '16 at 17:31










                • Thanks. Do you have any references for these conventions?
                  – Proletariat
                  Mar 7 '16 at 16:21






                • 2




                  +1 for the references. (@Proletariat, the ls output from /usr/bin is a reference. This is a question about conventions.)
                  – Wildcard
                  Jan 24 '17 at 5:14












                up vote
                51
                down vote










                up vote
                51
                down vote









                . is used to separate a filetype extension, e.g. foo.txt.



                - or _ is used to separate logical words, e.g. my-big-file.txt or sometimes my_big_file.txt. - is better because you don't have to press the Shift key (at least with a standard US English PC keyboard), others prefer _ because it looks more like a space.



                So if I understand your example, backup-part2-random or backup_part2_random would be closest to the normal Unix convention.




                CamelCase is normally not used on Linux/Unix systems. Have a look at file names in /bin and /usr/bin. CamelCase is the exception rather than the rule on Unix and Linux systems.



                (NetworkManager is the only example I can think of that uses CamelCase, and it was written by a Mac developer. Many have complained about this choice of name. On Ubuntu, they have actually renamed the script to network-manager.)



                For example, on /usr/bin on my system:



                $ ls -d [A-Z]* | wc -w # files starting with a capital
                6
                $ ls -d *_* | wc -w # files containing an underscore
                178
                $ ls -d *-* | wc -w # files containing a minus/dash
                409


                and even then, none of the files starting with a capital uses CamelCase:



                $ ls -d [A-Z]*
                GET HEAD POST X11 Xvnc Xvnc4





                share|improve this answer














                . is used to separate a filetype extension, e.g. foo.txt.



                - or _ is used to separate logical words, e.g. my-big-file.txt or sometimes my_big_file.txt. - is better because you don't have to press the Shift key (at least with a standard US English PC keyboard), others prefer _ because it looks more like a space.



                So if I understand your example, backup-part2-random or backup_part2_random would be closest to the normal Unix convention.




                CamelCase is normally not used on Linux/Unix systems. Have a look at file names in /bin and /usr/bin. CamelCase is the exception rather than the rule on Unix and Linux systems.



                (NetworkManager is the only example I can think of that uses CamelCase, and it was written by a Mac developer. Many have complained about this choice of name. On Ubuntu, they have actually renamed the script to network-manager.)



                For example, on /usr/bin on my system:



                $ ls -d [A-Z]* | wc -w # files starting with a capital
                6
                $ ls -d *_* | wc -w # files containing an underscore
                178
                $ ls -d *-* | wc -w # files containing a minus/dash
                409


                and even then, none of the files starting with a capital uses CamelCase:



                $ ls -d [A-Z]*
                GET HEAD POST X11 Xvnc Xvnc4






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Jun 29 '17 at 14:21









                Stéphane Chazelas

                285k53525864




                285k53525864










                answered Feb 13 '11 at 21:49









                Mikel

                37.9k996122




                37.9k996122











                • The . char can also be used to rotate things, not only to specify an extension. For example my.log my.log.1 my.log.2.gz.
                  – Depado
                  Nov 19 '15 at 17:13










                • So the hyphen/minus/dash is more common that the underscore.
                  – Hugo
                  Mar 4 '16 at 9:26










                • @Hugo Yes. The above shows minus (409) vs underscore (178).
                  – Mikel
                  Mar 4 '16 at 17:31










                • Thanks. Do you have any references for these conventions?
                  – Proletariat
                  Mar 7 '16 at 16:21






                • 2




                  +1 for the references. (@Proletariat, the ls output from /usr/bin is a reference. This is a question about conventions.)
                  – Wildcard
                  Jan 24 '17 at 5:14
















                • The . char can also be used to rotate things, not only to specify an extension. For example my.log my.log.1 my.log.2.gz.
                  – Depado
                  Nov 19 '15 at 17:13










                • So the hyphen/minus/dash is more common that the underscore.
                  – Hugo
                  Mar 4 '16 at 9:26










                • @Hugo Yes. The above shows minus (409) vs underscore (178).
                  – Mikel
                  Mar 4 '16 at 17:31










                • Thanks. Do you have any references for these conventions?
                  – Proletariat
                  Mar 7 '16 at 16:21






                • 2




                  +1 for the references. (@Proletariat, the ls output from /usr/bin is a reference. This is a question about conventions.)
                  – Wildcard
                  Jan 24 '17 at 5:14















                The . char can also be used to rotate things, not only to specify an extension. For example my.log my.log.1 my.log.2.gz.
                – Depado
                Nov 19 '15 at 17:13




                The . char can also be used to rotate things, not only to specify an extension. For example my.log my.log.1 my.log.2.gz.
                – Depado
                Nov 19 '15 at 17:13












                So the hyphen/minus/dash is more common that the underscore.
                – Hugo
                Mar 4 '16 at 9:26




                So the hyphen/minus/dash is more common that the underscore.
                – Hugo
                Mar 4 '16 at 9:26












                @Hugo Yes. The above shows minus (409) vs underscore (178).
                – Mikel
                Mar 4 '16 at 17:31




                @Hugo Yes. The above shows minus (409) vs underscore (178).
                – Mikel
                Mar 4 '16 at 17:31












                Thanks. Do you have any references for these conventions?
                – Proletariat
                Mar 7 '16 at 16:21




                Thanks. Do you have any references for these conventions?
                – Proletariat
                Mar 7 '16 at 16:21




                2




                2




                +1 for the references. (@Proletariat, the ls output from /usr/bin is a reference. This is a question about conventions.)
                – Wildcard
                Jan 24 '17 at 5:14




                +1 for the references. (@Proletariat, the ls output from /usr/bin is a reference. This is a question about conventions.)
                – Wildcard
                Jan 24 '17 at 5:14












                up vote
                35
                down vote













                Far more important that a particular convention is being consistent. Pick a style, and stick with it.






                share|improve this answer


























                  up vote
                  35
                  down vote













                  Far more important that a particular convention is being consistent. Pick a style, and stick with it.






                  share|improve this answer
























                    up vote
                    35
                    down vote










                    up vote
                    35
                    down vote









                    Far more important that a particular convention is being consistent. Pick a style, and stick with it.






                    share|improve this answer














                    Far more important that a particular convention is being consistent. Pick a style, and stick with it.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Feb 14 '11 at 14:33

























                    answered Feb 13 '11 at 14:41









                    David Oneill

                    85011119




                    85011119




















                        up vote
                        15
                        down vote













                        My take on Unix/Linux filename conventions:



                        • Unix/Linux filesystems don't inherently support the notion of an extension. The concept of a file extension completely exists as something supported by utilities such as cp, ls, or the shell you are using. I believe it is this way on NTFS as well, but I could be wrong.


                        • Executables, including shell scripts, usually never have any type of extension. Scripts will have a hashbang line (i.e. #!/bin/bash) that identifies what program should interpret it.


                        • Any executable that is two letters long is super important. So don't name your executables two-letter filenames. Any file in /etc ending in tab is also super important, such as fstab, mtab, inittab.

                        • Sometimes .d is appended to directory names, particularly in /etc, but this isn't widespread (UPDATE: https://serverfault.com/questions/240181/what-does-the-suffix-d-mean-in-linux)


                        • rc is widely used for configuration scripts or files, either prepending (e.g., rc.local) or suffixing (.vimrc)

                        • The Unix/Linux community has never had a three-character limit on extensions and frowns upon shortening well know extensions to fit. For example, don't use .htm at the end of HTML files on Unix/Linux, use .html.

                        • In a set of files, a filename is sometimes capitalized, or in all caps, so it appears at the head of a directory listing. The classic example is Makefile in source packages. Only do this for stuff like README.


                        • ~ is used to identify a backup file or a directory, as in important_stuff~, or /etc~. Many shells will expand a lone ~ to $HOME.

                        • Library files almost always begin with lib. Exception is zlib and probably a few others.

                        • Scripts that are called by inetd sometimes are tagged with a leading in., such as in.tftpd.

                        • The ending z in vmlinuz means zipped, but I've never seen any other file named this way.





                        share|improve this answer


















                        • 2




                          I often see shell scripts with a .sh "extension" on them. I personally find it somewhat annoying, but I have to admit that I may be ignorant of some good reason for using the .sh.
                          – Dan Moulding
                          Feb 14 '11 at 19:07






                        • 1




                          A thing comes to mind that it's useful to emphasize the fact that it is a text-based script and not a binary.
                          – LawrenceC
                          Feb 14 '11 at 20:00






                        • 1




                          @DanMoulding, personally, I use .sh on scripts which are (1) not intended to be run interactively, but only from other scripts/programs, or (2) are designed for sourcing rather than execution. For the former they must be executable; for the latter I leave the executable bit off and use the shebang line only for documentation of what shell the functions are written for.
                          – Wildcard
                          Jan 24 '17 at 5:19







                        • 2




                          @Wildcard I have since (6 years ago) gotten into this same habit. The extension actually makes a lot of sense for sourcing script bits. For instance, from an executable script written for zsh (i.e. #!/bin/zsh at the top) you know you can safely source another file with the .zsh extension and be sure that it contains legal zsh code. If your executable script is strictly Bourne Shell compliant (i.e. #!/bin/sh at the top), then you'd know that sourcing that .zsh file is going to be problematic.
                          – Dan Moulding
                          Jan 25 '17 at 21:00







                        • 3




                          I find using ".sh", ".py", ".pl", etc., is convenient, and some text editors (e.g., Geany) use those to make a first guess at the proper syntax highlighting scheme.
                          – bgvaughan
                          Jun 29 '17 at 15:18














                        up vote
                        15
                        down vote













                        My take on Unix/Linux filename conventions:



                        • Unix/Linux filesystems don't inherently support the notion of an extension. The concept of a file extension completely exists as something supported by utilities such as cp, ls, or the shell you are using. I believe it is this way on NTFS as well, but I could be wrong.


                        • Executables, including shell scripts, usually never have any type of extension. Scripts will have a hashbang line (i.e. #!/bin/bash) that identifies what program should interpret it.


                        • Any executable that is two letters long is super important. So don't name your executables two-letter filenames. Any file in /etc ending in tab is also super important, such as fstab, mtab, inittab.

                        • Sometimes .d is appended to directory names, particularly in /etc, but this isn't widespread (UPDATE: https://serverfault.com/questions/240181/what-does-the-suffix-d-mean-in-linux)


                        • rc is widely used for configuration scripts or files, either prepending (e.g., rc.local) or suffixing (.vimrc)

                        • The Unix/Linux community has never had a three-character limit on extensions and frowns upon shortening well know extensions to fit. For example, don't use .htm at the end of HTML files on Unix/Linux, use .html.

                        • In a set of files, a filename is sometimes capitalized, or in all caps, so it appears at the head of a directory listing. The classic example is Makefile in source packages. Only do this for stuff like README.


                        • ~ is used to identify a backup file or a directory, as in important_stuff~, or /etc~. Many shells will expand a lone ~ to $HOME.

                        • Library files almost always begin with lib. Exception is zlib and probably a few others.

                        • Scripts that are called by inetd sometimes are tagged with a leading in., such as in.tftpd.

                        • The ending z in vmlinuz means zipped, but I've never seen any other file named this way.





                        share|improve this answer


















                        • 2




                          I often see shell scripts with a .sh "extension" on them. I personally find it somewhat annoying, but I have to admit that I may be ignorant of some good reason for using the .sh.
                          – Dan Moulding
                          Feb 14 '11 at 19:07






                        • 1




                          A thing comes to mind that it's useful to emphasize the fact that it is a text-based script and not a binary.
                          – LawrenceC
                          Feb 14 '11 at 20:00






                        • 1




                          @DanMoulding, personally, I use .sh on scripts which are (1) not intended to be run interactively, but only from other scripts/programs, or (2) are designed for sourcing rather than execution. For the former they must be executable; for the latter I leave the executable bit off and use the shebang line only for documentation of what shell the functions are written for.
                          – Wildcard
                          Jan 24 '17 at 5:19







                        • 2




                          @Wildcard I have since (6 years ago) gotten into this same habit. The extension actually makes a lot of sense for sourcing script bits. For instance, from an executable script written for zsh (i.e. #!/bin/zsh at the top) you know you can safely source another file with the .zsh extension and be sure that it contains legal zsh code. If your executable script is strictly Bourne Shell compliant (i.e. #!/bin/sh at the top), then you'd know that sourcing that .zsh file is going to be problematic.
                          – Dan Moulding
                          Jan 25 '17 at 21:00







                        • 3




                          I find using ".sh", ".py", ".pl", etc., is convenient, and some text editors (e.g., Geany) use those to make a first guess at the proper syntax highlighting scheme.
                          – bgvaughan
                          Jun 29 '17 at 15:18












                        up vote
                        15
                        down vote










                        up vote
                        15
                        down vote









                        My take on Unix/Linux filename conventions:



                        • Unix/Linux filesystems don't inherently support the notion of an extension. The concept of a file extension completely exists as something supported by utilities such as cp, ls, or the shell you are using. I believe it is this way on NTFS as well, but I could be wrong.


                        • Executables, including shell scripts, usually never have any type of extension. Scripts will have a hashbang line (i.e. #!/bin/bash) that identifies what program should interpret it.


                        • Any executable that is two letters long is super important. So don't name your executables two-letter filenames. Any file in /etc ending in tab is also super important, such as fstab, mtab, inittab.

                        • Sometimes .d is appended to directory names, particularly in /etc, but this isn't widespread (UPDATE: https://serverfault.com/questions/240181/what-does-the-suffix-d-mean-in-linux)


                        • rc is widely used for configuration scripts or files, either prepending (e.g., rc.local) or suffixing (.vimrc)

                        • The Unix/Linux community has never had a three-character limit on extensions and frowns upon shortening well know extensions to fit. For example, don't use .htm at the end of HTML files on Unix/Linux, use .html.

                        • In a set of files, a filename is sometimes capitalized, or in all caps, so it appears at the head of a directory listing. The classic example is Makefile in source packages. Only do this for stuff like README.


                        • ~ is used to identify a backup file or a directory, as in important_stuff~, or /etc~. Many shells will expand a lone ~ to $HOME.

                        • Library files almost always begin with lib. Exception is zlib and probably a few others.

                        • Scripts that are called by inetd sometimes are tagged with a leading in., such as in.tftpd.

                        • The ending z in vmlinuz means zipped, but I've never seen any other file named this way.





                        share|improve this answer














                        My take on Unix/Linux filename conventions:



                        • Unix/Linux filesystems don't inherently support the notion of an extension. The concept of a file extension completely exists as something supported by utilities such as cp, ls, or the shell you are using. I believe it is this way on NTFS as well, but I could be wrong.


                        • Executables, including shell scripts, usually never have any type of extension. Scripts will have a hashbang line (i.e. #!/bin/bash) that identifies what program should interpret it.


                        • Any executable that is two letters long is super important. So don't name your executables two-letter filenames. Any file in /etc ending in tab is also super important, such as fstab, mtab, inittab.

                        • Sometimes .d is appended to directory names, particularly in /etc, but this isn't widespread (UPDATE: https://serverfault.com/questions/240181/what-does-the-suffix-d-mean-in-linux)


                        • rc is widely used for configuration scripts or files, either prepending (e.g., rc.local) or suffixing (.vimrc)

                        • The Unix/Linux community has never had a three-character limit on extensions and frowns upon shortening well know extensions to fit. For example, don't use .htm at the end of HTML files on Unix/Linux, use .html.

                        • In a set of files, a filename is sometimes capitalized, or in all caps, so it appears at the head of a directory listing. The classic example is Makefile in source packages. Only do this for stuff like README.


                        • ~ is used to identify a backup file or a directory, as in important_stuff~, or /etc~. Many shells will expand a lone ~ to $HOME.

                        • Library files almost always begin with lib. Exception is zlib and probably a few others.

                        • Scripts that are called by inetd sometimes are tagged with a leading in., such as in.tftpd.

                        • The ending z in vmlinuz means zipped, but I've never seen any other file named this way.






                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited Apr 13 '17 at 12:13









                        Community♦

                        1




                        1










                        answered Feb 14 '11 at 15:44









                        LawrenceC

                        8,31722240




                        8,31722240







                        • 2




                          I often see shell scripts with a .sh "extension" on them. I personally find it somewhat annoying, but I have to admit that I may be ignorant of some good reason for using the .sh.
                          – Dan Moulding
                          Feb 14 '11 at 19:07






                        • 1




                          A thing comes to mind that it's useful to emphasize the fact that it is a text-based script and not a binary.
                          – LawrenceC
                          Feb 14 '11 at 20:00






                        • 1




                          @DanMoulding, personally, I use .sh on scripts which are (1) not intended to be run interactively, but only from other scripts/programs, or (2) are designed for sourcing rather than execution. For the former they must be executable; for the latter I leave the executable bit off and use the shebang line only for documentation of what shell the functions are written for.
                          – Wildcard
                          Jan 24 '17 at 5:19







                        • 2




                          @Wildcard I have since (6 years ago) gotten into this same habit. The extension actually makes a lot of sense for sourcing script bits. For instance, from an executable script written for zsh (i.e. #!/bin/zsh at the top) you know you can safely source another file with the .zsh extension and be sure that it contains legal zsh code. If your executable script is strictly Bourne Shell compliant (i.e. #!/bin/sh at the top), then you'd know that sourcing that .zsh file is going to be problematic.
                          – Dan Moulding
                          Jan 25 '17 at 21:00







                        • 3




                          I find using ".sh", ".py", ".pl", etc., is convenient, and some text editors (e.g., Geany) use those to make a first guess at the proper syntax highlighting scheme.
                          – bgvaughan
                          Jun 29 '17 at 15:18












                        • 2




                          I often see shell scripts with a .sh "extension" on them. I personally find it somewhat annoying, but I have to admit that I may be ignorant of some good reason for using the .sh.
                          – Dan Moulding
                          Feb 14 '11 at 19:07






                        • 1




                          A thing comes to mind that it's useful to emphasize the fact that it is a text-based script and not a binary.
                          – LawrenceC
                          Feb 14 '11 at 20:00






                        • 1




                          @DanMoulding, personally, I use .sh on scripts which are (1) not intended to be run interactively, but only from other scripts/programs, or (2) are designed for sourcing rather than execution. For the former they must be executable; for the latter I leave the executable bit off and use the shebang line only for documentation of what shell the functions are written for.
                          – Wildcard
                          Jan 24 '17 at 5:19







                        • 2




                          @Wildcard I have since (6 years ago) gotten into this same habit. The extension actually makes a lot of sense for sourcing script bits. For instance, from an executable script written for zsh (i.e. #!/bin/zsh at the top) you know you can safely source another file with the .zsh extension and be sure that it contains legal zsh code. If your executable script is strictly Bourne Shell compliant (i.e. #!/bin/sh at the top), then you'd know that sourcing that .zsh file is going to be problematic.
                          – Dan Moulding
                          Jan 25 '17 at 21:00







                        • 3




                          I find using ".sh", ".py", ".pl", etc., is convenient, and some text editors (e.g., Geany) use those to make a first guess at the proper syntax highlighting scheme.
                          – bgvaughan
                          Jun 29 '17 at 15:18







                        2




                        2




                        I often see shell scripts with a .sh "extension" on them. I personally find it somewhat annoying, but I have to admit that I may be ignorant of some good reason for using the .sh.
                        – Dan Moulding
                        Feb 14 '11 at 19:07




                        I often see shell scripts with a .sh "extension" on them. I personally find it somewhat annoying, but I have to admit that I may be ignorant of some good reason for using the .sh.
                        – Dan Moulding
                        Feb 14 '11 at 19:07




                        1




                        1




                        A thing comes to mind that it's useful to emphasize the fact that it is a text-based script and not a binary.
                        – LawrenceC
                        Feb 14 '11 at 20:00




                        A thing comes to mind that it's useful to emphasize the fact that it is a text-based script and not a binary.
                        – LawrenceC
                        Feb 14 '11 at 20:00




                        1




                        1




                        @DanMoulding, personally, I use .sh on scripts which are (1) not intended to be run interactively, but only from other scripts/programs, or (2) are designed for sourcing rather than execution. For the former they must be executable; for the latter I leave the executable bit off and use the shebang line only for documentation of what shell the functions are written for.
                        – Wildcard
                        Jan 24 '17 at 5:19





                        @DanMoulding, personally, I use .sh on scripts which are (1) not intended to be run interactively, but only from other scripts/programs, or (2) are designed for sourcing rather than execution. For the former they must be executable; for the latter I leave the executable bit off and use the shebang line only for documentation of what shell the functions are written for.
                        – Wildcard
                        Jan 24 '17 at 5:19





                        2




                        2




                        @Wildcard I have since (6 years ago) gotten into this same habit. The extension actually makes a lot of sense for sourcing script bits. For instance, from an executable script written for zsh (i.e. #!/bin/zsh at the top) you know you can safely source another file with the .zsh extension and be sure that it contains legal zsh code. If your executable script is strictly Bourne Shell compliant (i.e. #!/bin/sh at the top), then you'd know that sourcing that .zsh file is going to be problematic.
                        – Dan Moulding
                        Jan 25 '17 at 21:00





                        @Wildcard I have since (6 years ago) gotten into this same habit. The extension actually makes a lot of sense for sourcing script bits. For instance, from an executable script written for zsh (i.e. #!/bin/zsh at the top) you know you can safely source another file with the .zsh extension and be sure that it contains legal zsh code. If your executable script is strictly Bourne Shell compliant (i.e. #!/bin/sh at the top), then you'd know that sourcing that .zsh file is going to be problematic.
                        – Dan Moulding
                        Jan 25 '17 at 21:00





                        3




                        3




                        I find using ".sh", ".py", ".pl", etc., is convenient, and some text editors (e.g., Geany) use those to make a first guess at the proper syntax highlighting scheme.
                        – bgvaughan
                        Jun 29 '17 at 15:18




                        I find using ".sh", ".py", ".pl", etc., is convenient, and some text editors (e.g., Geany) use those to make a first guess at the proper syntax highlighting scheme.
                        – bgvaughan
                        Jun 29 '17 at 15:18










                        up vote
                        8
                        down vote













                        In unix filename is just a string, unlike DOS, where filename was composed from name and extension. So any of given filenames is completely acceptable.



                        But many programs still use file suffixes beginning with dot to distinguish different file types, i.e. Apache Web Server uses suffixes to set correct MIME type in answer headers.






                        share|improve this answer
















                        • 5




                          While gelraen is 100% correct: Unix/Linux as such does not care about file extensions, modern flavours of Linux do care in so far as some shell extensions provide special identification (colours or otherwise) of certain file types and file managers provide automatic associations with programs. But just as important is for the human user to know which file is what type. To that end it is convenient to stick to a standard scheme not just consistent for yourself but with others. In this respect things should not be overly different than MS Windows (or MIME).
                          – asoundmove
                          Feb 13 '11 at 21:24










                        • That said sometimes several different extension styles can match the same purpose. Thus .tar.gz is equivalent to .tgz, .tar.bz2 = .tbz, .ps.gz is often shortened as .ps (confusingly) and I'm sure there are many more.
                          – asoundmove
                          Feb 13 '11 at 21:28










                        • @asoundmove .ps.gz means it's a compressed .ps file. Just like .tar.gz means compressed .tar file.
                          – jonescb
                          Feb 14 '11 at 15:42







                        • 1




                          @jonescb, yes of course. My point about it being confusing is that when I see .ps I expect a non compressed file (which I should be able to cat or less), but often .ps files are compressed and should in fact be .ps.gz for clarity (as they require zcat or zless for source code viewing). Some people decided to just suffix compressed PostScript files with .ps anyway because some common ps viewers actually don't mind whether they are compressed or not.
                          – asoundmove
                          Feb 14 '11 at 23:03















                        up vote
                        8
                        down vote













                        In unix filename is just a string, unlike DOS, where filename was composed from name and extension. So any of given filenames is completely acceptable.



                        But many programs still use file suffixes beginning with dot to distinguish different file types, i.e. Apache Web Server uses suffixes to set correct MIME type in answer headers.






                        share|improve this answer
















                        • 5




                          While gelraen is 100% correct: Unix/Linux as such does not care about file extensions, modern flavours of Linux do care in so far as some shell extensions provide special identification (colours or otherwise) of certain file types and file managers provide automatic associations with programs. But just as important is for the human user to know which file is what type. To that end it is convenient to stick to a standard scheme not just consistent for yourself but with others. In this respect things should not be overly different than MS Windows (or MIME).
                          – asoundmove
                          Feb 13 '11 at 21:24










                        • That said sometimes several different extension styles can match the same purpose. Thus .tar.gz is equivalent to .tgz, .tar.bz2 = .tbz, .ps.gz is often shortened as .ps (confusingly) and I'm sure there are many more.
                          – asoundmove
                          Feb 13 '11 at 21:28










                        • @asoundmove .ps.gz means it's a compressed .ps file. Just like .tar.gz means compressed .tar file.
                          – jonescb
                          Feb 14 '11 at 15:42







                        • 1




                          @jonescb, yes of course. My point about it being confusing is that when I see .ps I expect a non compressed file (which I should be able to cat or less), but often .ps files are compressed and should in fact be .ps.gz for clarity (as they require zcat or zless for source code viewing). Some people decided to just suffix compressed PostScript files with .ps anyway because some common ps viewers actually don't mind whether they are compressed or not.
                          – asoundmove
                          Feb 14 '11 at 23:03













                        up vote
                        8
                        down vote










                        up vote
                        8
                        down vote









                        In unix filename is just a string, unlike DOS, where filename was composed from name and extension. So any of given filenames is completely acceptable.



                        But many programs still use file suffixes beginning with dot to distinguish different file types, i.e. Apache Web Server uses suffixes to set correct MIME type in answer headers.






                        share|improve this answer












                        In unix filename is just a string, unlike DOS, where filename was composed from name and extension. So any of given filenames is completely acceptable.



                        But many programs still use file suffixes beginning with dot to distinguish different file types, i.e. Apache Web Server uses suffixes to set correct MIME type in answer headers.







                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered Feb 13 '11 at 14:12









                        gelraen

                        4,36011315




                        4,36011315







                        • 5




                          While gelraen is 100% correct: Unix/Linux as such does not care about file extensions, modern flavours of Linux do care in so far as some shell extensions provide special identification (colours or otherwise) of certain file types and file managers provide automatic associations with programs. But just as important is for the human user to know which file is what type. To that end it is convenient to stick to a standard scheme not just consistent for yourself but with others. In this respect things should not be overly different than MS Windows (or MIME).
                          – asoundmove
                          Feb 13 '11 at 21:24










                        • That said sometimes several different extension styles can match the same purpose. Thus .tar.gz is equivalent to .tgz, .tar.bz2 = .tbz, .ps.gz is often shortened as .ps (confusingly) and I'm sure there are many more.
                          – asoundmove
                          Feb 13 '11 at 21:28










                        • @asoundmove .ps.gz means it's a compressed .ps file. Just like .tar.gz means compressed .tar file.
                          – jonescb
                          Feb 14 '11 at 15:42







                        • 1




                          @jonescb, yes of course. My point about it being confusing is that when I see .ps I expect a non compressed file (which I should be able to cat or less), but often .ps files are compressed and should in fact be .ps.gz for clarity (as they require zcat or zless for source code viewing). Some people decided to just suffix compressed PostScript files with .ps anyway because some common ps viewers actually don't mind whether they are compressed or not.
                          – asoundmove
                          Feb 14 '11 at 23:03













                        • 5




                          While gelraen is 100% correct: Unix/Linux as such does not care about file extensions, modern flavours of Linux do care in so far as some shell extensions provide special identification (colours or otherwise) of certain file types and file managers provide automatic associations with programs. But just as important is for the human user to know which file is what type. To that end it is convenient to stick to a standard scheme not just consistent for yourself but with others. In this respect things should not be overly different than MS Windows (or MIME).
                          – asoundmove
                          Feb 13 '11 at 21:24










                        • That said sometimes several different extension styles can match the same purpose. Thus .tar.gz is equivalent to .tgz, .tar.bz2 = .tbz, .ps.gz is often shortened as .ps (confusingly) and I'm sure there are many more.
                          – asoundmove
                          Feb 13 '11 at 21:28










                        • @asoundmove .ps.gz means it's a compressed .ps file. Just like .tar.gz means compressed .tar file.
                          – jonescb
                          Feb 14 '11 at 15:42







                        • 1




                          @jonescb, yes of course. My point about it being confusing is that when I see .ps I expect a non compressed file (which I should be able to cat or less), but often .ps files are compressed and should in fact be .ps.gz for clarity (as they require zcat or zless for source code viewing). Some people decided to just suffix compressed PostScript files with .ps anyway because some common ps viewers actually don't mind whether they are compressed or not.
                          – asoundmove
                          Feb 14 '11 at 23:03








                        5




                        5




                        While gelraen is 100% correct: Unix/Linux as such does not care about file extensions, modern flavours of Linux do care in so far as some shell extensions provide special identification (colours or otherwise) of certain file types and file managers provide automatic associations with programs. But just as important is for the human user to know which file is what type. To that end it is convenient to stick to a standard scheme not just consistent for yourself but with others. In this respect things should not be overly different than MS Windows (or MIME).
                        – asoundmove
                        Feb 13 '11 at 21:24




                        While gelraen is 100% correct: Unix/Linux as such does not care about file extensions, modern flavours of Linux do care in so far as some shell extensions provide special identification (colours or otherwise) of certain file types and file managers provide automatic associations with programs. But just as important is for the human user to know which file is what type. To that end it is convenient to stick to a standard scheme not just consistent for yourself but with others. In this respect things should not be overly different than MS Windows (or MIME).
                        – asoundmove
                        Feb 13 '11 at 21:24












                        That said sometimes several different extension styles can match the same purpose. Thus .tar.gz is equivalent to .tgz, .tar.bz2 = .tbz, .ps.gz is often shortened as .ps (confusingly) and I'm sure there are many more.
                        – asoundmove
                        Feb 13 '11 at 21:28




                        That said sometimes several different extension styles can match the same purpose. Thus .tar.gz is equivalent to .tgz, .tar.bz2 = .tbz, .ps.gz is often shortened as .ps (confusingly) and I'm sure there are many more.
                        – asoundmove
                        Feb 13 '11 at 21:28












                        @asoundmove .ps.gz means it's a compressed .ps file. Just like .tar.gz means compressed .tar file.
                        – jonescb
                        Feb 14 '11 at 15:42





                        @asoundmove .ps.gz means it's a compressed .ps file. Just like .tar.gz means compressed .tar file.
                        – jonescb
                        Feb 14 '11 at 15:42





                        1




                        1




                        @jonescb, yes of course. My point about it being confusing is that when I see .ps I expect a non compressed file (which I should be able to cat or less), but often .ps files are compressed and should in fact be .ps.gz for clarity (as they require zcat or zless for source code viewing). Some people decided to just suffix compressed PostScript files with .ps anyway because some common ps viewers actually don't mind whether they are compressed or not.
                        – asoundmove
                        Feb 14 '11 at 23:03





                        @jonescb, yes of course. My point about it being confusing is that when I see .ps I expect a non compressed file (which I should be able to cat or less), but often .ps files are compressed and should in fact be .ps.gz for clarity (as they require zcat or zless for source code viewing). Some people decided to just suffix compressed PostScript files with .ps anyway because some common ps viewers actually don't mind whether they are compressed or not.
                        – asoundmove
                        Feb 14 '11 at 23:03











                        up vote
                        6
                        down vote













                        Characters you should not use in filenames:




                        | ; , ! @ # $ ( ) < > / " ' ` ~
                        [ ] = + & ^




                        Character delimiters you should use to make names easier to read:




                        _ - . :




                        (In some cases ":" has special meaning though)






                        share|improve this answer
















                        • 5




                          Of course, you can't even use "/" in filenames. Everything else is possible. And if you want to make it hard to access, even useful ;-)
                          – Jürgen A. Erhard
                          Feb 14 '11 at 12:48










                        • The list is actually a lot longer, including control and non-ASCII characters. Yes, you can have a backspace as part of a *nix file name.
                          – l0b0
                          Jun 20 '11 at 12:13










                        • More to the point, most *nix systems only disallow two specific characters in file names: the / path separator, and the (ASCII zero) string terminator.
                          – Michael Kjörling
                          Jun 26 '13 at 21:45














                        up vote
                        6
                        down vote













                        Characters you should not use in filenames:




                        | ; , ! @ # $ ( ) < > / " ' ` ~
                        [ ] = + & ^




                        Character delimiters you should use to make names easier to read:




                        _ - . :




                        (In some cases ":" has special meaning though)






                        share|improve this answer
















                        • 5




                          Of course, you can't even use "/" in filenames. Everything else is possible. And if you want to make it hard to access, even useful ;-)
                          – Jürgen A. Erhard
                          Feb 14 '11 at 12:48










                        • The list is actually a lot longer, including control and non-ASCII characters. Yes, you can have a backspace as part of a *nix file name.
                          – l0b0
                          Jun 20 '11 at 12:13










                        • More to the point, most *nix systems only disallow two specific characters in file names: the / path separator, and the (ASCII zero) string terminator.
                          – Michael Kjörling
                          Jun 26 '13 at 21:45












                        up vote
                        6
                        down vote










                        up vote
                        6
                        down vote









                        Characters you should not use in filenames:




                        | ; , ! @ # $ ( ) < > / " ' ` ~
                        [ ] = + & ^




                        Character delimiters you should use to make names easier to read:




                        _ - . :




                        (In some cases ":" has special meaning though)






                        share|improve this answer












                        Characters you should not use in filenames:




                        | ; , ! @ # $ ( ) < > / " ' ` ~
                        [ ] = + & ^




                        Character delimiters you should use to make names easier to read:




                        _ - . :




                        (In some cases ":" has special meaning though)







                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered Feb 13 '11 at 14:06









                        Istvan

                        1704




                        1704







                        • 5




                          Of course, you can't even use "/" in filenames. Everything else is possible. And if you want to make it hard to access, even useful ;-)
                          – Jürgen A. Erhard
                          Feb 14 '11 at 12:48










                        • The list is actually a lot longer, including control and non-ASCII characters. Yes, you can have a backspace as part of a *nix file name.
                          – l0b0
                          Jun 20 '11 at 12:13










                        • More to the point, most *nix systems only disallow two specific characters in file names: the / path separator, and the (ASCII zero) string terminator.
                          – Michael Kjörling
                          Jun 26 '13 at 21:45












                        • 5




                          Of course, you can't even use "/" in filenames. Everything else is possible. And if you want to make it hard to access, even useful ;-)
                          – Jürgen A. Erhard
                          Feb 14 '11 at 12:48










                        • The list is actually a lot longer, including control and non-ASCII characters. Yes, you can have a backspace as part of a *nix file name.
                          – l0b0
                          Jun 20 '11 at 12:13










                        • More to the point, most *nix systems only disallow two specific characters in file names: the / path separator, and the (ASCII zero) string terminator.
                          – Michael Kjörling
                          Jun 26 '13 at 21:45







                        5




                        5




                        Of course, you can't even use "/" in filenames. Everything else is possible. And if you want to make it hard to access, even useful ;-)
                        – Jürgen A. Erhard
                        Feb 14 '11 at 12:48




                        Of course, you can't even use "/" in filenames. Everything else is possible. And if you want to make it hard to access, even useful ;-)
                        – Jürgen A. Erhard
                        Feb 14 '11 at 12:48












                        The list is actually a lot longer, including control and non-ASCII characters. Yes, you can have a backspace as part of a *nix file name.
                        – l0b0
                        Jun 20 '11 at 12:13




                        The list is actually a lot longer, including control and non-ASCII characters. Yes, you can have a backspace as part of a *nix file name.
                        – l0b0
                        Jun 20 '11 at 12:13












                        More to the point, most *nix systems only disallow two specific characters in file names: the / path separator, and the (ASCII zero) string terminator.
                        – Michael Kjörling
                        Jun 26 '13 at 21:45




                        More to the point, most *nix systems only disallow two specific characters in file names: the / path separator, and the (ASCII zero) string terminator.
                        – Michael Kjörling
                        Jun 26 '13 at 21:45










                        up vote
                        5
                        down vote













                        To add to what others have said, I'd just say that while accented letters and many special characters are legal in filenames they can cause issues in any of the following scenarios:



                        • You share your filesystem with other computers, particularly with different operating systems;

                        • You share files with others (and although email tends to be quite good with conversions, sometimes it just does not work);

                        • You use shell scripts to automate some tasks (spaces are particularly problematic, though there are many ways to deal with them);

                        • You use a file share from another computer.

                        ...






                        share|improve this answer


























                          up vote
                          5
                          down vote













                          To add to what others have said, I'd just say that while accented letters and many special characters are legal in filenames they can cause issues in any of the following scenarios:



                          • You share your filesystem with other computers, particularly with different operating systems;

                          • You share files with others (and although email tends to be quite good with conversions, sometimes it just does not work);

                          • You use shell scripts to automate some tasks (spaces are particularly problematic, though there are many ways to deal with them);

                          • You use a file share from another computer.

                          ...






                          share|improve this answer
























                            up vote
                            5
                            down vote










                            up vote
                            5
                            down vote









                            To add to what others have said, I'd just say that while accented letters and many special characters are legal in filenames they can cause issues in any of the following scenarios:



                            • You share your filesystem with other computers, particularly with different operating systems;

                            • You share files with others (and although email tends to be quite good with conversions, sometimes it just does not work);

                            • You use shell scripts to automate some tasks (spaces are particularly problematic, though there are many ways to deal with them);

                            • You use a file share from another computer.

                            ...






                            share|improve this answer














                            To add to what others have said, I'd just say that while accented letters and many special characters are legal in filenames they can cause issues in any of the following scenarios:



                            • You share your filesystem with other computers, particularly with different operating systems;

                            • You share files with others (and although email tends to be quite good with conversions, sometimes it just does not work);

                            • You use shell scripts to automate some tasks (spaces are particularly problematic, though there are many ways to deal with them);

                            • You use a file share from another computer.

                            ...







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Jun 20 '11 at 3:18

























                            answered Feb 13 '11 at 21:35









                            asoundmove

                            1,92911217




                            1,92911217




















                                up vote
                                4
                                down vote













                                Stick to alphanumeric filenames. Avoid spaces or replace spaces with underscores ( _ ). Limit punctuation in file names to periods (.), underscores ( _ ), and hyphens (-). Generally filenames are lowercase, but I use CamelCase when I have multiple words in the filename.



                                Use extensions which indicate the type of file. Programs do not need extensions as the execute bit is used to indicate programs, and the shells know how to run programs of various types. It is common but not required to (.sh) for shell scripts, and (.pl) for perl scripts. The Windows executable extensions .bat, .com, .scr, and .exe indicate Windows executables on Unix.



                                Pick a standard and stick to it. But it won't break things if you avoid it.



                                Hidden (or dot) files have names starting with a period. These normally don't show up in directory listings. Use 'ls -a' to include the dot files in the list.






                                share|improve this answer


















                                • 3




                                  CamelCase is an anti pattern on Unix. The OP was asking about conventions.
                                  – Mikel
                                  Feb 13 '11 at 21:46






                                • 2




                                  It's not "bad" versus "good". It's "this is how it's usually done". It's a convention the OP was asking for. The reason? It could be because Unix people don't like pressing Shift, it could be because old systems only had UPPERCASE, or for another reason. I'm not sure.
                                  – Mikel
                                  Feb 14 '11 at 3:03










                                • @Mikel I also program Java where CamelCase is a convention. Sometimes patterns and conventions conflict.
                                  – BillThor
                                  Feb 14 '11 at 17:16











                                • .scr is also a Windows executable extension.
                                  – LawrenceC
                                  Feb 25 '11 at 0:17






                                • 1




                                  @ultrasawblade Thanks, shows how often I script Windows. I tried to skip the rarer executable extensions like cmd, pif, vb*, wsh, and the rest of them.
                                  – BillThor
                                  Feb 25 '11 at 19:37















                                up vote
                                4
                                down vote













                                Stick to alphanumeric filenames. Avoid spaces or replace spaces with underscores ( _ ). Limit punctuation in file names to periods (.), underscores ( _ ), and hyphens (-). Generally filenames are lowercase, but I use CamelCase when I have multiple words in the filename.



                                Use extensions which indicate the type of file. Programs do not need extensions as the execute bit is used to indicate programs, and the shells know how to run programs of various types. It is common but not required to (.sh) for shell scripts, and (.pl) for perl scripts. The Windows executable extensions .bat, .com, .scr, and .exe indicate Windows executables on Unix.



                                Pick a standard and stick to it. But it won't break things if you avoid it.



                                Hidden (or dot) files have names starting with a period. These normally don't show up in directory listings. Use 'ls -a' to include the dot files in the list.






                                share|improve this answer


















                                • 3




                                  CamelCase is an anti pattern on Unix. The OP was asking about conventions.
                                  – Mikel
                                  Feb 13 '11 at 21:46






                                • 2




                                  It's not "bad" versus "good". It's "this is how it's usually done". It's a convention the OP was asking for. The reason? It could be because Unix people don't like pressing Shift, it could be because old systems only had UPPERCASE, or for another reason. I'm not sure.
                                  – Mikel
                                  Feb 14 '11 at 3:03










                                • @Mikel I also program Java where CamelCase is a convention. Sometimes patterns and conventions conflict.
                                  – BillThor
                                  Feb 14 '11 at 17:16











                                • .scr is also a Windows executable extension.
                                  – LawrenceC
                                  Feb 25 '11 at 0:17






                                • 1




                                  @ultrasawblade Thanks, shows how often I script Windows. I tried to skip the rarer executable extensions like cmd, pif, vb*, wsh, and the rest of them.
                                  – BillThor
                                  Feb 25 '11 at 19:37













                                up vote
                                4
                                down vote










                                up vote
                                4
                                down vote









                                Stick to alphanumeric filenames. Avoid spaces or replace spaces with underscores ( _ ). Limit punctuation in file names to periods (.), underscores ( _ ), and hyphens (-). Generally filenames are lowercase, but I use CamelCase when I have multiple words in the filename.



                                Use extensions which indicate the type of file. Programs do not need extensions as the execute bit is used to indicate programs, and the shells know how to run programs of various types. It is common but not required to (.sh) for shell scripts, and (.pl) for perl scripts. The Windows executable extensions .bat, .com, .scr, and .exe indicate Windows executables on Unix.



                                Pick a standard and stick to it. But it won't break things if you avoid it.



                                Hidden (or dot) files have names starting with a period. These normally don't show up in directory listings. Use 'ls -a' to include the dot files in the list.






                                share|improve this answer














                                Stick to alphanumeric filenames. Avoid spaces or replace spaces with underscores ( _ ). Limit punctuation in file names to periods (.), underscores ( _ ), and hyphens (-). Generally filenames are lowercase, but I use CamelCase when I have multiple words in the filename.



                                Use extensions which indicate the type of file. Programs do not need extensions as the execute bit is used to indicate programs, and the shells know how to run programs of various types. It is common but not required to (.sh) for shell scripts, and (.pl) for perl scripts. The Windows executable extensions .bat, .com, .scr, and .exe indicate Windows executables on Unix.



                                Pick a standard and stick to it. But it won't break things if you avoid it.



                                Hidden (or dot) files have names starting with a period. These normally don't show up in directory listings. Use 'ls -a' to include the dot files in the list.







                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                edited Feb 25 '11 at 19:32

























                                answered Feb 13 '11 at 16:09









                                BillThor

                                7,4651325




                                7,4651325







                                • 3




                                  CamelCase is an anti pattern on Unix. The OP was asking about conventions.
                                  – Mikel
                                  Feb 13 '11 at 21:46






                                • 2




                                  It's not "bad" versus "good". It's "this is how it's usually done". It's a convention the OP was asking for. The reason? It could be because Unix people don't like pressing Shift, it could be because old systems only had UPPERCASE, or for another reason. I'm not sure.
                                  – Mikel
                                  Feb 14 '11 at 3:03










                                • @Mikel I also program Java where CamelCase is a convention. Sometimes patterns and conventions conflict.
                                  – BillThor
                                  Feb 14 '11 at 17:16











                                • .scr is also a Windows executable extension.
                                  – LawrenceC
                                  Feb 25 '11 at 0:17






                                • 1




                                  @ultrasawblade Thanks, shows how often I script Windows. I tried to skip the rarer executable extensions like cmd, pif, vb*, wsh, and the rest of them.
                                  – BillThor
                                  Feb 25 '11 at 19:37













                                • 3




                                  CamelCase is an anti pattern on Unix. The OP was asking about conventions.
                                  – Mikel
                                  Feb 13 '11 at 21:46






                                • 2




                                  It's not "bad" versus "good". It's "this is how it's usually done". It's a convention the OP was asking for. The reason? It could be because Unix people don't like pressing Shift, it could be because old systems only had UPPERCASE, or for another reason. I'm not sure.
                                  – Mikel
                                  Feb 14 '11 at 3:03










                                • @Mikel I also program Java where CamelCase is a convention. Sometimes patterns and conventions conflict.
                                  – BillThor
                                  Feb 14 '11 at 17:16











                                • .scr is also a Windows executable extension.
                                  – LawrenceC
                                  Feb 25 '11 at 0:17






                                • 1




                                  @ultrasawblade Thanks, shows how often I script Windows. I tried to skip the rarer executable extensions like cmd, pif, vb*, wsh, and the rest of them.
                                  – BillThor
                                  Feb 25 '11 at 19:37








                                3




                                3




                                CamelCase is an anti pattern on Unix. The OP was asking about conventions.
                                – Mikel
                                Feb 13 '11 at 21:46




                                CamelCase is an anti pattern on Unix. The OP was asking about conventions.
                                – Mikel
                                Feb 13 '11 at 21:46




                                2




                                2




                                It's not "bad" versus "good". It's "this is how it's usually done". It's a convention the OP was asking for. The reason? It could be because Unix people don't like pressing Shift, it could be because old systems only had UPPERCASE, or for another reason. I'm not sure.
                                – Mikel
                                Feb 14 '11 at 3:03




                                It's not "bad" versus "good". It's "this is how it's usually done". It's a convention the OP was asking for. The reason? It could be because Unix people don't like pressing Shift, it could be because old systems only had UPPERCASE, or for another reason. I'm not sure.
                                – Mikel
                                Feb 14 '11 at 3:03












                                @Mikel I also program Java where CamelCase is a convention. Sometimes patterns and conventions conflict.
                                – BillThor
                                Feb 14 '11 at 17:16





                                @Mikel I also program Java where CamelCase is a convention. Sometimes patterns and conventions conflict.
                                – BillThor
                                Feb 14 '11 at 17:16













                                .scr is also a Windows executable extension.
                                – LawrenceC
                                Feb 25 '11 at 0:17




                                .scr is also a Windows executable extension.
                                – LawrenceC
                                Feb 25 '11 at 0:17




                                1




                                1




                                @ultrasawblade Thanks, shows how often I script Windows. I tried to skip the rarer executable extensions like cmd, pif, vb*, wsh, and the rest of them.
                                – BillThor
                                Feb 25 '11 at 19:37





                                @ultrasawblade Thanks, shows how often I script Windows. I tried to skip the rarer executable extensions like cmd, pif, vb*, wsh, and the rest of them.
                                – BillThor
                                Feb 25 '11 at 19:37











                                up vote
                                4
                                down vote













                                Two thoughts:




                                1. In the Naming Variables, Functions, and Files section of the GNU Coding Standards you'll find:




                                  Please use underscores to separate words in a name, so that the Emacs word commands can be useful within them. Stick to lower case;




                                  While IMO saying "You should use _ because emacs" seems a bit dated, it is nevertheless in their 'standards' document.




                                2. Let's suppose for a moment that we all agree that the linux kernel is the be-all-and-end-all* of linux projects, and that the conventions used there are what could be considered 'standard' convention.



                                  grep-ing source for the linux kernel you'll find the following:




                                  • 44.6% of the time only dash is used


                                  • 54.1% of the time only underscore


                                  • 1.2% of the time a file uses both.


                                Interestingly, the source for git weighs in at 85% for dashes, 3.8% for underscores, and 11.1% for both.



                                The choice is clear, debate over. ;)



                                Personal opinion: I use dashes for aesthetic and shift key reasons. If you're working on a team, take a vote. But to reiterate what's been said, be consistent.



                                * or "be_all and end_all" if you like






                                share|improve this answer
























                                  up vote
                                  4
                                  down vote













                                  Two thoughts:




                                  1. In the Naming Variables, Functions, and Files section of the GNU Coding Standards you'll find:




                                    Please use underscores to separate words in a name, so that the Emacs word commands can be useful within them. Stick to lower case;




                                    While IMO saying "You should use _ because emacs" seems a bit dated, it is nevertheless in their 'standards' document.




                                  2. Let's suppose for a moment that we all agree that the linux kernel is the be-all-and-end-all* of linux projects, and that the conventions used there are what could be considered 'standard' convention.



                                    grep-ing source for the linux kernel you'll find the following:




                                    • 44.6% of the time only dash is used


                                    • 54.1% of the time only underscore


                                    • 1.2% of the time a file uses both.


                                  Interestingly, the source for git weighs in at 85% for dashes, 3.8% for underscores, and 11.1% for both.



                                  The choice is clear, debate over. ;)



                                  Personal opinion: I use dashes for aesthetic and shift key reasons. If you're working on a team, take a vote. But to reiterate what's been said, be consistent.



                                  * or "be_all and end_all" if you like






                                  share|improve this answer






















                                    up vote
                                    4
                                    down vote










                                    up vote
                                    4
                                    down vote









                                    Two thoughts:




                                    1. In the Naming Variables, Functions, and Files section of the GNU Coding Standards you'll find:




                                      Please use underscores to separate words in a name, so that the Emacs word commands can be useful within them. Stick to lower case;




                                      While IMO saying "You should use _ because emacs" seems a bit dated, it is nevertheless in their 'standards' document.




                                    2. Let's suppose for a moment that we all agree that the linux kernel is the be-all-and-end-all* of linux projects, and that the conventions used there are what could be considered 'standard' convention.



                                      grep-ing source for the linux kernel you'll find the following:




                                      • 44.6% of the time only dash is used


                                      • 54.1% of the time only underscore


                                      • 1.2% of the time a file uses both.


                                    Interestingly, the source for git weighs in at 85% for dashes, 3.8% for underscores, and 11.1% for both.



                                    The choice is clear, debate over. ;)



                                    Personal opinion: I use dashes for aesthetic and shift key reasons. If you're working on a team, take a vote. But to reiterate what's been said, be consistent.



                                    * or "be_all and end_all" if you like






                                    share|improve this answer












                                    Two thoughts:




                                    1. In the Naming Variables, Functions, and Files section of the GNU Coding Standards you'll find:




                                      Please use underscores to separate words in a name, so that the Emacs word commands can be useful within them. Stick to lower case;




                                      While IMO saying "You should use _ because emacs" seems a bit dated, it is nevertheless in their 'standards' document.




                                    2. Let's suppose for a moment that we all agree that the linux kernel is the be-all-and-end-all* of linux projects, and that the conventions used there are what could be considered 'standard' convention.



                                      grep-ing source for the linux kernel you'll find the following:




                                      • 44.6% of the time only dash is used


                                      • 54.1% of the time only underscore


                                      • 1.2% of the time a file uses both.


                                    Interestingly, the source for git weighs in at 85% for dashes, 3.8% for underscores, and 11.1% for both.



                                    The choice is clear, debate over. ;)



                                    Personal opinion: I use dashes for aesthetic and shift key reasons. If you're working on a team, take a vote. But to reiterate what's been said, be consistent.



                                    * or "be_all and end_all" if you like







                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Aug 8 '16 at 14:41









                                    Roy Truelove

                                    1412




                                    1412




















                                        up vote
                                        0
                                        down vote













                                        I agree with David Oneill that you should just go with something.



                                        But it is nice if the files is sortable in the same dir,
                                        so dont number 0..10 but number 00..10.



                                        When using dates in names, go with a standard date format like ISO8601.



                                        And dont be afraid to use multiple chars to separate logical parts in the name. If you use _ (that was 3 _), then you can simplify the regexps on filenames later on.



                                        So your example could then be something like this:



                                        backup_2011-06-19T114012___part002___random


                                        Easy to read and easy to parse with scripts.






                                        share|improve this answer
























                                          up vote
                                          0
                                          down vote













                                          I agree with David Oneill that you should just go with something.



                                          But it is nice if the files is sortable in the same dir,
                                          so dont number 0..10 but number 00..10.



                                          When using dates in names, go with a standard date format like ISO8601.



                                          And dont be afraid to use multiple chars to separate logical parts in the name. If you use _ (that was 3 _), then you can simplify the regexps on filenames later on.



                                          So your example could then be something like this:



                                          backup_2011-06-19T114012___part002___random


                                          Easy to read and easy to parse with scripts.






                                          share|improve this answer






















                                            up vote
                                            0
                                            down vote










                                            up vote
                                            0
                                            down vote









                                            I agree with David Oneill that you should just go with something.



                                            But it is nice if the files is sortable in the same dir,
                                            so dont number 0..10 but number 00..10.



                                            When using dates in names, go with a standard date format like ISO8601.



                                            And dont be afraid to use multiple chars to separate logical parts in the name. If you use _ (that was 3 _), then you can simplify the regexps on filenames later on.



                                            So your example could then be something like this:



                                            backup_2011-06-19T114012___part002___random


                                            Easy to read and easy to parse with scripts.






                                            share|improve this answer












                                            I agree with David Oneill that you should just go with something.



                                            But it is nice if the files is sortable in the same dir,
                                            so dont number 0..10 but number 00..10.



                                            When using dates in names, go with a standard date format like ISO8601.



                                            And dont be afraid to use multiple chars to separate logical parts in the name. If you use _ (that was 3 _), then you can simplify the regexps on filenames later on.



                                            So your example could then be something like this:



                                            backup_2011-06-19T114012___part002___random


                                            Easy to read and easy to parse with scripts.







                                            share|improve this answer












                                            share|improve this answer



                                            share|improve this answer










                                            answered Jun 19 '11 at 9:41









                                            Johan

                                            3,13911627




                                            3,13911627




















                                                up vote
                                                0
                                                down vote













                                                Words in a filename can be either separated with _ or - according to Unix convention.



                                                If you use -, it's easier to type, saves you from pressing SHIFT. But since - takes so little space, it is a bit hard to read word separations compared to _. Using _ to separate words makes it look much cleaner since _ takes up more space.



                                                In shell scripting and other computer programming, _ are used for multi word variables, like MY_ENVIRONMENT_FILE. Making the filenames use _ as well keeps it consistent: MY_ENVIRONMENT_FILE=~/my_environment_file.



                                                In web development, - is preferred for file naming. One reason is probably because the underline in weblinks can hide the underscores and might make it difficult if you are typing the weblink by hand.



                                                In most editors and as well as web pages, this_long_word can be fully selected with a double click but not this-long-word.






                                                share|improve this answer




















                                                • Hmmm, why are you reading your filenames in a variable-width font? Open up your terminal and - and _ take up just exactly the same space! :)
                                                  – Wildcard
                                                  Jan 24 '17 at 5:27











                                                • Haha, you are right. I use the SourceCodePro+Powerline+Awesome Regular patched font. Even with monospace fonts, _ looks cleaner even though it takes the same space as -. I should have used the word "apparently". Regarding the _ and - when using monospace fonts, the difference can be best explained with this analogical picture: evsc.net/v8/wp/wp-content/uploads/2010/09/…
                                                  – GMaster
                                                  Jan 24 '17 at 5:46















                                                up vote
                                                0
                                                down vote













                                                Words in a filename can be either separated with _ or - according to Unix convention.



                                                If you use -, it's easier to type, saves you from pressing SHIFT. But since - takes so little space, it is a bit hard to read word separations compared to _. Using _ to separate words makes it look much cleaner since _ takes up more space.



                                                In shell scripting and other computer programming, _ are used for multi word variables, like MY_ENVIRONMENT_FILE. Making the filenames use _ as well keeps it consistent: MY_ENVIRONMENT_FILE=~/my_environment_file.



                                                In web development, - is preferred for file naming. One reason is probably because the underline in weblinks can hide the underscores and might make it difficult if you are typing the weblink by hand.



                                                In most editors and as well as web pages, this_long_word can be fully selected with a double click but not this-long-word.






                                                share|improve this answer




















                                                • Hmmm, why are you reading your filenames in a variable-width font? Open up your terminal and - and _ take up just exactly the same space! :)
                                                  – Wildcard
                                                  Jan 24 '17 at 5:27











                                                • Haha, you are right. I use the SourceCodePro+Powerline+Awesome Regular patched font. Even with monospace fonts, _ looks cleaner even though it takes the same space as -. I should have used the word "apparently". Regarding the _ and - when using monospace fonts, the difference can be best explained with this analogical picture: evsc.net/v8/wp/wp-content/uploads/2010/09/…
                                                  – GMaster
                                                  Jan 24 '17 at 5:46













                                                up vote
                                                0
                                                down vote










                                                up vote
                                                0
                                                down vote









                                                Words in a filename can be either separated with _ or - according to Unix convention.



                                                If you use -, it's easier to type, saves you from pressing SHIFT. But since - takes so little space, it is a bit hard to read word separations compared to _. Using _ to separate words makes it look much cleaner since _ takes up more space.



                                                In shell scripting and other computer programming, _ are used for multi word variables, like MY_ENVIRONMENT_FILE. Making the filenames use _ as well keeps it consistent: MY_ENVIRONMENT_FILE=~/my_environment_file.



                                                In web development, - is preferred for file naming. One reason is probably because the underline in weblinks can hide the underscores and might make it difficult if you are typing the weblink by hand.



                                                In most editors and as well as web pages, this_long_word can be fully selected with a double click but not this-long-word.






                                                share|improve this answer












                                                Words in a filename can be either separated with _ or - according to Unix convention.



                                                If you use -, it's easier to type, saves you from pressing SHIFT. But since - takes so little space, it is a bit hard to read word separations compared to _. Using _ to separate words makes it look much cleaner since _ takes up more space.



                                                In shell scripting and other computer programming, _ are used for multi word variables, like MY_ENVIRONMENT_FILE. Making the filenames use _ as well keeps it consistent: MY_ENVIRONMENT_FILE=~/my_environment_file.



                                                In web development, - is preferred for file naming. One reason is probably because the underline in weblinks can hide the underscores and might make it difficult if you are typing the weblink by hand.



                                                In most editors and as well as web pages, this_long_word can be fully selected with a double click but not this-long-word.







                                                share|improve this answer












                                                share|improve this answer



                                                share|improve this answer










                                                answered Jan 24 '17 at 4:27









                                                GMaster

                                                1,6391119




                                                1,6391119











                                                • Hmmm, why are you reading your filenames in a variable-width font? Open up your terminal and - and _ take up just exactly the same space! :)
                                                  – Wildcard
                                                  Jan 24 '17 at 5:27











                                                • Haha, you are right. I use the SourceCodePro+Powerline+Awesome Regular patched font. Even with monospace fonts, _ looks cleaner even though it takes the same space as -. I should have used the word "apparently". Regarding the _ and - when using monospace fonts, the difference can be best explained with this analogical picture: evsc.net/v8/wp/wp-content/uploads/2010/09/…
                                                  – GMaster
                                                  Jan 24 '17 at 5:46

















                                                • Hmmm, why are you reading your filenames in a variable-width font? Open up your terminal and - and _ take up just exactly the same space! :)
                                                  – Wildcard
                                                  Jan 24 '17 at 5:27











                                                • Haha, you are right. I use the SourceCodePro+Powerline+Awesome Regular patched font. Even with monospace fonts, _ looks cleaner even though it takes the same space as -. I should have used the word "apparently". Regarding the _ and - when using monospace fonts, the difference can be best explained with this analogical picture: evsc.net/v8/wp/wp-content/uploads/2010/09/…
                                                  – GMaster
                                                  Jan 24 '17 at 5:46
















                                                Hmmm, why are you reading your filenames in a variable-width font? Open up your terminal and - and _ take up just exactly the same space! :)
                                                – Wildcard
                                                Jan 24 '17 at 5:27





                                                Hmmm, why are you reading your filenames in a variable-width font? Open up your terminal and - and _ take up just exactly the same space! :)
                                                – Wildcard
                                                Jan 24 '17 at 5:27













                                                Haha, you are right. I use the SourceCodePro+Powerline+Awesome Regular patched font. Even with monospace fonts, _ looks cleaner even though it takes the same space as -. I should have used the word "apparently". Regarding the _ and - when using monospace fonts, the difference can be best explained with this analogical picture: evsc.net/v8/wp/wp-content/uploads/2010/09/…
                                                – GMaster
                                                Jan 24 '17 at 5:46





                                                Haha, you are right. I use the SourceCodePro+Powerline+Awesome Regular patched font. Even with monospace fonts, _ looks cleaner even though it takes the same space as -. I should have used the word "apparently". Regarding the _ and - when using monospace fonts, the difference can be best explained with this analogical picture: evsc.net/v8/wp/wp-content/uploads/2010/09/…
                                                – GMaster
                                                Jan 24 '17 at 5:46











                                                up vote
                                                0
                                                down vote













                                                One convention is to use "_" to replace spaces as separators between words. Other characters could be used to replace spaces, but there are slightly stronger conventional uses for "-" and "." in pathnames, so "_" is usually preferred.



                                                Spaces are legal in pathnames, but are conventionally avoided, because they require quoting the pathname ("foo bar") or escaping the spaces (foo bar). A properly written shell script will quote variables that may include spaces, particularly pathnames, but failing to do so is a common oversight, and it's a lot of extra typing when doing a one-off command entered at the command line.



                                                Using "-" to separate clusters of numbers, as in timestamps or serial numbers, is a convention commonly used outside the context of filesystems. Using "." to separate "file extensions" that indicate the type of file is very common, and some important tools depend on it. For instance, the package management system on Red Hat Enterprise Linux and its derivatives, RPM, expects package files to end with ".rpm". The traditional tarball is a tar file (".tar") that has been gzipped (".gz"), and so ends in ".tar.gz".



                                                So putting these together, you often end up with filenames that look like, "home_backup_2017-07-01.tar.gz"






                                                share|improve this answer
























                                                  up vote
                                                  0
                                                  down vote













                                                  One convention is to use "_" to replace spaces as separators between words. Other characters could be used to replace spaces, but there are slightly stronger conventional uses for "-" and "." in pathnames, so "_" is usually preferred.



                                                  Spaces are legal in pathnames, but are conventionally avoided, because they require quoting the pathname ("foo bar") or escaping the spaces (foo bar). A properly written shell script will quote variables that may include spaces, particularly pathnames, but failing to do so is a common oversight, and it's a lot of extra typing when doing a one-off command entered at the command line.



                                                  Using "-" to separate clusters of numbers, as in timestamps or serial numbers, is a convention commonly used outside the context of filesystems. Using "." to separate "file extensions" that indicate the type of file is very common, and some important tools depend on it. For instance, the package management system on Red Hat Enterprise Linux and its derivatives, RPM, expects package files to end with ".rpm". The traditional tarball is a tar file (".tar") that has been gzipped (".gz"), and so ends in ".tar.gz".



                                                  So putting these together, you often end up with filenames that look like, "home_backup_2017-07-01.tar.gz"






                                                  share|improve this answer






















                                                    up vote
                                                    0
                                                    down vote










                                                    up vote
                                                    0
                                                    down vote









                                                    One convention is to use "_" to replace spaces as separators between words. Other characters could be used to replace spaces, but there are slightly stronger conventional uses for "-" and "." in pathnames, so "_" is usually preferred.



                                                    Spaces are legal in pathnames, but are conventionally avoided, because they require quoting the pathname ("foo bar") or escaping the spaces (foo bar). A properly written shell script will quote variables that may include spaces, particularly pathnames, but failing to do so is a common oversight, and it's a lot of extra typing when doing a one-off command entered at the command line.



                                                    Using "-" to separate clusters of numbers, as in timestamps or serial numbers, is a convention commonly used outside the context of filesystems. Using "." to separate "file extensions" that indicate the type of file is very common, and some important tools depend on it. For instance, the package management system on Red Hat Enterprise Linux and its derivatives, RPM, expects package files to end with ".rpm". The traditional tarball is a tar file (".tar") that has been gzipped (".gz"), and so ends in ".tar.gz".



                                                    So putting these together, you often end up with filenames that look like, "home_backup_2017-07-01.tar.gz"






                                                    share|improve this answer












                                                    One convention is to use "_" to replace spaces as separators between words. Other characters could be used to replace spaces, but there are slightly stronger conventional uses for "-" and "." in pathnames, so "_" is usually preferred.



                                                    Spaces are legal in pathnames, but are conventionally avoided, because they require quoting the pathname ("foo bar") or escaping the spaces (foo bar). A properly written shell script will quote variables that may include spaces, particularly pathnames, but failing to do so is a common oversight, and it's a lot of extra typing when doing a one-off command entered at the command line.



                                                    Using "-" to separate clusters of numbers, as in timestamps or serial numbers, is a convention commonly used outside the context of filesystems. Using "." to separate "file extensions" that indicate the type of file is very common, and some important tools depend on it. For instance, the package management system on Red Hat Enterprise Linux and its derivatives, RPM, expects package files to end with ".rpm". The traditional tarball is a tar file (".tar") that has been gzipped (".gz"), and so ends in ".tar.gz".



                                                    So putting these together, you often end up with filenames that look like, "home_backup_2017-07-01.tar.gz"







                                                    share|improve this answer












                                                    share|improve this answer



                                                    share|improve this answer










                                                    answered Jun 29 '17 at 15:57









                                                    bgvaughan

                                                    278110




                                                    278110




















                                                        up vote
                                                        0
                                                        down vote













                                                        use - for naming files

                                                        and _ for functions
                                                        . for extensions



                                                        cat << EOF > foo-bar.sh 
                                                        foo_bar()
                                                        echo baz

                                                        EOF





                                                        share|improve this answer


























                                                          up vote
                                                          0
                                                          down vote













                                                          use - for naming files

                                                          and _ for functions
                                                          . for extensions



                                                          cat << EOF > foo-bar.sh 
                                                          foo_bar()
                                                          echo baz

                                                          EOF





                                                          share|improve this answer
























                                                            up vote
                                                            0
                                                            down vote










                                                            up vote
                                                            0
                                                            down vote









                                                            use - for naming files

                                                            and _ for functions
                                                            . for extensions



                                                            cat << EOF > foo-bar.sh 
                                                            foo_bar()
                                                            echo baz

                                                            EOF





                                                            share|improve this answer














                                                            use - for naming files

                                                            and _ for functions
                                                            . for extensions



                                                            cat << EOF > foo-bar.sh 
                                                            foo_bar()
                                                            echo baz

                                                            EOF






                                                            share|improve this answer














                                                            share|improve this answer



                                                            share|improve this answer








                                                            edited Aug 23 at 12:53









                                                            roaima

                                                            40.4k547110




                                                            40.4k547110










                                                            answered Aug 23 at 12:25









                                                            Akhil J

                                                            265




                                                            265




















                                                                up vote
                                                                -1
                                                                down vote













                                                                There is definitely a standard for Linux. If you look at the file names in any Linux system they are lower case with dashes: /usr/bin/ssh-keygen. This is specified in one of the Linux Standards Base documents that I cannot find right now. It is also specified by GNU which says to use underscores for variable names and dashes for file names.






                                                                share|improve this answer
























                                                                  up vote
                                                                  -1
                                                                  down vote













                                                                  There is definitely a standard for Linux. If you look at the file names in any Linux system they are lower case with dashes: /usr/bin/ssh-keygen. This is specified in one of the Linux Standards Base documents that I cannot find right now. It is also specified by GNU which says to use underscores for variable names and dashes for file names.






                                                                  share|improve this answer






















                                                                    up vote
                                                                    -1
                                                                    down vote










                                                                    up vote
                                                                    -1
                                                                    down vote









                                                                    There is definitely a standard for Linux. If you look at the file names in any Linux system they are lower case with dashes: /usr/bin/ssh-keygen. This is specified in one of the Linux Standards Base documents that I cannot find right now. It is also specified by GNU which says to use underscores for variable names and dashes for file names.






                                                                    share|improve this answer












                                                                    There is definitely a standard for Linux. If you look at the file names in any Linux system they are lower case with dashes: /usr/bin/ssh-keygen. This is specified in one of the Linux Standards Base documents that I cannot find right now. It is also specified by GNU which says to use underscores for variable names and dashes for file names.







                                                                    share|improve this answer












                                                                    share|improve this answer



                                                                    share|improve this answer










                                                                    answered Mar 8 '14 at 20:12









                                                                    Bill Chatfield

                                                                    1




                                                                    1




















                                                                        up vote
                                                                        -2
                                                                        down vote













                                                                        To add to what everyone else has said:



                                                                        1-Even though Linux doesn't care much about extensions, Windows does, so make sure any file you ever plan on giving anyone has the appropriate extension.



                                                                        2-Camel caps seems to be the easiest to use scripts with, no special characters to worry about escape sequences.






                                                                        share|improve this answer


















                                                                        • 4




                                                                          -1. CamelCase is NOT used on Linux.
                                                                          – Mikel
                                                                          Feb 13 '11 at 21:50














                                                                        up vote
                                                                        -2
                                                                        down vote













                                                                        To add to what everyone else has said:



                                                                        1-Even though Linux doesn't care much about extensions, Windows does, so make sure any file you ever plan on giving anyone has the appropriate extension.



                                                                        2-Camel caps seems to be the easiest to use scripts with, no special characters to worry about escape sequences.






                                                                        share|improve this answer


















                                                                        • 4




                                                                          -1. CamelCase is NOT used on Linux.
                                                                          – Mikel
                                                                          Feb 13 '11 at 21:50












                                                                        up vote
                                                                        -2
                                                                        down vote










                                                                        up vote
                                                                        -2
                                                                        down vote









                                                                        To add to what everyone else has said:



                                                                        1-Even though Linux doesn't care much about extensions, Windows does, so make sure any file you ever plan on giving anyone has the appropriate extension.



                                                                        2-Camel caps seems to be the easiest to use scripts with, no special characters to worry about escape sequences.






                                                                        share|improve this answer














                                                                        To add to what everyone else has said:



                                                                        1-Even though Linux doesn't care much about extensions, Windows does, so make sure any file you ever plan on giving anyone has the appropriate extension.



                                                                        2-Camel caps seems to be the easiest to use scripts with, no special characters to worry about escape sequences.







                                                                        share|improve this answer














                                                                        share|improve this answer



                                                                        share|improve this answer








                                                                        edited Feb 14 '11 at 0:04

























                                                                        answered Feb 13 '11 at 21:48









                                                                        Yitzchak

                                                                        1171




                                                                        1171







                                                                        • 4




                                                                          -1. CamelCase is NOT used on Linux.
                                                                          – Mikel
                                                                          Feb 13 '11 at 21:50












                                                                        • 4




                                                                          -1. CamelCase is NOT used on Linux.
                                                                          – Mikel
                                                                          Feb 13 '11 at 21:50







                                                                        4




                                                                        4




                                                                        -1. CamelCase is NOT used on Linux.
                                                                        – Mikel
                                                                        Feb 13 '11 at 21:50




                                                                        -1. CamelCase is NOT used on Linux.
                                                                        – Mikel
                                                                        Feb 13 '11 at 21:50


                                                                        Popular posts from this blog

                                                                        How to check contact read email or not when send email to Individual?

                                                                        Displaying single band from multi-band raster using QGIS

                                                                        How many registers does an x86_64 CPU actually have?