0

How can you open a file from the terminal. For example from terminal how can I open a .txt or .py file?

6
  • 2
    In what way do you want to open it? Do you want to edit the file, just view it, run it, or something else?
    – Aurora0001
    Feb 23, 2018 at 20:44
  • I would like to open it so I can edit it.
    – linuxuser1
    Feb 23, 2018 at 21:20
  • 2
    You want to edit it using what application?
    – goldilocks
    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
    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
    Feb 24, 2018 at 10:43

3 Answers 3

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).

1

Simple Answer

To view a python / text file you can use cat command.

cat /home/pi/documents/yourfile.txt

To edit a python / text file you can use vim or nano commands.

vim - vim ~/yourfile.txt
nano - nano ~/yourfile.py

0

Short answer:

nano file.txt

Or

nano /home/user/documents/file.txt

Ctrl+x to close.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.