You are not logged in.
Pages: 1
Good afternoon,
been spending a few hours learning the terminal and was looking at the cat command
Looking to create a file and take the output of the terminal and save it to the file.
The examples I seen online are as follow:
cat > file1 i will add some text inthe file1
At the end of the last word on my text which would be file1 I supposed to hit CTRL+d
I do but nothing happens the file is created without any text.
Not sure if am not selecting the correct key combination or the syntax is wrong
using xfce4-terminal if that helps.
Last edited by ccerna1 (2017-04-16 03:37:43)
Offline
Ctrl-d sends and EOF symbol or "End of file". It will close a shell session if used at a prompt. But in your "cat" use it would just end the file. However, to be used as an end of file for "cat" (getting input from stdin, i.e. the keyboard) you need to press Ctrl-d on a new line. So hit Enter after your last line of text, then hit ctrl-d.
Honestly, I'm not sure why this is. A file can end without a last newline character. So in principle one should be able to send the EOF from anywhere. But in practice it doesn't seem to work that way when reading from keyboard-stdin.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
So a couple of things I notice my locale was not set duh! me after a whole year using this... selected the correct one and generated a new locale.
check the keyboard setting was set at default and now is Generic 105 key.
When I run the command I get this:
cat > file1 this is a test
cat: is: No such file or directory
cat: a: No such file or directory
cat: test: No such file or directory
when i check the directory the file is created but is empty.
I hit enter as you stated and in the new line ctrl d and it closed the terminal
Offline
Ok I notice what I was doing wrong you were correct
first
cat > file1 (hit enter and will take me to line below without a terminal prompt)
there is no terminal prompt here so I write the text
text
text
I hit control d here and will save the text to the file
Offline
Ah, yes, you need to hit enter after a command as well before it even starts listening for input. Technically you could use a herestring to have input on the same line, but that lesson will likely come quite a bit later in your learning.
If you are not already using it, I'd suggest you read through Greg's wiki which is the de-facto standard bash tutorial.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Great thank you for setting me in the right path!
Offline
Pages: 1