0

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

asked Feb 23, 2018 at 20:41
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? Commented Feb 23, 2018 at 20:44
  • I would like to open it so I can edit it. Commented Feb 23, 2018 at 21:20
  • 2
    You want to edit it using what application? Commented 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? Commented 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)? Commented 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).

answered Feb 23, 2018 at 21:13
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

answered Feb 25, 2018 at 7:04
0

Short answer:

nano file.txt

Or

nano /home/user/documents/file.txt

Ctrl+x to close.

answered Feb 23, 2018 at 21:52

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.