Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Extensions are a feature of Windows. It's true that many Linux programs use them, but they are not a feature of the operating system itself. If your file is called "thing.odt", then that's the name, while in non-Unix type systems the name would be "thing".
Gedit is not a program that insists on creating extensions. The office suites do it, but that's because they have a lot of specialised formats to keep track of.
Distribution: RPM Distros,Mostly Mandrake Forks;Drake Tools/Utilities all the way!GO MAGEIA!!!
Posts: 986
Original Poster
Rep:
thanks for the help!
Lets say I open a gedit file with abiword. Does abiword inspect the file (calculate the file format) or is gedit's file format stored in the gedit file somewhere so abiword just look at a header or something to determine how to represent the file?
On Linux, in opposite to Windows systems, the filetype is not determined by file extensions, like .txt, but by their actual format.
So when the file or program is run against a particular file. The program being used to open the file will determine whether it can open the file or not?
If not the right program for the file; Linux kernel will just throw an error?
Gedit has no file format, it just saves whatever you put into it. Normally that's just text. Abiword would look at the file and determine that it's ASCII text, and open it as such. Yes, it's up to the program to decide if it can open the file. The kernel doesn't do anything, the program you told to open the file is responsible for giving you the error message if it can't open it.
LibreOffice has to use extensions, because the file may be opened by other operating systems like Windows, which insist on having the proper extension, or else they just refuse to open the file. For a plain text file, you can name it anything you like, with any extension you like, or none at all, it makes no difference to a Linux program. Gedit will happily try to open any file you give it, but if it's not a text file, it will tell you so and ask if you really, really want to it to try to open the file. If you say yes, it will attempt to display the file as text, even though the ASCII symbols may look strange. Think before you say yes, and attempt to edit a binary file.
Lets say I open a gedit file with abiword. Does abiword inspect the file (calculate the file format) or is gedit's file format stored in the gedit file somewhere so abiword just look at a header or something to determine how to represent the file?
There is no such thing as a Gedit file, gedit is a plain text editor. If you open it in Abiword Abiword will recognize that it is a plain text file and open it accordingly.
Quote:
Originally Posted by JJJCR
So when the file or program is run against a particular file. The program being used to open the file will determine whether it can open the file or not?
Yes.
Quote:
If not the right program for the file; Linux kernel will just throw an error?
No, the kernel doesn't care about file formats and also does not know which programs can open which filetypes. It is the program that tries to open that file that is throwing the error messages.
Quote:
Would there be a case that you can open a malicious file?
Difficult question. Malicious files are usually those that have either an executable part in the content, like Flash or makros of an office program, or when the content is interpreted, like PDF files. Usually you won't get a malicious reaction from a program that is not meant to open a specific filetype.
Would there be a case that you can open a malicious file?
Well, since a malicious file will usually be an executable file, there are safeguards in place that greatly reduce the risk. An executable file must be marked as executable by most modern systems in order to run. If it's not, it will simply open as a text file. (assuming it's a plain text script)
You can also limit file execution to files in the appropriate directories. (/bin /usr/bin etc.)
Most distros are configured that way out the box and won't run an executable file from your home directory regardless.
Since you need root privileges to copy files to the root directories where executables are normally launched from, it is a not easy for a hacker or some malware to put a malicious file there.
What the extension dose do is provide an easy, readable visual clue to the end user as to what the function of a file might be.
For example, .doc .pdf .odt are clearly documents while .txt is probably human readable plain text and .py .sh suggests plain text scripts and are likely executable.
The real problem with editing executable binary files with a text editor is that you will probably make the file unusable. If it's a necessary part of the OS you may make the system unusable. As long as you don't edit the file, or don't save it after editing, there should be no problem. Even if the binary does contain malicious code, opening it in a text editor should have no effects. You would need to run the binary before it could do anything.
Distribution: RPM Distros,Mostly Mandrake Forks;Drake Tools/Utilities all the way!GO MAGEIA!!!
Posts: 986
Original Poster
Rep:
Quote:
There is no such thing as a Gedit file, gedit is a plain text editor. If you open it in Abiword Abiword will recognize that it is a plain text file and open it accordingly.
Does "recognize" mean that the type of file is stored in a header of the gedit file?
Edit: Does the linux loader do the work for gedit?
Last edited by theKbStockpiler; 02-13-2014 at 01:32 PM.
There is no header for text files. It's just plain ASCII text. The binary which opens the file is responsible for recognizing that.
What Linux loader? What happens is that gedit, or any other Linux program, is loaded into memory and then has the responsibility for doing whatever it does. In the case of gedit, it either opens the file passed to it via the command line or another program, or if there is none, it waits for the user to tell it what to do. If it is told to open a file, it opens the file. It makes no difference what the filename is, or what the format is. It just opens the file. It should look at the file it opened, and act accordingly. Gedit will check the file, and if it finds that it's not a plain ASCII text file, it will ask you what you want it to do. If it is a text file, it will show the contents in the edit window. Any Linux program should do something similar - open the file it's told to open, and then do something. If it finds the file is not the type it expects, it should default to asking the user what to do. The file type is dependent entirely on the contents of the file, and not at all on the filename.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.