ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
I am not sure, but I believe in Windows you can run
Code:
> start SomeTextFile.txt
on a terminal and Windows will open the text file with whatever program is configured as the default one for opening .txt files.
Whether that is true or not, is there such a thing on Linux?
I remember there used to be such a command for KDE a very long time ago (like 15 years ago), but I don't know if it is still used and, anyway, I need some command that does not rely on KDE. It just has to assume the user has a graphical environment. Is that possible?
Wow! there are SO many ways to open a text file!
Do you mean to read, or to edit?
If the file is names "file.txt" one could display it with
Code:
cat file.txt
or
Code:
less file.txt
or
Code:
more file.txt
or
Code:
view file.txt
or possibly a dozen or more additional options.
One might open it for editing with
Code:
vi file.txt
or
Code:
vim file.txt
or
Code:
nano file.txt
or
Code:
kate file.txt
or
Code:
joe file.txt
or
Code:
pico file.txt
or any of many other options depending upon what text editors you might have installed.
If you have a file manager installed, you can open that (generally it is an Xwindows program dso you open it in your gui desktop interface from the menu system) and click on the txt file and it will might in your default text editor - however you have that set at the time.
Should be possible. I don't know if any such command that exists but fairly easy to create a script i.e. find the mime type via the find command and then find what application is associated with that type by searching the mimeapps.list file.
You can set the $EDITOR variable in Linux, technically you can name this variable whatever you want, just make sure you are not interfering with existing variables.
If there is a taskbar with a kind of “start”-button, the “utilities” should comprise some text-editor.
Alternatively there should be a “run” function, although there is no obligation, as far as I know: Usually you hit Alt+F2 and name the program or command-line that you wish to start.
Examples are listed above in this thread, but the command-line editors need to be preceded by the call to a terminal application, like:
Code:
/usr/bin/lxterminal -e "vim file.txt"
Compared to your Windows-command that you state to use “in a terminal application”, the procedure is identical on Linux. Open a terminal and use one of the calls in post #2, above.
I remember there used to be such a command for KDE a very long time ago (like 15 years ago), but I don't know if it is still used and, anyway, I need some command that does not rely on KDE. It just has to assume the user has a graphical environment. Is that possible?
Many distros will check a file and then launch the appropriate graphical program if you run xdg-open with the file name as the first option.
Code:
xdg-open somefile
Otherwise, you'll have to know or guess whether to use geany, kate, gedit, mousepad, leafpad, etc. and use one of them by name. I have a script which is on many different desktops, each with a different distro, and it does just that.
I am not sure, but I believe in Windows you can run
Code:
> start SomeTextFile.txt
on a terminal and Windows will open the text file with whatever program is configured as the default one for opening .txt files.
Whether that is true or not, is there such a thing on Linux?
I remember there used to be such a command for KDE a very long time ago (like 15 years ago), but I don't know if it is still used and, anyway, I need some command that does not rely on KDE. It just has to assume the user has a graphical environment. Is that possible?
TIA
I do not believe this is specifically true. Using start in the Windows command prompt should attempt to run a program and unless the file is a script or executable, this will not work.
Linux:
Well many have answered. Do we misunderstand your question? Because you obviously know Linux. wpeckham very much covered it.
I do not believe this is specifically true. Using start in the Windows command prompt should attempt to run a program and unless the file is a script or executable, this will not work.
Nope, it will work:
Quote:
Originally Posted by https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2008-R2-and-2008/cc770297(v=ws.10)
You can run nonexecutable files through their file association by typing the name of the file as a command.
Quote:
Originally Posted by rtmistler
Well many have answered. Do we misunderstand your question? Because you obviously know Linux. wpeckham very much covered it.
Probably because of the poorly worded title, many misunderstood what was being asked.
I'm pretty sure Turbocapitalist answered the actual question - i.e: xdg-open is the equivalent to the above behaviour.
(A search for "linux open file in default application" contains many results saying the same thing...)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.