![]() |
Ultimate linux CLI noob question: "How to create a plain text file within xterm?"
Can anyone tell me how to create a new text file in xterm? I'm trying to follow the directions on the how to use xterm wiki about setting up a profile. Unfortunately, creating a new text file within xterm is not something I've learned to do yet.
|
Re: Ultimate linux CLI noob question: "How to create a plain text file within xterm?"
vi's a text editor that you can use inside xterm
vi .profile may do it. bit odd to learn however. |
Re: Ultimate linux CLI noob question: "How to create a plain text file within xterm?"
I normally use Touch.
Quote:
Code:
Code:
|
Re: Ultimate linux CLI noob question: "How to create a plain text file within xterm?"
The tone of your reply makes me think maybe I'm doing something wrong. Which is quite possible because I'm following a fairly convoluted path to solving my problem.
Problem: I'm trying to teach myself Python. The Python tutorial I'm using at byteofpyton.org says, in order to execute a python program that I write from any directory within the CLI, I need to edit the "PATH environment variable". That is, if I want to run my Python programs without first cd'ing to the dir in which the programs exist, I need to set up the "PATH environment variable". From this thread I got the impression that, in order to edit this "PATH environment variable" that I need to create a .profile file. For this, I was following the instructions specified on the xterm wiki. Am I totally barking up the wrong tree here? |
Re: Ultimate linux CLI noob question: "How to create a plain text file within xterm?"
Looking at that site, I'll tell you the quick way to do this (setting the path).
echo export ENV=$HOME/.shrc >> ~/.profile echo PATH=$PATH:PUTYOURDIRECTORYHERE >> ~/.shrc Replace PUTYOURDIRECTORYHERE with the directory you would like to run the program from. remember you cannot run from mmc. |
Re: Ultimate linux CLI noob question: "How to create a plain text file within xterm?"
Essentially Echo does have the ability to write to files (if you use >>) and the file has to be on the right side. The ~ means to create a file in your home directory and the .profile means that it will create that file (.profile) but it will be hidden from your view (in programs like the built in editor and file manager). If you run "ls -a" without the quotes then you can see files in a directory if they have a dot in front or not.
You cannot run programs from the SD cards because of the file system used on them. Also, if you want to make changes to a file (as opposed to dumping text into them) then you will need a text editor to do it. Vi and nano are possibilities. However, if you run the echo commands above properly the first time then an editor isn't needed... just make sure to run the right commands. |
Re: Ultimate linux CLI noob question: "How to create a plain text file within xterm?"
Quote:
it may, for instance, be possible to avoid automated detection at a toll booth by passing through it at a very high speed -- but you wouldn't expect someone unfamiliar with driving to accomplish this task without a high liklihood of catastrophic failure... |
Re: Ultimate linux CLI noob question: "How to create a plain text file within xterm?"
Quote:
In order to execute a program (any program, not just python programs) from the CLI, you have to write the full path to that program. You can write an absolute path (which starts at the root directory named "/"), or a relative path (which starts at the "current directory"). For example, if you have written a program named "mytest.py", and placed that program in the folder /home/user/myscripts/, then in order to execute that program you have to write: Code:
/home/user/myscripts/mytest.py Code:
./mytest.py If you do not specify any path before the program name, i.e: if you simply write: mytest.py in the CLI, and press Return, then the PATH variable come into action. This variable holds a list of directories, separated by colons. The CLI will search the program you want to run in this list, one directory at turn. When the program is found, it is run. If the list is exhausted and the program is not found, you obtain the message: Code:
-sh: mytest.py: not found Code:
echo $PATH You can alter the PATH variable, by assigning it a new value, and "exporting" it. For example: Code:
export PATH=/home/user/myscripts No panic. The changes to the PATH variable are local. They dissapear if you end the CLI session, so close the xterm and open a new instance. That is, you have your PATH restored, everything works again. If you want to *add* a new directory to your PATH variable, as opposed to *replace* it with a new directory, you can use the following syntax: Code:
export PATH=$PATH:/home/user/myscripts Code:
export PATH=/usr/bin:/bin:/home/user/myscripts So this is the whole story about the PATH variable? Well, it is if you dont mind to write the PATH assignation each time you open xterm. Remember that changes to the PATH variable are lost when xterm is closed. If you want to make these changes more permanent, you will be glad to know that, if you write a shell script named .profile and put it in your $HOME, it will be run each time an xterm is open (to be precise, when a shell session is started, even if you start it from ssh). So you can write a .profile which assigns your PATH variable as you like, and have this value assigned automatically in each session. Creating files from command line Now for your question. To write .profile (or any other file), you should use an editor. vi is an editor which comes with the OS, but it is difficult to use. However, for very short files, you can write them from the command line, using the echo command, or the cat command. I prefer the later: Code:
cat >> $HOME/.profile The cat command, used as above, appends all text you type (up to the Ctrl-D, which means "end of file") to the file you specify after the ">>" You should type carefully, because you cannot edit a line after you press Return. Even before pressing Return, the editing capabilities are very restricted. You only can delete chars (using backspace) and write them again, but you cannot move the cursor in the line. However, for short texts, or for text which are "copy&pasted", cat can be a quick way of creating file contents. |
Re: Ultimate linux CLI noob question: "How to create a plain text file within xterm?"
Quote:
And thanks to everyone for the info, especially jldiaz who has proven, yet again, to be very patient and willing to help a cluelees noob such as I. It was very clear and helpful. |
Re: Ultimate linux CLI noob question: "How to create a plain text file within xterm?"
Good posting by jldiaz.
To start editing a file you will also need to use a text editor of some kind. 'vi' comes pre-installed. I myself only know the most basic commands so I use it only for simple stuff (like updating the already mentioned configuration files). Still, it's a powerful editor and can be used for writing e.g. python programs, if you want to. Here's a guide to using vi: (there are others, easy to find with google): http://www.cs.rit.edu/~cslab/vi.html UPDATE: I forgot to mention that the 'esc' key (essential with vi) is the physical button with that curved little arrow. |
All times are GMT. The time now is 14:17. |
vBulletin® Version 3.8.8