How can you open a file from the terminal. For example from terminal how can I open a .txt or .py file?
-
2In what way do you want to open it? Do you want to edit the file, just view it, run it, or something else?Aurora0001– Aurora00012018年02月23日 20:44:42 +00:00Commented Feb 23, 2018 at 20:44
-
I would like to open it so I can edit it.linuxuser1– linuxuser12018年02月23日 21:20:25 +00:00Commented Feb 23, 2018 at 21:20
-
2You want to edit it using what application?goldilocks– goldilocks2018年02月23日 21:41:01 +00:00Commented Feb 23, 2018 at 21:41
-
lets say I want to open a python file and edit it in Thonny. how would I do this from the terminal?linuxuser1– linuxuser12018年02月23日 21:45:16 +00:00Commented Feb 23, 2018 at 21:45
-
@linuxuser1 Thonny is a GUI program; running it from the terminal doesn't make a lot of sense unless you already have a GUI set up. Are you already running one (e.g. PIXEL)?Aurora0001– Aurora00012018年02月24日 10:43:39 +00:00Commented Feb 24, 2018 at 10:43
3 Answers 3
To view the text file you could use less
or cat
.
Example: cat /path/file.txt
. Of course this works only if the file is readable for your user account. For details please read the manpage: man cat
.
To edit a file you can choose between many editors. I recommend to start with nano
. A good read: Raspberry Pi Documentation - Text editors.
To learn more command line basics I recommend the eBook The MagPi Essentials - Conquer The Command Line (you can download it for free).
Short answer:
nano file.txt
Or
nano /home/user/documents/file.txt
Ctrl+x to close.