View Full Version : Opening files
nealbo
11-08-2006, 07:50 AM
I have another basic question about linux. This probably second nature to everyone, but I can't for the life of me figure out how to open a file from the command line.
Also, once someone tells me how to open a file from the command line :) how would I go about changing the default editor that opens it?
nox-Hand
11-09-2006, 02:46 PM
By file, you mean a file that can be edited in an editor?
Also, do you want a command-line-based editor, or a graphical?
If you want a graphical, I'd highly suggest you just open the program from the menu - its a bother to do else. Though, if you insist:
If you wish to open gedit (a GNOME text editor), and a file in /home/nealbo/websites/etc/test.php, you would write this in the command line:
gedit /home/nealbo/websites/etc/test.php
or, if you are already the user owning the /home folder, just
gedit ~/websites/etc/test.php
Or, if you are already in the /home/nealbo/ folder, just
gedit websites/etc/test.php
If you want to open a command line based editor, you should use the nano editor ( my personal taste ). There is also VIM text editor, which offers highlighting for all sorts, but it is very hard to use without a bulk manual at your side. nano just works, and it's very sophisticated and practical for editing things. Open the example file like so:
nano /home/nealbo/websites/etc/test.php
(( here you can just do everything stated in the gedit line, but replace gedit with nano.
It's that simple! :) If you want to make a file that doesn't already exist, you can simply type the path you want it created in, or JUST open nano, and then save it when you exit :D
By the way, if you use Ubuntu, or Debian-based systems, and it's a restricted file you are going to edit, use 'sudo' before the command to give yourself temporary administrator rights (provided you are allowed :) )
For example:
sudo nano /etc/apt/sources.list
NOTE: ALWAYS MAKE BACKUPS! :)
If you need more help, please don't hesitate to ask!
mikeyp
11-09-2006, 04:50 PM
If you just want to look at whats in the file but not edit it, you could use the following commands:
"cat filename"- This will output the whole file on the command line.
"more filename"- This will output the whole file but only a window's worth at a time.
nox-Hand
11-10-2006, 01:34 AM
Also, you can use the "less" command when listing a file, where you can actually use up/down arrows to scroll the text :)
nealbo
11-10-2006, 09:36 AM
Thanks for the details, thats made things a bit easier for me :)
I have one last question though - what is the purpose of the $EDITOR environmental variable if there is no way to simply open file (i.e. text file) without first declaring the program to use to open it?
Would this change the default editor to nedit - $EDITOR=nedit
?
nox-Hand
11-10-2006, 01:21 PM
I am quite certain that's for.... well, I'd say it's for the graphical enviroment, but I can't be certain. Maybe mikeyp can tell you :)
mikeyp
11-10-2006, 04:56 PM
$EDITOR sets the editor that will be used by other programs such as the mail program. If $EDITOR is not set then vi is used.
nox-Hand
11-10-2006, 05:59 PM
vi :o
That should be changed! I hate vi xD
fireboy
11-11-2006, 10:56 PM
The file you are trying to open may be damaged. Your Microsoft Office program may let you try to recover the text from the damaged ... When you create or open a file in a Microsoft Office program, the file opens in a separate window
nox-Hand
11-12-2006, 06:50 AM
That guys a maniac!
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.