How do I open a plain text file in any Linux?
I am not sure, but I believe in Windows you can run
Code:
> start SomeTextFile.txt 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 |
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 Code:
less file.txt Code:
more file.txt Code:
view file.txt One might open it for editing with Code:
vi file.txt Code:
vim file.txt Code:
nano file.txt Code:
kate file.txt Code:
joe file.txt Code:
pico file.txt 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. What is it you really want to do? |
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.
https://wiki.archlinux.org/title/XDG_MIME_Applications |
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.
|
Can also do alias's. I don't use them but many do. Then you can type in whatever you want.
https://vitux.com/how-to-create-alia...nds-in-debian/ example Code:
start='nano' Code:
runthisnow='apt update && apt full-upgrade -y' |
GUI, Folks!
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" |
Quote:
Code:
xdg-open somefile |
Completely forgot about xdg-open. It uses the mime type to determine what application to use.
|
As a senior member this seems a bit odd, however:
https://googlethatforyou.com?q=How%2...any%20Linux%3F |
Quote:
Linux: Well many have answered. Do we misunderstand your question? Because you obviously know Linux. wpeckham very much covered it. And you do not require a graphical environment. |
Quote:
Quote:
Quote:
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...) |
xdg-open is just what the doctor ordered. Thank you.
The only question now is whether it is available in a large enough number of installations. I think I will embed a basic text editor in my application. I guess it's the only foolproof way. |
If those are solutions, then mimetype and mimeopen might also be useful!
As mentioned, once you find the command you want to use one could alias "start" to be an alias for that command. |
Quote:
Ed |
Just going to add that the OSX equivalent to "start" and "xdg-open" is "open".
|
All times are GMT -5. The time now is 11:29 AM. |