I am checking the filename validity on Ubuntu computers. I want to check whether the file extension is correct.

  • If the only valid dot is the one before the file extension, then this check is valid:

    example.endexample -> file extension is endexample 
  • But if a dot is allowed in the filename, then this check is invalid:

    example.continue.endexample -> file extension is continue.endexample 

So is separating the value after the first dot in order to get the file extension enough?

4

2 Answers

File extensions (and therefore dots) have no special meaning as such in Linux. By tradition we use .sh for a shell script, .py for a Python one, .c for a C-source text and so on. And also .doc and so on for compability with other OSs. But everything works fine without or with other extensions.

To verify what type a given file is, use the file command:

file somefilename 

See man file for further description.

Also, the shell will try to execute everything that has an execute-bit set in permissions, using the header of the file to decide how. For scripts this header is called a shebang and has the form:

#!/path/to/interpreter 

If the shebang is missing, the interpreter/shell that is used is the same as the calling one.

This is very easy to answer: Yes, dots are allowed everywhere in Linux filenames. Even "worse": Linux and Unix filenames don't necessarily have extensions expressed in the name of the file.

So you will probably find many "incorrect" or missing file extensions, since there are no rules for filename extensions as in Microsoft's systems.

You can find the general rules here: Linux / UNIX: Rules For Naming File And Directory Names

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy