2 Ways to open any text file or script in Ubuntu Linux 01/31/13

So there is a file that you want to see the contents of? It might be a log file that a program has generated or be a configuration file or have a funny file extension such as .php or .py?

In this post we will show two great ways of seeing and editing the file in the easiest possible ways. The two methods will cover 99% of cases even if something has went really wrong with your system.

The first method should be your first port of call when you have a normal system and are accessing it through the normal GUI. It’s called gedit!

If for some reason you don’t have gedit installed on your system, install it via typing the following into a terminal:

sudo apt-get install gedit

Now to edit any text based file with gedit simply use the command sudo gedit path/to/file. For example:

sudo gedit /etc/apt/sources.list

Because you are launching gedit with your sudo credentials you can now edit and save files that would otherwise be read only.

The GUI makes gedit simple to use and it has lots of nice features such as a great find/replace, tabs for multiple files, highlighting and colour schemes for editing code etc.

But, what if you don’t have access to the GUI and you are working solely via the command line terminal? An example of when this might happen would be when you are working on Ubuntu Server, via SSH or something isn’t correct in your graphic card drivers, you cant access the GUI and you need to manually edit the xorg.conf file.

In these types of cases you need to know about Nano!

Nano is a very simple text editor that runs directly in the terminal. If it’s not installed, then use:

sudo apt-get install nano

To edit any text based file with Nano simply use the command sudo nano path/to/file. For example:

sudo nano /etc/X11/xorg.conf

Everything is pretty straight forward from here and it’s a simple text editor that you can type directly into. One thing you will see is that at the very bottom of your terminal you will now see a list of shortcuts that look like an up arrow followed by a letter. To activate one of these shortcuts, you simply press the Ctrl key plus the letter. For example Ctrl+g shows the Help text and Ctrl+x exits Nano (and gives you the option to save your changes).

The great thing about Nano is that it will save you in emergencies when you cant access the GUI. You don’t even need a mouse!

Care to Share?

You can leave a response, or trackback from your own site.

Leave a Reply

close comment popup

Leave A Reply